Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 22f22aa

Browse filesBrowse files
committed
[MLIR][OpenMP] Simplify OpenMP device codegen
After removing host operations from the device MLIR module, it is no longer necessary to provide special codegen logic to prevent these operations from causing compiler crashes or miscompilations. This patch removes these now unnecessary code paths to simplify codegen logic. Some MLIR tests are now replaced with Flang tests, since the responsibility of dealing with host operations has been moved earlier in the compilation flow. MLIR tests holding target device modules are updated to no longer include now unsupported host operations.
1 parent 67313f1 commit 22f22aa
Copy full SHA for 22f22aa
Expand file treeCollapse file tree

12 files changed

+409
-588
lines changed
+87Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
!===----------------------------------------------------------------------===!
2+
! This directory can be used to add Integration tests involving multiple
3+
! stages of the compiler (for eg. from Fortran to LLVM IR). It should not
4+
! contain executable tests. We should only add tests here sparingly and only
5+
! if there is no other way to test. Repeat this message in each test that is
6+
! added to this directory and sub-directories.
7+
!===----------------------------------------------------------------------===!
8+
9+
!REQUIRES: amdgpu-registered-target
10+
!RUN: %flang_fc1 -triple amdgcn-amd-amdhsa -emit-llvm -fopenmp -fopenmp-version=50 -fopenmp-is-target-device %s -o - | FileCheck %s
11+
12+
! CHECK-NOT: define void @nested_target_in_parallel
13+
! CHECK: define weak_odr protected amdgpu_kernel void @__omp_offloading_{{.*}}_nested_target_in_parallel_{{.*}}(ptr %{{.*}}, ptr %{{.*}})
14+
subroutine nested_target_in_parallel(v)
15+
implicit none
16+
integer, intent(inout) :: v(10)
17+
18+
!$omp parallel
19+
!$omp target map(tofrom: v)
20+
!$omp end target
21+
!$omp end parallel
22+
end subroutine
23+
24+
! CHECK-NOT: define void @nested_target_in_wsloop
25+
! CHECK: define weak_odr protected amdgpu_kernel void @__omp_offloading_{{.*}}_nested_target_in_wsloop_{{.*}}(ptr %{{.*}}, ptr %{{.*}})
26+
subroutine nested_target_in_wsloop(v)
27+
implicit none
28+
integer, intent(inout) :: v(10)
29+
integer :: i
30+
31+
!$omp do
32+
do i=1, 10
33+
!$omp target map(tofrom: v)
34+
!$omp end target
35+
end do
36+
end subroutine
37+
38+
! CHECK-NOT: define void @nested_target_in_parallel_with_private
39+
! CHECK: define weak_odr protected amdgpu_kernel void @__omp_offloading_{{.*}}_nested_target_in_parallel_with_private_{{.*}}(ptr %{{.*}}, ptr %{{.*}}, ptr %{{.*}})
40+
subroutine nested_target_in_parallel_with_private(v)
41+
implicit none
42+
integer, intent(inout) :: v(10)
43+
integer :: x
44+
x = 10
45+
46+
!$omp parallel firstprivate(x)
47+
!$omp target map(tofrom: v(1:x))
48+
!$omp end target
49+
!$omp end parallel
50+
end subroutine
51+
52+
! CHECK-NOT: define void @nested_target_in_task_with_private
53+
! CHECK: define weak_odr protected amdgpu_kernel void @__omp_offloading_{{.*}}_nested_target_in_task_with_private_{{.*}}(ptr %{{.*}}, ptr %{{.*}}, ptr %{{.*}})
54+
subroutine nested_target_in_task_with_private(v)
55+
implicit none
56+
integer, intent(inout) :: v(10)
57+
integer :: x
58+
x = 10
59+
60+
!$omp task firstprivate(x)
61+
!$omp target map(tofrom: v(1:x))
62+
!$omp end target
63+
!$omp end task
64+
end subroutine
65+
66+
! CHECK-NOT: define void @target_and_atomic_update
67+
! CHECK: define weak_odr protected amdgpu_kernel void @__omp_offloading_{{.*}}_target_and_atomic_update_{{.*}}(ptr %{{.*}})
68+
subroutine target_and_atomic_update(x, expr)
69+
implicit none
70+
integer, intent(inout) :: x, expr
71+
72+
!$omp target
73+
!$omp end target
74+
75+
!$omp atomic update
76+
x = x + expr
77+
end subroutine
78+
79+
! CHECK-NOT: define void @nested_target_in_associate
80+
! CHECK: define weak_odr protected amdgpu_kernel void @__omp_offloading_{{.*}}_nested_target_in_associate_{{.*}}(ptr %{{.*}}, ptr %{{.*}}, ptr %{{.*}})
81+
subroutine nested_target_in_associate(x)
82+
integer, pointer, contiguous :: x(:)
83+
associate(y => x)
84+
!$omp target map(tofrom: y)
85+
!$omp end target
86+
end associate
87+
end subroutine
+37Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
!===----------------------------------------------------------------------===!
2+
! This directory can be used to add Integration tests involving multiple
3+
! stages of the compiler (for eg. from Fortran to LLVM IR). It should not
4+
! contain executable tests. We should only add tests here sparingly and only
5+
! if there is no other way to test. Repeat this message in each test that is
6+
! added to this directory and sub-directories.
7+
!===----------------------------------------------------------------------===!
8+
9+
!REQUIRES: amdgpu-registered-target
10+
!RUN: %flang_fc1 -triple amdgcn-amd-amdhsa -emit-llvm -fopenmp -fopenmp-version=50 -fopenmp-is-target-device %s -o - | FileCheck %s
11+
12+
! This tests the fix for https://github.com/llvm/llvm-project/issues/84606
13+
! We are only interested in ensuring that the -mlir-to-llmvir pass doesn't crash.
14+
15+
! CHECK: define weak_odr protected amdgpu_kernel void @{{.*}}QQmain{{.*}}({{.*}})
16+
program main
17+
implicit none
18+
integer, parameter :: N = 5
19+
integer, dimension(5) :: a
20+
integer :: i
21+
integer :: target_a = 0
22+
23+
!$omp task depend(out:a)
24+
do i = 1, N
25+
a(i) = i
26+
end do
27+
!$omp end task
28+
29+
!$omp target map(tofrom:target_a) map(tofrom:a)
30+
do i = 1, N
31+
target_a = target_a + i
32+
a(i) = a(i) + i
33+
end do
34+
!$omp end target
35+
print*, target_a
36+
print*, a
37+
end program main
+40Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
!===----------------------------------------------------------------------===!
2+
! This directory can be used to add Integration tests involving multiple
3+
! stages of the compiler (for eg. from Fortran to LLVM IR). It should not
4+
! contain executable tests. We should only add tests here sparingly and only
5+
! if there is no other way to test. Repeat this message in each test that is
6+
! added to this directory and sub-directories.
7+
!===----------------------------------------------------------------------===!
8+
9+
!REQUIRES: amdgpu-registered-target
10+
!RUN: %flang_fc1 -triple amdgcn-amd-amdhsa -emit-llvm -fopenmp -fopenmp-version=50 -fopenmp-is-target-device %s -o - | FileCheck %s
11+
12+
! The aim of this test is to verify host threadprivate directives do not cause
13+
! crashes during OpenMP target device codegen when used in conjunction with
14+
! target code in the same function.
15+
16+
! CHECK: define weak_odr protected amdgpu_kernel void @{{.*}}(ptr %{{.*}}, ptr %[[ARG1:.*]], ptr %[[ARG2:.*]]) #{{[0-9]+}} {
17+
! CHECK: %[[ALLOCA_X:.*]] = alloca ptr, align 8, addrspace(5)
18+
! CHECK: %[[ASCAST_X:.*]] = addrspacecast ptr addrspace(5) %[[ALLOCA_X]] to ptr
19+
! CHECK: store ptr %[[ARG1]], ptr %[[ASCAST_X]], align 8
20+
21+
! CHECK: %[[ALLOCA_N:.*]] = alloca ptr, align 8, addrspace(5)
22+
! CHECK: %[[ASCAST_N:.*]] = addrspacecast ptr addrspace(5) %[[ALLOCA_N]] to ptr
23+
! CHECK: store ptr %[[ARG2]], ptr %[[ASCAST_N]], align 8
24+
25+
! CHECK: %[[LOAD_X:.*]] = load ptr, ptr %[[ASCAST_X]], align 8
26+
! CHECK: call void @bar_(ptr %[[LOAD_X]], ptr %[[ASCAST_N]])
27+
28+
module test
29+
implicit none
30+
integer :: n
31+
!$omp threadprivate(n)
32+
33+
contains
34+
subroutine foo(x)
35+
integer, intent(inout) :: x(10)
36+
!$omp target map(tofrom: x(1:n))
37+
call bar(x, n)
38+
!$omp end target
39+
end subroutine
40+
end module

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.