-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[mlir][acc] Refactor and expand OpenACC utils #115119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
razvanlupusoru
wants to merge
2
commits into
llvm:main
Choose a base branch
from
razvanlupusoru:accutils1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
//===- OpenACCUtils.h - OpenACC Utilities -----------------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef MLIR_DIALECT_OPENACC_UTILS_OPENACCUTILS_H_ | ||
#define MLIR_DIALECT_OPENACC_UTILS_OPENACCUTILS_H_ | ||
|
||
#include "mlir/Dialect/OpenACC/OpenACC.h" | ||
|
||
namespace mlir { | ||
namespace acc { | ||
/// Used to obtain the `varPtr` from a data clause operation. | ||
/// Returns empty value if not a data clause operation or is a data exit | ||
/// operation with no `varPtr`. | ||
mlir::Value getVarPtr(mlir::Operation *accDataClauseOp); | ||
|
||
/// Used to set the `varPtr` of a data clause operation. | ||
/// Returns true if it was set successfully and false if this is not a data | ||
/// clause operation. | ||
bool setVarPtr(mlir::Operation *accDataClauseOp, mlir::Value varPtr); | ||
|
||
/// Used to obtain the `accPtr` from a data clause operation. | ||
/// When a data entry operation, it obtains its result `accPtr` value. | ||
/// If a data exit operation, it obtains its operand `accPtr` value. | ||
/// Returns empty value if not a data clause operation. | ||
mlir::Value getAccPtr(mlir::Operation *accDataClauseOp); | ||
|
||
/// Used to set the `accPtr` for a data exit operation. | ||
/// Returns true if it was set successfully and false if is not a data exit | ||
/// operation (data entry operations have their result as `accPtr` which | ||
/// cannot be changed). | ||
bool setAccPtr(mlir::Operation *accDataClauseOp, mlir::Value accPtr); | ||
|
||
/// Used to obtain the `varPtrPtr` from a data clause operation. | ||
/// Returns empty value if not a data clause operation. | ||
mlir::Value getVarPtrPtr(mlir::Operation *accDataClauseOp); | ||
|
||
/// Used to set the `varPtrPtr` for a data clause operation. | ||
/// Returns false if the operation does not have varPtrPtr or is not a data | ||
/// clause op. | ||
bool setVarPtrPtr(mlir::Operation *accDataClauseOp, mlir::Value varPtrPtr); | ||
|
||
/// Used to obtain `bounds` from an acc data clause operation. | ||
/// Returns an empty vector if there are no bounds. | ||
mlir::SmallVector<mlir::Value> getBounds(mlir::Operation *accDataClauseOp); | ||
|
||
/// Used to set `bounds` for an acc data clause operation. It completely | ||
/// replaces all bounds operands with the new list. | ||
/// Returns false if new bounds were not set (such as when argument is not | ||
/// an acc data clause operation). | ||
bool setBounds(mlir::Operation *accDataClauseOp, | ||
mlir::SmallVector<mlir::Value> &bounds); | ||
bool setBounds(mlir::Operation *accDataClauseOp, mlir::Value bound); | ||
|
||
/// Used to obtain the `dataClause` from a data clause operation. | ||
/// Returns empty optional if not a data operation. | ||
std::optional<mlir::acc::DataClause> | ||
getDataClause(mlir::Operation *accDataClauseOp); | ||
|
||
/// Used to set the `dataClause` on a data clause operation. | ||
/// Returns true if successfully set and false otherwise. | ||
bool setDataClause(mlir::Operation *accDataClauseOp, | ||
mlir::acc::DataClause dataClause); | ||
|
||
/// Used to find out whether this data operation uses structured runtime | ||
/// counters. Returns false if not a data operation or if it is a data operation | ||
/// without the structured flag set. | ||
bool getStructuredFlag(mlir::Operation *accDataClauseOp); | ||
|
||
/// Used to update the data clause operation whether it represents structured | ||
/// or dynamic (value of `structured` is passed as false). | ||
/// Returns true if successfully set and false otherwise. | ||
bool setStructuredFlag(mlir::Operation *accDataClauseOp, bool structured); | ||
|
||
/// Used to find out whether data operation is implicit. | ||
/// Returns false if not a data operation or if it is a data operation without | ||
/// implicit flag. | ||
bool getImplicitFlag(mlir::Operation *accDataClauseOp); | ||
|
||
/// Used to update the data clause operation whether this operation is | ||
/// implicit or explicit (`implicit` set as false). | ||
/// Returns true if successfully set and false otherwise. | ||
bool setImplicitFlag(mlir::Operation *accDataClauseOp, bool implicit); | ||
|
||
/// Used to obtain the `name` from an acc operation. | ||
std::optional<llvm::StringRef> getVarName(mlir::Operation *accDataClauseOp); | ||
|
||
/// Used to obtain `async` operands from an acc data clause operation. | ||
/// Returns an empty vector if there are no such operands. | ||
mlir::SmallVector<mlir::Value> | ||
getAsyncOperands(mlir::Operation *accDataClauseOp); | ||
|
||
/// Returns an array of acc:DeviceTypeAttr attributes attached to | ||
/// an acc data clause operation, that correspond to the device types | ||
/// associated with the async clauses with an async-value. | ||
mlir::ArrayAttr getAsyncOperandsDeviceType(mlir::Operation *accDataClauseOp); | ||
|
||
/// Returns an array of acc:DeviceTypeAttr attributes attached to | ||
/// an acc data clause operation, that correspond to the device types | ||
/// associated with the async clauses without an async-value. | ||
mlir::ArrayAttr getAsyncOnly(mlir::Operation *accDataClauseOp); | ||
|
||
/// Used to get an immutable range iterating over the data operands. | ||
mlir::ValueRange getDataOperands(mlir::Operation *accOp); | ||
|
||
/// Used to get a mutable range iterating over the data operands. | ||
mlir::MutableOperandRange getMutableDataOperands(mlir::Operation *accOp); | ||
|
||
} // namespace acc | ||
} // namespace mlir | ||
|
||
#endif // MLIR_DIALECT_OPENACC_UTILS_OPENACCUTILS_H_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
add_subdirectory(IR) | ||
add_subdirectory(Transforms) | ||
add_subdirectory(Utils) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
add_mlir_dialect_library(MLIROpenACCUtils | ||
OpenACCUtils.cpp | ||
|
||
ADDITIONAL_HEADER_DIRS | ||
${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect/OpenACC | ||
|
||
DEPENDS | ||
MLIROpenACCPassIncGen | ||
MLIROpenACCOpsIncGen | ||
MLIROpenACCEnumsIncGen | ||
MLIROpenACCAttributesIncGen | ||
MLIROpenACCMPOpsInterfacesIncGen | ||
MLIROpenACCOpsInterfacesIncGen | ||
MLIROpenACCTypeInterfacesIncGen | ||
|
||
LINK_LIBS PUBLIC | ||
MLIRIR | ||
MLIROpenACCDialect | ||
MLIRSupport | ||
) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be nicer to refactor this into proper interfaces for these operations instead of just creating a new lib.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with this. There are a couple of reasons I decided to do this MR this way:
Operation
. So no need to have any explicit casts in source code.I see this MR as orthogonal to your recommendation. The utilities can use the interfaces that we define.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MR -> PR
I'm not sure I see the motivation to move this away from the ops. Now you need to duplicate the code in the dialect part and have an extra library to link with. These utility functions are pretty much tied to the operations or do I miss something? Ultimately I'm not against it but it feels odd to duplicate some code. Maybe these could be inlined function defined in header?