-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[OpenACC] Add reduction recipe helper to ACC Dialect #154566
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
Conversation
Similar to how we did for private/firstprivate, these helper functions should make generating the recipes for the Clang FE easier.
@llvm/pr-subscribers-openacc @llvm/pr-subscribers-mlir-openacc Author: Erich Keane (erichkeane) ChangesSimilar to how we did for private/firstprivate, these helper functions should make generating the recipes for the Clang FE easier. Full diff: https://github.com/llvm/llvm-project/pull/154566.diff 2 Files Affected:
diff --git a/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td b/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td
index 47646b3b8fec9..0db11aa9af683 100644
--- a/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td
+++ b/mlir/include/mlir/Dialect/OpenACC/OpenACCOps.td
@@ -1540,6 +1540,11 @@ def OpenACC_ParallelOp : OpenACC_Op<"parallel",
/// recipe.
void addFirstPrivatization(MLIRContext *, mlir::acc::FirstprivateOp op,
mlir::acc::FirstprivateRecipeOp recipe);
+
+ /// Adds a reduction clause variable to this operation, including its
+ /// recipe.
+ void addReduction(MLIRContext *, mlir::acc::ReductionOp op,
+ mlir::acc::ReductionRecipeOp recipe);
}];
let assemblyFormat = [{
@@ -1689,6 +1694,10 @@ def OpenACC_SerialOp : OpenACC_Op<"serial",
/// recipe.
void addFirstPrivatization(MLIRContext *, mlir::acc::FirstprivateOp op,
mlir::acc::FirstprivateRecipeOp recipe);
+ /// Adds a reduction clause variable to this operation, including its
+ /// recipe.
+ void addReduction(MLIRContext *, mlir::acc::ReductionOp op,
+ mlir::acc::ReductionRecipeOp recipe);
}];
let assemblyFormat = [{
@@ -2415,6 +2424,10 @@ def OpenACC_LoopOp : OpenACC_Op<"loop",
/// Adds a private clause variable to this operation, including its recipe.
void addPrivatization(MLIRContext *, mlir::acc::PrivateOp op,
mlir::acc::PrivateRecipeOp recipe);
+ /// Adds a reduction clause variable to this operation, including its
+ /// recipe.
+ void addReduction(MLIRContext *, mlir::acc::ReductionOp op,
+ mlir::acc::ReductionRecipeOp recipe);
}];
let hasCustomAssemblyFormat = 1;
diff --git a/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp b/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
index d7c8916f43a2c..5fd426eee1dfd 100644
--- a/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
+++ b/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
@@ -1404,6 +1404,22 @@ void acc::ParallelOp::addFirstPrivatization(
mlir::SymbolRefAttr::get(context, recipe.getSymName().str()));
setFirstprivatizationRecipesAttr(mlir::ArrayAttr::get(context, recipes));
}
+
+void acc::ParallelOp::addReduction(MLIRContext *context,
+ mlir::acc::ReductionOp op,
+ mlir::acc::ReductionRecipeOp recipe) {
+ getReductionOperandsMutable().append(op.getResult());
+
+ llvm::SmallVector<mlir::Attribute> recipes;
+
+ if (getReductionRecipesAttr())
+ llvm::copy(getReductionRecipesAttr(), std::back_inserter(recipes));
+
+ recipes.push_back(
+ mlir::SymbolRefAttr::get(context, recipe.getSymName().str()));
+ setReductionRecipesAttr(mlir::ArrayAttr::get(context, recipes));
+}
+
static ParseResult parseNumGangs(
mlir::OpAsmParser &parser,
llvm::SmallVectorImpl<mlir::OpAsmParser::UnresolvedOperand> &operands,
@@ -2070,6 +2086,21 @@ void acc::SerialOp::addFirstPrivatization(
setFirstprivatizationRecipesAttr(mlir::ArrayAttr::get(context, recipes));
}
+void acc::SerialOp::addReduction(MLIRContext *context,
+ mlir::acc::ReductionOp op,
+ mlir::acc::ReductionRecipeOp recipe) {
+ getReductionOperandsMutable().append(op.getResult());
+
+ llvm::SmallVector<mlir::Attribute> recipes;
+
+ if (getReductionRecipesAttr())
+ llvm::copy(getReductionRecipesAttr(), std::back_inserter(recipes));
+
+ recipes.push_back(
+ mlir::SymbolRefAttr::get(context, recipe.getSymName().str()));
+ setReductionRecipesAttr(mlir::ArrayAttr::get(context, recipes));
+}
+
//===----------------------------------------------------------------------===//
// KernelsOp
//===----------------------------------------------------------------------===//
@@ -3088,6 +3119,20 @@ void acc::LoopOp::addPrivatization(MLIRContext *context,
setPrivatizationRecipesAttr(mlir::ArrayAttr::get(context, recipes));
}
+void acc::LoopOp::addReduction(MLIRContext *context, mlir::acc::ReductionOp op,
+ mlir::acc::ReductionRecipeOp recipe) {
+ getReductionOperandsMutable().append(op.getResult());
+
+ llvm::SmallVector<mlir::Attribute> recipes;
+
+ if (getReductionRecipesAttr())
+ llvm::copy(getReductionRecipesAttr(), std::back_inserter(recipes));
+
+ recipes.push_back(
+ mlir::SymbolRefAttr::get(context, recipe.getSymName().str()));
+ setReductionRecipesAttr(mlir::ArrayAttr::get(context, recipes));
+}
+
//===----------------------------------------------------------------------===//
// DataOp
//===----------------------------------------------------------------------===//
|
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.
LGTM! Sorry I missed the email for this PR :-)
Similar to how we did for private/firstprivate, these helper functions should make generating the recipes for the Clang FE easier.