Skip to content

Commit 1bb2af6

Browse files
committed
[mlir][gpu] Add verification to disallow nested gpu.launch ops
This PR adds a verification check in `LaunchOp::verify()` to disallow nested `gpu.launch` operations. Nested `gpu.launch` is currently unsupported and can lead to undefined or unintended behavior during lowering. This change ensures that such cases are caught early during IR verification.
1 parent ed5bd23 commit 1bb2af6

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

mlir/lib/Dialect/GPU/IR/GPUDialect.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,9 @@ LogicalResult LaunchOp::verify() {
866866
if (!(hasClusterSize()) &&
867867
(getClusterSizeX() || getClusterSizeY() || getClusterSizeZ()))
868868
return emitOpError() << "cluster size must be all present";
869+
870+
if (getOperation()->getParentOfType<LaunchOp>())
871+
return emitOpError() << "not support nested launches";
869872
return success();
870873
}
871874

mlir/test/Dialect/GPU/invalid.mlir

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,21 @@ func.func @launch_requires_gpu_return(%sz : index) {
3535

3636
// -----
3737

38+
func.func @nested_launches(%sz : index) {
39+
gpu.launch blocks(%bx, %by, %bz) in (%sbx = %sz, %sby = %sz, %sbz = %sz)
40+
threads(%tx, %ty, %tz) in (%stx = %sz, %sty = %sz, %stz = %sz) {
41+
// @expected-error@+1 {{'gpu.launch' op not support nested launches}}
42+
gpu.launch blocks(%bx1, %by1, %bz1) in (%sbx1 = %sz, %sby1 = %sz, %sbz1 = %sz)
43+
threads(%tx1, %ty1, %tz1) in (%stx1 = %sz, %sty1 = %sz, %stz1 = %sz) {
44+
gpu.terminator
45+
}
46+
gpu.terminator
47+
}
48+
return
49+
}
50+
51+
// -----
52+
3853
func.func @launch_func_too_few_operands(%sz : index) {
3954
// expected-error@+1 {{expected 6 or more operands}}
4055
"gpu.launch_func"(%sz, %sz, %sz, %sz, %sz)

0 commit comments

Comments
 (0)