-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[NFC][OpenMP][MLIR] Add MLIR test for lowering parallel if #71788
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NFC][OpenMP][MLIR] Add MLIR test for lowering parallel if #71788
Conversation
@llvm/pr-subscribers-mlir @llvm/pr-subscribers-mlir-llvm Author: Dominik Adamski (DominikAdamski) ChangesAdd test for clause omp target parallel if (parallel : cond ) Test checks if corresponding MLIR construct is correctly lowered to LLVM IR. Full diff: https://github.com/llvm/llvm-project/pull/71788.diff 1 Files Affected:
diff --git a/mlir/test/Target/LLVMIR/omptarget-parallel-llvm.mlir b/mlir/test/Target/LLVMIR/omptarget-parallel-llvm.mlir
index 4457d7f4275260d..160b56f42edf440 100644
--- a/mlir/test/Target/LLVMIR/omptarget-parallel-llvm.mlir
+++ b/mlir/test/Target/LLVMIR/omptarget-parallel-llvm.mlir
@@ -17,6 +17,26 @@ module attributes {dlti.dl_spec = #dlti.dl_spec<#dlti.dl_entry<"dlti.alloca_memo
}
llvm.return
}
+
+ llvm.func @parallel_if(%arg0: !llvm.ptr {fir.bindc_name = "ifcond"}) {
+ %0 = llvm.mlir.constant(1 : i64) : i64
+ %1 = llvm.alloca %0 x i32 {bindc_name = "d"} : (i64) -> !llvm.ptr
+ %2 = omp.map_info var_ptr(%1 : !llvm.ptr, i32) map_clauses(from) capture(ByRef) -> !llvm.ptr {name = "d"}
+ %3 = omp.map_info var_ptr(%arg0 : !llvm.ptr, i32) map_clauses(implicit, exit_release_or_enter_alloc) capture(ByCopy) -> !llvm.ptr {name = "ifcond"}
+ omp.target map_entries(%2 -> %arg1, %3 -> %arg2 : !llvm.ptr, !llvm.ptr) {
+ ^bb0(%arg1: !llvm.ptr, %arg2: !llvm.ptr):
+ %4 = llvm.mlir.constant(10 : i32) : i32
+ %5 = llvm.load %arg2 : !llvm.ptr -> i32
+ %6 = llvm.mlir.constant(0 : i64) : i32
+ %7 = llvm.icmp "ne" %5, %6 : i32
+ omp.parallel if(%7 : i1) {
+ llvm.store %4, %arg1 : i32, !llvm.ptr
+ omp.terminator
+ }
+ omp.terminator
+ }
+ llvm.return
+ }
}
// CHECK: define weak_odr protected amdgpu_kernel void [[FUNC0:@.*]](
@@ -43,3 +63,13 @@ module attributes {dlti.dl_spec = #dlti.dl_spec<#dlti.dl_entry<"dlti.alloca_memo
// CHECK: define internal void [[FUNC1]](
// CHECK-SAME: ptr noalias noundef [[TID_ADDR_ASCAST:%.*]], ptr noalias noundef [[ZERO_ADDR_ASCAST:%.*]], ptr [[TMP0:%.*]]) #[[ATTR0:[0-9]+]] {
+// CHECK: define weak_odr protected amdgpu_kernel void [[FUNC2:@.*]](
+// CHECK-SAME: ptr [[IFCOND_ARG0:%.*]], ptr [[IFCOND_ARG1:.*]], ptr [[IFCOND_ARG2:.*]]) {
+// CHECK: store ptr [[IFCOND_ARG2]], ptr [[IFCOND_TMP1:%.]], align 8
+// CHECK: [[IFCOND_TMP2:%.*]] = load i32, ptr [[IFCOND_TMP1]], align 4
+// CHECK: [[IFCOND_TMP3:%.*]] = icmp ne i32 [[IFCOND_TMP2]], 0
+// CHECK: [[IFCOND_TMP4:%.*]] = sext i1 [[IFCOND_TMP3]] to i32
+// CHECK: call void @__kmpc_parallel_51(ptr addrspacecast (
+// CHECK-SAME: ptr addrspace(1) @[[IFCOND_GLOB:[0-9]+]] to ptr),
+// CHECK-SAME: i32 [[IFCOND_THREAD_NUM:%.*]], i32 [[IFCOND_TMP4]], i32 -1,
+// CHECK-SAME: i32 -1, ptr [[FUNC1:@.*]], ptr null, ptr [[IFCOND_TMP5:%.*]], i64 1)
|
Add test for clause omp target parallel if (parallel : cond ) Test checks if corresponding MLIR construct is correctly lowered to LLVM IR.
f397391
to
6682a44
Compare
Can you add some more comments about |
I added comments in test file. They explain the purpose of given test. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, generally, the %
in the mlir SSA value is not captured usually. Only the name or number is captured.
// CHECK: %[[VAL_0:.*]] = alloca [1 x ptr], align 8
Also, only capture the values that are required for the checks. Others can be skipped using {{.*}}
.
// CHECK: define weak_odr protected amdgpu_kernel void [[FUNC_NUM_THREADS0:@.*]]( | ||
// CHECK-NOT: call void @__kmpc_push_num_threads( | ||
// CHECK: call void @__kmpc_parallel_51(ptr addrspacecast ( | ||
// CHECK-SAME: ptr addrspace(1) @[[NUM_THREADS_GLOB:[0-9]+]] to ptr), | ||
// CHECK-SAME: i32 [[NUM_THREADS_TMP0:%.*]], i32 1, i32 156, | ||
// CHECK-SAME: i32 -1, ptr [[FUNC_NUM_THREADS1:@.*]], ptr null, ptr [[NUM_THREADS_TMP1:%.*]], i64 1) | ||
|
||
// The one of arguments of kmpc_parallel_51 function is responsible for handling if clause |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// The one of arguments of kmpc_parallel_51 function is responsible for handling if clause | |
// One of the arguments of kmpc_parallel_51 function is responsible for handling if clause |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
// is correctly lowered to LLVM IR code and the if condition variable | ||
// is passed as a param to kmpc_parallel_51 function | ||
|
||
// CHECK: define weak_odr protected amdgpu_kernel void [[FUNC2:@.*]]( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How did this amdgpu_kernel
name appear? Is that from the target triple?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, please see function void OpenMPIRBuilder::setOutlinedTargetRegionFunctionAttributes
: https://github.com/llvm/llvm-project/blob/main/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp#L4489
|
||
// CHECK: define weak_odr protected amdgpu_kernel void [[FUNC2:@.*]]( | ||
// CHECK-SAME: ptr [[IFCOND_ARG0:%.*]], ptr [[IFCOND_ARG1:.*]], ptr [[IFCOND_ARG2:.*]]) { | ||
// CHECK: store ptr [[IFCOND_ARG2]], ptr [[IFCOND_TMP1:%.]], align 8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// CHECK: store ptr [[IFCOND_ARG2]], ptr [[IFCOND_TMP1:%.]], align 8 | |
// CHECK: store ptr [[IFCOND_ARG2]], ptr [[IFCOND_TMP1:%.*]], align 8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
|
||
// CHECK: define weak_odr protected amdgpu_kernel void [[FUNC2:@.*]]( | ||
// CHECK-SAME: ptr [[IFCOND_ARG0:%.*]], ptr [[IFCOND_ARG1:.*]], ptr [[IFCOND_ARG2:.*]]) { | ||
// CHECK: store ptr [[IFCOND_ARG2]], ptr [[IFCOND_TMP1:%.]], align 8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like IFCOND_ARG2
is the important argument here. If others are not used then no need to capture them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LG.
Add test for clause omp target parallel if (parallel : cond )
Test checks if corresponding MLIR construct is correctly lowered to LLVM IR.