[Mlir-commits] [mlir] [mlir][GPU] Verify known_{block, grid, cluster}_size is non-negative (PR #179886)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Feb 5 00:52:07 PST 2026
https://github.com/woruyu created https://github.com/llvm/llvm-project/pull/179886
### Summary
This PR resolves https://github.com/llvm/llvm-project/issues/179604
>From 3de024a0647c1576e30efb83be48a24f2fb250ba Mon Sep 17 00:00:00 2001
From: woruyu <1214539920 at qq.com>
Date: Thu, 5 Feb 2026 16:49:50 +0800
Subject: [PATCH] [mlir][GPU] Verify known_{block,grid,cluster}_size is
non-negative
---
mlir/include/mlir/Dialect/GPU/IR/GPUOps.td | 19 ++++++++++++++++---
mlir/test/Dialect/GPU/invalid.mlir | 13 ++++++++++++-
2 files changed, 28 insertions(+), 4 deletions(-)
diff --git a/mlir/include/mlir/Dialect/GPU/IR/GPUOps.td b/mlir/include/mlir/Dialect/GPU/IR/GPUOps.td
index 7891cf19ac921..e5847254e80f2 100644
--- a/mlir/include/mlir/Dialect/GPU/IR/GPUOps.td
+++ b/mlir/include/mlir/Dialect/GPU/IR/GPUOps.td
@@ -347,9 +347,22 @@ def GPU_SubgroupSizeOp : GPU_Op<"subgroup_size", [
let assemblyFormat = "(`upper_bound` $upper_bound^)? attr-dict `:` type($result)";
}
-def GPU_OptionalDimSizeHintAttr : ConfinedAttr<OptionalAttr<DenseI32ArrayAttr>,
- [AttrConstraint<Or<[IsNullAttr.predicate, DenseArrayCount<3>.predicate]>,
- "with 3 elements (if present)">]>;
+def GPU_OptionalDimSizeHintAttr : ConfinedAttr<
+ OptionalAttr<DenseI32ArrayAttr>,
+ [AttrConstraint<
+ Or<[
+ IsNullAttr.predicate,
+ And<[
+ DenseArrayCount<3>.predicate,
+ CPred<"([](mlir::Attribute a) { "
+ " auto arr = ::llvm::cast<::mlir::DenseI32ArrayAttr>(a).asArrayRef();"
+ " return ::llvm::all_of(arr, [](int32_t v) { return v >= 0; });"
+ "})($_self)">
+ ]>
+ ]>,
+ "with 3 elements (if present) and all elements >= 0"
+ >]
+>;
def GPU_GPUFuncOp : GPU_Op<"func", [
HasParent<"GPUModuleOp">, AutomaticAllocationScope, FunctionOpInterface,
diff --git a/mlir/test/Dialect/GPU/invalid.mlir b/mlir/test/Dialect/GPU/invalid.mlir
index 9c338e06f1b26..9620db43e6f17 100644
--- a/mlir/test/Dialect/GPU/invalid.mlir
+++ b/mlir/test/Dialect/GPU/invalid.mlir
@@ -816,7 +816,7 @@ module attributes {gpu.container_module} {
module attributes {gpu.container_module} {
gpu.module @kernel {
- // expected-error at +1 {{'gpu.func' op attribute 'known_block_size' failed to satisfy constraint: i32 dense array attribute with 3 elements (if present)}}
+ // expected-error at +1 {{'gpu.func' op attribute 'known_block_size' failed to satisfy constraint: i32 dense array attribute with 3 elements (if present) and all elements >= 0}}
gpu.func @kernel() kernel attributes {known_block_size = array<i32: 2, 1>} {
gpu.return
}
@@ -825,6 +825,17 @@ module attributes {gpu.container_module} {
// -----
+module attributes {gpu.container_module} {
+ gpu.module @kernel {
+ // expected-error at +1 {{'gpu.func' op attribute 'known_block_size' failed to satisfy constraint: i32 dense array attribute with 3 elements (if present) and all elements >= 0}}
+ gpu.func @kernel() kernel attributes {known_block_size = array<i32: 2, 1, -1>} {
+ gpu.return
+ }
+ }
+}
+
+// -----
+
module {
// expected-error at +1 {{'func.func' op gpu.known_block_size must contain exactly 3 elements}}
func.func @kernel() attributes {gpu.known_block_size = array<i32: 2, 1>} {
More information about the Mlir-commits
mailing list