Skip to content

Commit d9bab33

Browse files
authored
[mlir][OpenMP] add verifier and tests for cancel taskgroup (#137154)
1 parent 194da37 commit d9bab33

File tree

3 files changed

+95
-2
lines changed

3 files changed

+95
-2
lines changed

mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -3216,7 +3216,11 @@ LogicalResult CancelOp::verify() {
32163216
<< "must not have a nowait clause";
32173217
}
32183218
}
3219-
// TODO : Add more when we support taskgroup.
3219+
if ((cct == ClauseCancellationConstructType::Taskgroup) &&
3220+
!mlir::isa<omp::TaskOp>(structuralParent)) {
3221+
return emitOpError() << "cancel taskgroup must appear "
3222+
<< "inside a task region";
3223+
}
32203224
return success();
32213225
}
32223226

@@ -3253,7 +3257,11 @@ LogicalResult CancellationPointOp::verify() {
32533257
return emitOpError() << "cancellation point sections must appear "
32543258
<< "inside a sections region";
32553259
}
3256-
// TODO : Add more when we support taskgroup.
3260+
if ((cct == ClauseCancellationConstructType::Taskgroup) &&
3261+
!mlir::isa<omp::TaskOp>(structuralParent)) {
3262+
return emitOpError() << "cancellation point taskgroup must appear "
3263+
<< "inside a task region";
3264+
}
32573265
return success();
32583266
}
32593267

mlir/test/Dialect/OpenMP/invalid.mlir

+24
Original file line numberDiff line numberDiff line change
@@ -1754,6 +1754,18 @@ func.func @omp_cancel2() {
17541754

17551755
// -----
17561756

1757+
func.func @omp_cancel_taskloop() {
1758+
omp.sections {
1759+
// expected-error @below {{cancel taskgroup must appear inside a task region}}
1760+
omp.cancel cancellation_construct_type(taskgroup)
1761+
// CHECK: omp.terminator
1762+
omp.terminator
1763+
}
1764+
return
1765+
}
1766+
1767+
// -----
1768+
17571769
func.func @omp_cancel3(%arg1 : i32, %arg2 : i32, %arg3 : i32) -> () {
17581770
omp.wsloop nowait {
17591771
omp.loop_nest (%0) : i32 = (%arg1) to (%arg2) step (%arg3) {
@@ -1841,6 +1853,18 @@ func.func @omp_cancellationpoint2() {
18411853

18421854
// -----
18431855

1856+
func.func @omp_cancellationpoint_taskgroup() {
1857+
omp.sections {
1858+
// expected-error @below {{cancellation point taskgroup must appear inside a task region}}
1859+
omp.cancellation_point cancellation_construct_type(taskgroup)
1860+
// CHECK: omp.terminator
1861+
omp.terminator
1862+
}
1863+
return
1864+
}
1865+
1866+
// -----
1867+
18441868
omp.declare_reduction @add_f32 : f32
18451869
init {
18461870
^bb0(%arg: f32):

mlir/test/Dialect/OpenMP/ops.mlir

+61
Original file line numberDiff line numberDiff line change
@@ -2201,6 +2201,20 @@ func.func @omp_cancel_sections() -> () {
22012201
return
22022202
}
22032203

2204+
func.func @omp_cancel_taskgroup() -> () {
2205+
omp.taskgroup {
2206+
omp.task {
2207+
// CHECK: omp.cancel cancellation_construct_type(taskgroup)
2208+
omp.cancel cancellation_construct_type(taskgroup)
2209+
// CHECK: omp.terminator
2210+
omp.terminator
2211+
}
2212+
// CHECK: omp.terminator
2213+
omp.terminator
2214+
}
2215+
return
2216+
}
2217+
22042218
func.func @omp_cancel_parallel_nested(%if_cond : i1) -> () {
22052219
omp.parallel {
22062220
scf.if %if_cond {
@@ -2243,6 +2257,22 @@ func.func @omp_cancel_sections_nested(%if_cond : i1) -> () {
22432257
return
22442258
}
22452259

2260+
func.func @omp_cancel_taskgroup_nested(%if_cond : i1) -> () {
2261+
omp.taskgroup {
2262+
omp.task {
2263+
scf.if %if_cond {
2264+
// CHECK: omp.cancel cancellation_construct_type(taskgroup)
2265+
omp.cancel cancellation_construct_type(taskgroup)
2266+
}
2267+
// CHECK: omp.terminator
2268+
omp.terminator
2269+
}
2270+
// CHECK: omp.terminator
2271+
omp.terminator
2272+
}
2273+
return
2274+
}
2275+
22462276
func.func @omp_cancellationpoint_parallel() -> () {
22472277
omp.parallel {
22482278
// CHECK: omp.cancellation_point cancellation_construct_type(parallel)
@@ -2283,6 +2313,22 @@ func.func @omp_cancellationpoint_sections() -> () {
22832313
return
22842314
}
22852315

2316+
func.func @omp_cancellationpoint_taskgroup() -> () {
2317+
omp.taskgroup {
2318+
omp.task {
2319+
// CHECK: omp.cancellation_point cancellation_construct_type(taskgroup)
2320+
omp.cancellation_point cancellation_construct_type(taskgroup)
2321+
// CHECK: omp.cancel cancellation_construct_type(taskgroup)
2322+
omp.cancel cancellation_construct_type(taskgroup)
2323+
// CHECK: omp.terminator
2324+
omp.terminator
2325+
}
2326+
// CHECK: omp.terminator
2327+
omp.terminator
2328+
}
2329+
return
2330+
}
2331+
22862332
func.func @omp_cancellationpoint_parallel_nested(%if_cond : i1) -> () {
22872333
omp.parallel {
22882334
scf.if %if_cond {
@@ -2323,6 +2369,21 @@ func.func @omp_cancellationpoint_sections_nested(%if_cond : i1) -> () {
23232369
return
23242370
}
23252371

2372+
func.func @omp_cancellationpoint_taskgroup_nested(%if_cond : i1) -> () {
2373+
omp.taskgroup {
2374+
omp.task {
2375+
scf.if %if_cond {
2376+
// CHECK: omp.cancellation_point cancellation_construct_type(taskgroup)
2377+
omp.cancellation_point cancellation_construct_type(taskgroup)
2378+
}
2379+
omp.terminator
2380+
}
2381+
// CHECK: omp.terminator
2382+
omp.terminator
2383+
}
2384+
return
2385+
}
2386+
23262387
// CHECK-LABEL: @omp_taskgroup_no_tasks
23272388
func.func @omp_taskgroup_no_tasks() -> () {
23282389

0 commit comments

Comments
 (0)