[Mlir-commits] [mlir] 5defa85 - [mlir][acc] Improve verifier messages for device_type duplicates (#170773)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Dec 4 15:52:56 PST 2025
Author: Razvan Lupusoru
Date: 2025-12-04T15:52:53-08:00
New Revision: 5defa851bd739d3796816bb412f5855d477bb9e7
URL: https://github.com/llvm/llvm-project/commit/5defa851bd739d3796816bb412f5855d477bb9e7
DIFF: https://github.com/llvm/llvm-project/commit/5defa851bd739d3796816bb412f5855d477bb9e7.diff
LOG: [mlir][acc] Improve verifier messages for device_type duplicates (#170773)
This improves the acc dialect IR verifier messages when duplicate
device_types are found by also noting which device_type is the one
causing the error.
Added:
Modified:
mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
mlir/test/Dialect/OpenACC/invalid.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp b/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
index 7b91393c0314f..64bbb1e91f293 100644
--- a/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
+++ b/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
@@ -3028,19 +3028,21 @@ bool hasDuplicateDeviceTypes(
}
/// Check for duplicates in the DeviceType array attribute.
-LogicalResult checkDeviceTypes(mlir::ArrayAttr deviceTypes) {
+/// Returns std::nullopt if no duplicates, or the duplicate DeviceType if found.
+static std::optional<mlir::acc::DeviceType>
+checkDeviceTypes(mlir::ArrayAttr deviceTypes) {
llvm::SmallSet<mlir::acc::DeviceType, 3> crtDeviceTypes;
if (!deviceTypes)
- return success();
+ return std::nullopt;
for (auto attr : deviceTypes) {
auto deviceTypeAttr =
mlir::dyn_cast_or_null<mlir::acc::DeviceTypeAttr>(attr);
if (!deviceTypeAttr)
- return failure();
+ return mlir::acc::DeviceType::None;
if (!crtDeviceTypes.insert(deviceTypeAttr.getValue()).second)
- return failure();
+ return deviceTypeAttr.getValue();
}
- return success();
+ return std::nullopt;
}
LogicalResult acc::LoopOp::verify() {
@@ -3067,9 +3069,10 @@ LogicalResult acc::LoopOp::verify() {
getCollapseDeviceTypeAttr().getValue().size())
return emitOpError() << "collapse attribute count must match collapse"
<< " device_type count";
- if (failed(checkDeviceTypes(getCollapseDeviceTypeAttr())))
- return emitOpError()
- << "duplicate device_type found in collapseDeviceType attribute";
+ if (auto duplicateDeviceType = checkDeviceTypes(getCollapseDeviceTypeAttr()))
+ return emitOpError() << "duplicate device_type `"
+ << acc::stringifyDeviceType(*duplicateDeviceType)
+ << "` found in collapseDeviceType attribute";
// Check gang
if (!getGangOperands().empty()) {
@@ -3082,8 +3085,12 @@ LogicalResult acc::LoopOp::verify() {
return emitOpError() << "gangOperandsArgType attribute count must match"
<< " gangOperands count";
}
- if (getGangAttr() && failed(checkDeviceTypes(getGangAttr())))
- return emitOpError() << "duplicate device_type found in gang attribute";
+ if (getGangAttr()) {
+ if (auto duplicateDeviceType = checkDeviceTypes(getGangAttr()))
+ return emitOpError() << "duplicate device_type `"
+ << acc::stringifyDeviceType(*duplicateDeviceType)
+ << "` found in gang attribute";
+ }
if (failed(verifyDeviceTypeAndSegmentCountMatch(
*this, getGangOperands(), getGangOperandsSegmentsAttr(),
@@ -3091,22 +3098,30 @@ LogicalResult acc::LoopOp::verify() {
return failure();
// Check worker
- if (failed(checkDeviceTypes(getWorkerAttr())))
- return emitOpError() << "duplicate device_type found in worker attribute";
- if (failed(checkDeviceTypes(getWorkerNumOperandsDeviceTypeAttr())))
- return emitOpError() << "duplicate device_type found in "
- "workerNumOperandsDeviceType attribute";
+ if (auto duplicateDeviceType = checkDeviceTypes(getWorkerAttr()))
+ return emitOpError() << "duplicate device_type `"
+ << acc::stringifyDeviceType(*duplicateDeviceType)
+ << "` found in worker attribute";
+ if (auto duplicateDeviceType =
+ checkDeviceTypes(getWorkerNumOperandsDeviceTypeAttr()))
+ return emitOpError() << "duplicate device_type `"
+ << acc::stringifyDeviceType(*duplicateDeviceType)
+ << "` found in workerNumOperandsDeviceType attribute";
if (failed(verifyDeviceTypeCountMatch(*this, getWorkerNumOperands(),
getWorkerNumOperandsDeviceTypeAttr(),
"worker")))
return failure();
// Check vector
- if (failed(checkDeviceTypes(getVectorAttr())))
- return emitOpError() << "duplicate device_type found in vector attribute";
- if (failed(checkDeviceTypes(getVectorOperandsDeviceTypeAttr())))
- return emitOpError() << "duplicate device_type found in "
- "vectorOperandsDeviceType attribute";
+ if (auto duplicateDeviceType = checkDeviceTypes(getVectorAttr()))
+ return emitOpError() << "duplicate device_type `"
+ << acc::stringifyDeviceType(*duplicateDeviceType)
+ << "` found in vector attribute";
+ if (auto duplicateDeviceType =
+ checkDeviceTypes(getVectorOperandsDeviceTypeAttr()))
+ return emitOpError() << "duplicate device_type `"
+ << acc::stringifyDeviceType(*duplicateDeviceType)
+ << "` found in vectorOperandsDeviceType attribute";
if (failed(verifyDeviceTypeCountMatch(*this, getVectorOperands(),
getVectorOperandsDeviceTypeAttr(),
"vector")))
@@ -4096,7 +4111,8 @@ LogicalResult acc::RoutineOp::verify() {
if (parallelism > 1 || (baseParallelism == 1 && parallelism == 1))
return emitError() << "only one of `gang`, `worker`, `vector`, `seq` can "
- "be present at the same time";
+ "be present at the same time for device_type `"
+ << acc::stringifyDeviceType(dtype) << "`";
}
return success();
diff --git a/mlir/test/Dialect/OpenACC/invalid.mlir b/mlir/test/Dialect/OpenACC/invalid.mlir
index 6c5f8f63815b4..d1a1c93800264 100644
--- a/mlir/test/Dialect/OpenACC/invalid.mlir
+++ b/mlir/test/Dialect/OpenACC/invalid.mlir
@@ -76,27 +76,65 @@ acc.loop {
// -----
-// expected-error at +1 {{'acc.loop' op duplicate device_type found in gang attribute}}
+// expected-error at +1 {{'acc.loop' op duplicate device_type `none` found in gang attribute}}
acc.loop {
acc.yield
} attributes {gang = [#acc.device_type<none>, #acc.device_type<none>]}
// -----
-// expected-error at +1 {{'acc.loop' op duplicate device_type found in worker attribute}}
+// expected-error at +1 {{'acc.loop' op duplicate device_type `none` found in worker attribute}}
acc.loop {
acc.yield
} attributes {worker = [#acc.device_type<none>, #acc.device_type<none>]}
// -----
-// expected-error at +1 {{'acc.loop' op duplicate device_type found in vector attribute}}
+// expected-error at +1 {{'acc.loop' op duplicate device_type `none` found in vector attribute}}
acc.loop {
acc.yield
} attributes {vector = [#acc.device_type<none>, #acc.device_type<none>]}
// -----
+// expected-error at +1 {{'acc.loop' op duplicate device_type `nvidia` found in gang attribute}}
+acc.loop {
+ acc.yield
+} attributes {gang = [#acc.device_type<nvidia>, #acc.device_type<nvidia>]}
+
+// -----
+
+// expected-error at +1 {{'acc.loop' op duplicate device_type `none` found in collapseDeviceType attribute}}
+acc.loop {
+ acc.yield
+} attributes {collapse = [1, 1], collapseDeviceType = [#acc.device_type<none>, #acc.device_type<none>], independent = [#acc.device_type<none>]}
+
+// -----
+
+%i64value = arith.constant 1 : i64
+// expected-error at +1 {{'acc.loop' op duplicate device_type `none` found in workerNumOperandsDeviceType attribute}}
+acc.loop worker(%i64value: i64, %i64value: i64) {
+ acc.yield
+} attributes {workerNumOperandsDeviceType = [#acc.device_type<none>, #acc.device_type<none>], independent = [#acc.device_type<none>]}
+
+// -----
+
+%i64value = arith.constant 1 : i64
+// expected-error at +1 {{'acc.loop' op duplicate device_type `none` found in vectorOperandsDeviceType attribute}}
+acc.loop vector(%i64value: i64, %i64value: i64) {
+ acc.yield
+} attributes {vectorOperandsDeviceType = [#acc.device_type<none>, #acc.device_type<none>], independent = [#acc.device_type<none>]}
+
+// -----
+
+func.func @acc_routine_parallelism() -> () {
+ return
+}
+// expected-error at +1 {{only one of `gang`, `worker`, `vector`, `seq` can be present at the same time for device_type `nvidia`}}
+"acc.routine"() <{func_name = @acc_routine_parallelism, sym_name = "acc_routine_parallelism_rout", gang = [#acc.device_type<nvidia>], worker = [#acc.device_type<nvidia>]}> : () -> ()
+
+// -----
+
%1 = arith.constant 1 : i32
%2 = arith.constant 10 : i32
// expected-error at +1 {{only one of auto, independent, seq can be present at the same time}}
More information about the Mlir-commits
mailing list