-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[OpenACC][CIR] Lower 'num_workers' for parallel/kernels #136578
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
Merged
Merged
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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -46,10 +46,27 @@ class OpenACCClauseCIREmitter final | |||||
// diagnostics are gone. | ||||||
SourceLocation dirLoc; | ||||||
|
||||||
const OpenACCDeviceTypeClause *lastDeviceTypeClause = nullptr; | ||||||
|
||||||
void clauseNotImplemented(const OpenACCClause &c) { | ||||||
cgf.cgm.errorNYI(c.getSourceRange(), "OpenACC Clause", c.getClauseKind()); | ||||||
} | ||||||
|
||||||
mlir::Value createIntExpr(const Expr *intExpr) { | ||||||
mlir::Value expr = cgf.emitScalarExpr(intExpr); | ||||||
mlir::Location exprLoc = cgf.cgm.getLoc(intExpr->getBeginLoc()); | ||||||
|
||||||
mlir::IntegerType targetType = mlir::IntegerType::get( | ||||||
&cgf.getMLIRContext(), cgf.getContext().getIntWidth(intExpr->getType()), | ||||||
intExpr->getType()->isSignedIntegerOrEnumerationType() | ||||||
? mlir::IntegerType::SignednessSemantics::Signed | ||||||
: mlir::IntegerType::SignednessSemantics::Unsigned); | ||||||
|
||||||
auto conversionOp = builder.create<mlir::UnrealizedConversionCastOp>( | ||||||
exprLoc, targetType, expr); | ||||||
return conversionOp.getResult(0); | ||||||
} | ||||||
|
||||||
// 'condition' as an OpenACC grammar production is used for 'if' and (some | ||||||
// variants of) 'self'. It needs to be emitted as a signless-1-bit value, so | ||||||
// this function emits the expression, then sets the unrealized conversion | ||||||
|
@@ -109,14 +126,15 @@ class OpenACCClauseCIREmitter final | |||||
} | ||||||
|
||||||
void VisitDeviceTypeClause(const OpenACCDeviceTypeClause &clause) { | ||||||
lastDeviceTypeClause = &clause; | ||||||
if constexpr (isOneOfTypes<OpTy, InitOp, ShutdownOp>) { | ||||||
llvm::SmallVector<mlir::Attribute> deviceTypes; | ||||||
std::optional<mlir::ArrayAttr> existingDeviceTypes = | ||||||
operation.getDeviceTypes(); | ||||||
|
||||||
// Ensure we keep the existing ones, and in the correct 'new' order. | ||||||
if (existingDeviceTypes) { | ||||||
for (const mlir::Attribute &Attr : *existingDeviceTypes) | ||||||
for (mlir::Attribute Attr : *existingDeviceTypes) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed here: 4b98955 |
||||||
deviceTypes.push_back(mlir::acc::DeviceTypeAttr::get( | ||||||
builder.getContext(), | ||||||
cast<mlir::acc::DeviceTypeAttr>(Attr).getValue())); | ||||||
|
@@ -136,6 +154,51 @@ class OpenACCClauseCIREmitter final | |||||
if (!clause.getArchitectures().empty()) | ||||||
operation.setDeviceType( | ||||||
decodeDeviceType(clause.getArchitectures()[0].getIdentifierInfo())); | ||||||
} else if constexpr (isOneOfTypes<OpTy, ParallelOp, SerialOp, KernelsOp>) { | ||||||
// Nothing to do here, these constructs don't have any IR for these, as | ||||||
// they just modify the other clauses IR. So setting of `lastDeviceType` | ||||||
// (done above) is all we need. | ||||||
} else { | ||||||
return clauseNotImplemented(clause); | ||||||
} | ||||||
} | ||||||
|
||||||
void VisitNumWorkersClause(const OpenACCNumWorkersClause &clause) { | ||||||
if constexpr (isOneOfTypes<OpTy, ParallelOp, KernelsOp>) { | ||||||
// Collect the 'existing' device-type attributes so we can re-create them | ||||||
// and insert them. | ||||||
llvm::SmallVector<mlir::Attribute> deviceTypes; | ||||||
mlir::ArrayAttr existingDeviceTypes = | ||||||
operation.getNumWorkersDeviceTypeAttr(); | ||||||
|
||||||
if (existingDeviceTypes) { | ||||||
for (mlir::Attribute Attr : existingDeviceTypes) | ||||||
deviceTypes.push_back(mlir::acc::DeviceTypeAttr::get( | ||||||
builder.getContext(), | ||||||
cast<mlir::acc::DeviceTypeAttr>(Attr).getValue())); | ||||||
} | ||||||
|
||||||
// Insert 1 version of the 'int-expr' to the NumWorkers list per-current | ||||||
// device type. | ||||||
mlir::Value intExpr = createIntExpr(clause.getIntExpr()); | ||||||
if (lastDeviceTypeClause) { | ||||||
for (const DeviceTypeArgument &arg : | ||||||
lastDeviceTypeClause->getArchitectures()) { | ||||||
deviceTypes.push_back(mlir::acc::DeviceTypeAttr::get( | ||||||
builder.getContext(), decodeDeviceType(arg.getIdentifierInfo()))); | ||||||
operation.getNumWorkersMutable().append(intExpr); | ||||||
} | ||||||
} else { | ||||||
// Else, we just add a single for 'none'. | ||||||
deviceTypes.push_back(mlir::acc::DeviceTypeAttr::get( | ||||||
builder.getContext(), mlir::acc::DeviceType::None)); | ||||||
operation.getNumWorkersMutable().append(intExpr); | ||||||
} | ||||||
|
||||||
operation.setNumWorkersDeviceTypeAttr( | ||||||
mlir::ArrayAttr::get(builder.getContext(), deviceTypes)); | ||||||
} else if constexpr (isOneOfTypes<OpTy, SerialOp>) { | ||||||
llvm_unreachable("num_workers not valid on serial"); | ||||||
} else { | ||||||
return clauseNotImplemented(clause); | ||||||
} | ||||||
|
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
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.
What's the lifetime of this object? Who owns it?
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.
Its owned by the AST, so its lifetime lasts until the AST is destroyed, which is after frontend codegen.