[mlir][acc] Effectively serial check should permit missing dimension#194981
Closed
razvanlupusoru wants to merge 2 commits into
Closed
[mlir][acc] Effectively serial check should permit missing dimension#194981razvanlupusoru wants to merge 2 commits into
razvanlupusoru wants to merge 2 commits into
Conversation
The `isEffectivelySerial` check for `acc.compute_region` required that all parallelism dimensions be set to 1. However, missing dimensions means that the level of parallelism is not assigned and thus should not be considered. Fix the issue and add unit tests for the API.
|
@llvm/pr-subscribers-mlir-openacc @llvm/pr-subscribers-openacc Author: Razvan Lupusoru (razvanlupusoru) ChangesThe Full diff: https://github.com/llvm/llvm-project/pull/194981.diff 2 Files Affected:
diff --git a/mlir/lib/Dialect/OpenACC/IR/OpenACCCG.cpp b/mlir/lib/Dialect/OpenACC/IR/OpenACCCG.cpp
index fe806186ce25d..4d06b1f1ff90e 100644
--- a/mlir/lib/Dialect/OpenACC/IR/OpenACCCG.cpp
+++ b/mlir/lib/Dialect/OpenACC/IR/OpenACCCG.cpp
@@ -506,6 +506,10 @@ bool ComputeRegionOp::isEffectivelySerial() {
return true;
auto checkDim = [&](GPUParallelDimAttr dim) -> bool {
+ // Launch dimensions without an explicit `acc.par_width` for that dimension
+ // means that no such parallelism is assigned and thus defaults to width 1.
+ if (!getLaunchArg(dim))
+ return true;
auto val = getKnownConstantLaunchArg(dim);
return val && *val == 1;
};
diff --git a/mlir/unittests/Dialect/OpenACC/OpenACCCGOpsTest.cpp b/mlir/unittests/Dialect/OpenACC/OpenACCCGOpsTest.cpp
index 44283c9091b4d..800d3b9a3108d 100644
--- a/mlir/unittests/Dialect/OpenACC/OpenACCCGOpsTest.cpp
+++ b/mlir/unittests/Dialect/OpenACC/OpenACCCGOpsTest.cpp
@@ -93,11 +93,78 @@ class OpenACCCGOpsTest : public ::testing::Test {
YieldOp::create(regionBuilder, loc);
}
+ /// Build a single `acc.compute_region` with the given launch arguments.
+ ComputeRegionOp makeComputeRegion(HostContext &host, ValueRange launchArgs) {
+ Region sourceRegion;
+ populateSourceRegionSingleBlock(sourceRegion, context, loc, std::nullopt,
+ false);
+ IRMapping mapping;
+ // Setting an empty origin since it should not be relevant for the tests.
+ ComputeRegionOp cr = buildComputeRegion(
+ loc, launchArgs, {}, "", sourceRegion, host.rewriter, mapping);
+ return cr;
+ }
+
MLIRContext context;
OpBuilder b;
Location loc;
};
+//===----------------------------------------------------------------------===//
+// ComputeRegionOp::isEffectivelySerial
+//===----------------------------------------------------------------------===//
+
+TEST_F(OpenACCCGOpsTest, IsEffectivelySerialNoLaunchArgs) {
+ HostContext host(context, loc, b);
+ ComputeRegionOp cr = makeComputeRegion(host, {});
+ EXPECT_TRUE(cr.isEffectivelySerial());
+ EXPECT_TRUE(succeeded(host.module->verify()));
+}
+
+TEST_F(OpenACCCGOpsTest, IsEffectivelySerialSparseDimsConstantOne) {
+ HostContext host(context, loc, b);
+ Value c1 = arith::ConstantIndexOp::create(host.rewriter, loc, 1);
+ Value pwBx = ParWidthOp::create(host.rewriter, loc, c1,
+ GPUParallelDimAttr::blockXDim(&context));
+ Value pwTy = ParWidthOp::create(host.rewriter, loc, c1,
+ GPUParallelDimAttr::threadYDim(&context));
+ Value pwTx = ParWidthOp::create(host.rewriter, loc, c1,
+ GPUParallelDimAttr::threadXDim(&context));
+ ComputeRegionOp cr = makeComputeRegion(host, {pwBx, pwTy, pwTx});
+ EXPECT_TRUE(cr.isEffectivelySerial());
+ EXPECT_TRUE(succeeded(host.module->verify()));
+}
+
+TEST_F(OpenACCCGOpsTest,
+ IsEffectivelySerialFalseWhenThreadXWidthGreaterThanOne) {
+ HostContext host(context, loc, b);
+ Value c2 = arith::ConstantIndexOp::create(host.rewriter, loc, 2);
+ Value pwTx = ParWidthOp::create(host.rewriter, loc, c2,
+ GPUParallelDimAttr::threadXDim(&context));
+ ComputeRegionOp cr = makeComputeRegion(host, pwTx);
+ EXPECT_FALSE(cr.isEffectivelySerial());
+ EXPECT_TRUE(succeeded(host.module->verify()));
+}
+
+TEST_F(OpenACCCGOpsTest, IsEffectivelySerialFalseWhenLaunchWidthUnknown) {
+ HostContext host(context, loc, b);
+ Value pwTx = ParWidthOp::create(host.rewriter, loc, Value(),
+ GPUParallelDimAttr::threadXDim(&context));
+ ComputeRegionOp cr = makeComputeRegion(host, pwTx);
+ EXPECT_FALSE(cr.isEffectivelySerial());
+ EXPECT_TRUE(succeeded(host.module->verify()));
+}
+
+TEST_F(OpenACCCGOpsTest, IsEffectivelySerialTrueWhenSeqLaunchPresent) {
+ HostContext host(context, loc, b);
+ Value c7 = arith::ConstantIndexOp::create(host.rewriter, loc, 7);
+ Value pwSeq = ParWidthOp::create(host.rewriter, loc, c7,
+ GPUParallelDimAttr::seqDim(&context));
+ ComputeRegionOp cr = makeComputeRegion(host, pwSeq);
+ EXPECT_TRUE(cr.isEffectivelySerial());
+ EXPECT_TRUE(succeeded(host.module->verify()));
+}
+
//===----------------------------------------------------------------------===//
// ComputeRegionOp::wireHoistedValueThroughIns
//===----------------------------------------------------------------------===//
|
Contributor
Author
|
I am abandoning this in favor of #195158 |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The
isEffectivelySerialcheck foracc.compute_regionrequired that all parallelism dimensions be set to 1. However, missing dimensions means that the level of parallelism is not assigned and thus should not be considered. Fix the issue and add unit tests for the API.