diff options
author | Valentin Clement <clementval@gmail.com> | 2023-05-17 11:06:07 -0700 |
---|---|---|
committer | Valentin Clement <clementval@gmail.com> | 2023-05-17 11:08:24 -0700 |
commit | 9c3299b8593041cfcb33da205877d33d768104ca (patch) | |
tree | 4af632013a6ae361b6bb94ff4133ee54d7a76f45 /mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp | |
parent | e9a17453ee559a114d1c40ef939ee4478999a76e (diff) | |
download | llvm-9c3299b8593041cfcb33da205877d33d768104ca.tar.gz |
[mlir][openacc] Add private representation
Currently privatization is not well represented in the OpenACC dialect. This
patch is a prototype to model privatization with a dedicated operation that
declares how the private value is created and destroyed.
The newly introduced operation is `acc.private.recipe` and it declares
an OpenACC privatization. The operation requires one mandatory and
one optional region.
1. The initializer region specifies how to create and initialize a new
private value. For example in Fortran, a derived-type might have a
default initialization. The region has an argument that contains the
value that need to be privatized. This is useful if the type is not
a known at compile time and the private value is needed to create its
copy.
2. The destroy region specifies how to destruct the value when it reaches
its end of life. It takes the privatized value as argument.
A same privatization can be used for multiple operand if they have the same
type and do not require a specific default initialization.
Example:
```mlir
acc.private.recipe @privatization_f32 : f32 init {
^bb0(%0: f32):
// init region contains a sequence of operations to create and initialize the
// copy if needed.
} destroy {
^bb0(%0: f32):
// destroy region contains a sequences of operations to destruct the created
// copy.
}
// The privatization symbol is then used in the corresponding operation.
acc.parallel private(@privatization_f32 -> %a : f32) {
}
```
Reviewed By: razvanlupusoru, jeanPerier
Differential Revision: https://reviews.llvm.org/D150622
Diffstat (limited to 'mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp')
-rw-r--r-- | mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp b/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp index 4013657a4b28..0a93447ef04e 100644 --- a/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp +++ b/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp @@ -335,6 +335,38 @@ struct RemoveConstantIfConditionWithRegion : public OpRewritePattern<OpTy> { } // namespace //===----------------------------------------------------------------------===// +// PrivateRecipeOp +//===----------------------------------------------------------------------===// + +LogicalResult acc::PrivateRecipeOp::verifyRegions() { + if (getInitRegion().empty()) + return emitOpError() << "expects non-empty init region"; + Block &initBlock = getInitRegion().front(); + if (initBlock.getNumArguments() != 1 || + initBlock.getArgument(0).getType() != getType()) + return emitOpError() << "expects init region with one argument of the " + << "privatization type"; + + for (YieldOp yieldOp : getInitRegion().getOps<YieldOp>()) { + if (yieldOp.getOperands().size() != 1 || + yieldOp.getOperands().getTypes()[0] != getType()) + return emitOpError() << "expects init region to yield a value " + "of the privatization type"; + } + + // Destroy region is optional. + if (getDestroyRegion().empty()) + return success(); + + Block &destroyBlock = getDestroyRegion().front(); + if (destroyBlock.getNumArguments() != 1 || + destroyBlock.getArgument(0).getType() != getType()) + return emitOpError() << "expects destroy region with one argument of the " + << "privatization type"; + return success(); +} + +//===----------------------------------------------------------------------===// // ParallelOp //===----------------------------------------------------------------------===// |