-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[NFC][flang][OpenMP] do concurrent to device mapping lit tests
#155992
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| ! Verifies that proper `omp.map.bounds` ops are emitted when an allocatable is | ||
| ! implicitly mapped by a `do concurrent` loop. | ||
|
|
||
| ! RUN: %flang_fc1 -emit-hlfir -fopenmp -fdo-concurrent-to-openmp=device %s -o - \ | ||
| ! RUN: | FileCheck %s | ||
| program main | ||
| implicit none | ||
|
|
||
| integer,parameter :: n = 1000000 | ||
| real, allocatable, dimension(:) :: y | ||
| integer :: i | ||
|
|
||
| allocate(y(1:n)) | ||
|
|
||
| do concurrent(i=1:n) | ||
| y(i) = 42 | ||
| end do | ||
|
|
||
| deallocate(y) | ||
| end program main | ||
|
|
||
| ! CHECK: %[[Y_DECL:.*]]:2 = hlfir.declare %{{.*}} {fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QFEy"} | ||
| ! CHECK: %[[Y_VAL:.*]] = fir.load %[[Y_DECL]]#0 | ||
| ! CHECK: %[[Y_DIM0:.*]]:3 = fir.box_dims %[[Y_VAL]], %{{c0_.*}} | ||
| ! CHECK: %[[Y_LB:.*]] = arith.constant 0 : index | ||
| ! CHECK: %[[Y_UB:.*]] = arith.subi %[[Y_DIM0]]#1, %{{c1_.*}} : index | ||
| ! CHECK: %[[Y_BOUNDS:.*]] = omp.map.bounds lower_bound(%[[Y_LB]] : index) upper_bound(%[[Y_UB]] : index) extent(%[[Y_DIM0]]#1 : index) | ||
| ! CHECK: %[[MEM_MAP:.*]] = omp.map.info {{.*}} bounds(%[[Y_BOUNDS]]) | ||
| ! CHECK: omp.map.info var_ptr(%[[Y_DECL]]#1 : {{.*}}) {{.*}} members(%[[MEM_MAP]] : {{.*}}) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| ! Tests `host_eval` clause code-gen and loop nest bounds on host vs. device. | ||
|
|
||
| ! RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa \ | ||
| ! RUN: -fdo-concurrent-to-openmp=device %s -o - \ | ||
| ! RUN: | FileCheck %s --check-prefix=HOST -vv | ||
|
|
||
| ! RUN: %flang_fc1 -triple amdgcn-amd-amdhsa -emit-hlfir -fopenmp \ | ||
| ! RUN: -fopenmp-is-target-device -fdo-concurrent-to-openmp=device %s -o - \ | ||
| ! RUN: | FileCheck %s --check-prefix=DEVICE | ||
|
|
||
| program do_concurrent_host_eval | ||
| implicit none | ||
| integer :: i, j | ||
|
|
||
| do concurrent (i=1:10, j=1:20) | ||
| end do | ||
| end program do_concurrent_host_eval | ||
|
|
||
| ! HOST: omp.target host_eval( | ||
| ! HOST-SAME: %{{[^[:space:]]+}} -> %[[I_LB:[^,]+]], | ||
| ! HOST-SAME: %{{[^[:space:]]+}} -> %[[I_UB:[^,]+]], | ||
| ! HOST-SAME: %{{[^[:space:]]+}} -> %[[I_ST:[^,]+]], | ||
| ! HOST-SAME: %{{[^[:space:]]+}} -> %[[J_LB:[^,]+]], | ||
| ! HOST-SAME: %{{[^[:space:]]+}} -> %[[J_UB:[^,]+]], | ||
| ! HOST-SAME: %{{[^[:space:]]+}} -> %[[J_ST:[^,]+]] : {{.*}}) map_entries | ||
|
|
||
| ! HOST: omp.loop_nest ({{.*}}, {{.*}}) : index = (%[[I_LB]], %[[J_LB]]) to | ||
| ! HOST-SAME: (%[[I_UB]], %[[J_UB]]) inclusive step | ||
| ! HOST-SAME: (%[[I_ST]], %[[J_ST]]) | ||
|
|
||
| ! DEVICE: omp.target map_entries( | ||
| ! DEVICE-SAME: %{{[^[:space:]]+}} -> %[[I_LB_MAP:[^,]+]], | ||
| ! DEVICE-SAME: %{{[^[:space:]]+}} -> %[[I_UB_MAP:[^,]+]], | ||
| ! DEVICE-SAME: %{{[^[:space:]]+}} -> %[[I_ST_MAP:[^,]+]], | ||
|
|
||
| ! DEVICE-SAME: %{{[^[:space:]]+}} -> %[[J_LB_MAP:[^,]+]], | ||
| ! DEVICE-SAME: %{{[^[:space:]]+}} -> %[[J_UB_MAP:[^,]+]], | ||
| ! DEVICE-SAME: %{{[^[:space:]]+}} -> %[[J_ST_MAP:[^,]+]], | ||
|
|
||
| ! DEVICE-SAME: %{{[^[:space:]]+}} -> %{{[^,]+}}, | ||
| ! DEVICE-SAME: %{{[^[:space:]]+}} -> %{{[^,]+}} : {{.*}}) | ||
|
|
||
| ! DEVICE: %[[I_LB_DECL:.*]]:2 = hlfir.declare %[[I_LB_MAP]] | ||
| ! DEVICE: %[[I_LB:.*]] = fir.load %[[I_LB_DECL]]#1 : !fir.ref<index> | ||
|
|
||
| ! DEVICE: %[[I_UB_DECL:.*]]:2 = hlfir.declare %[[I_UB_MAP]] | ||
| ! DEVICE: %[[I_UB:.*]] = fir.load %[[I_UB_DECL]]#1 : !fir.ref<index> | ||
|
|
||
| ! DEVICE: %[[I_ST_DECL:.*]]:2 = hlfir.declare %[[I_ST_MAP]] | ||
| ! DEVICE: %[[I_ST:.*]] = fir.load %[[I_ST_DECL]]#1 : !fir.ref<index> | ||
|
|
||
| ! DEVICE: %[[J_LB_DECL:.*]]:2 = hlfir.declare %[[J_LB_MAP]] | ||
| ! DEVICE: %[[J_LB:.*]] = fir.load %[[J_LB_DECL]]#1 : !fir.ref<index> | ||
|
|
||
| ! DEVICE: %[[J_UB_DECL:.*]]:2 = hlfir.declare %[[J_UB_MAP]] | ||
| ! DEVICE: %[[J_UB:.*]] = fir.load %[[J_UB_DECL]]#1 : !fir.ref<index> | ||
|
|
||
| ! DEVICE: %[[J_ST_DECL:.*]]:2 = hlfir.declare %[[J_ST_MAP]] | ||
| ! DEVICE: %[[J_ST:.*]] = fir.load %[[J_ST_DECL]]#1 : !fir.ref<index> | ||
|
|
||
| ! DEVICE: omp.loop_nest ({{.*}}, {{.*}}) : index = (%[[I_LB]], %[[J_LB]]) to | ||
| ! DEVICE-SAME: (%[[I_UB]], %[[J_UB]]) inclusive step | ||
| ! DEVICE-SAME: (%[[I_ST]], %[[J_ST]]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| ! Tests mapping of a basic `do concurrent` loop to | ||
| ! `!$omp target teams distribute parallel do`. | ||
| ! RUN: %flang_fc1 -emit-hlfir -fopenmp -fdo-concurrent-to-openmp=device %s -o - \ | ||
| ! RUN: | FileCheck %s | ||
|
|
||
| program do_concurrent_shape | ||
| implicit none | ||
| integer :: a(10, 20) | ||
| integer :: i, j | ||
|
|
||
| do concurrent (i=1:10, j=1:20) | ||
| a(i, j) = i * j | ||
| end do | ||
| end program do_concurrent_shape | ||
|
|
||
| ! CHECK: fir.store %{{c10.*}} to %[[DIM0_EXT:.*]] : !fir.ref<index> | ||
| ! CHECK: fir.store %{{c20.*}} to %[[DIM1_EXT:.*]] : !fir.ref<index> | ||
|
|
||
| ! CHECK: omp.map.info | ||
| ! CHECK: omp.map.info | ||
| ! CHECK: omp.map.info | ||
|
|
||
| ! CHECK: omp.map.info | ||
| ! CHECK: omp.map.info | ||
| ! CHECK: omp.map.info | ||
|
|
||
| ! CHECK: omp.map.info | ||
| ! CHECK: omp.map.info | ||
| ! CHECK: omp.map.info | ||
|
|
||
| ! CHECK: %[[DIM0_EXT_MAP:.*]] = omp.map.info | ||
| ! CHECK-SAME: var_ptr(%[[DIM0_EXT]] : !fir.ref<index>, index) | ||
| ! CHECK-SAME: map_clauses(implicit, exit_release_or_enter_alloc) | ||
| ! CHECK-SAME: capture(ByCopy) -> !fir.ref<index> {name = "_QFEa.extent.dim0"} | ||
|
|
||
| ! CHECK: %[[DIM1_EXT_MAP:.*]] = omp.map.info | ||
| ! CHECK-SAME: var_ptr(%[[DIM1_EXT]] : !fir.ref<index>, index) | ||
| ! CHECK-SAME: map_clauses(implicit, exit_release_or_enter_alloc) | ||
| ! CHECK-SAME: capture(ByCopy) -> !fir.ref<index> {name = "_QFEa.extent.dim1"} | ||
|
|
||
| ! CHECK: omp.target host_eval({{.*}}) map_entries( | ||
| ! CHECK-SAME: %{{[^[:space:]]+}} -> %{{[^,]+}}, | ||
| ! CHECK-SAME: %{{[^[:space:]]+}} -> %{{[^,]+}}, | ||
| ! CHECK-SAME: %{{[^[:space:]]+}} -> %{{[^,]+}}, | ||
| ! CHECK-SAME: %{{[^[:space:]]+}} -> %{{[^,]+}}, | ||
| ! CHECK-SAME: %{{[^[:space:]]+}} -> %{{[^,]+}}, | ||
| ! CHECK-SAME: %{{[^[:space:]]+}} -> %{{[^,]+}}, | ||
| ! CHECK-SAME: %{{[^[:space:]]+}} -> %{{[^,]+}}, | ||
| ! CHECK-SAME: %{{[^[:space:]]+}} -> %{{[^,]+}}, | ||
| ! CHECK-SAME: %{{[^[:space:]]+}} -> %{{[^,]+}}, | ||
| ! CHECK-SAME: %[[DIM0_EXT_MAP]] -> %[[DIM0_EXT_ARG:[^,]+]], | ||
| ! CHECK-SAME: %[[DIM1_EXT_MAP]] -> %[[DIM1_EXT_ARG:[^,]+]] : {{.*}}) | ||
|
|
||
| ! CHECK-DAG: %[[DIM0_EXT_DEV:.*]] = fir.load %[[DIM0_EXT_ARG]] | ||
| ! CHECK-DAG: %[[DIM1_EXT_DEV:.*]] = fir.load %[[DIM1_EXT_ARG]] | ||
|
|
||
| ! CHECK: %[[SHAPE:.*]] = fir.shape %[[DIM0_EXT_DEV]], %[[DIM1_EXT_DEV]] | ||
| ! CHECK: %{{.*}}:2 = hlfir.declare %{{.*}}(%[[SHAPE]]) {uniq_name = "_QFEa"} | ||
|
|
||
| subroutine do_concurrent_shape_shift | ||
| implicit none | ||
| integer :: a(2:10) | ||
| integer :: i | ||
|
|
||
| do concurrent (i=1:10) | ||
| a(i) = i | ||
| end do | ||
| end subroutine do_concurrent_shape_shift | ||
|
|
||
| ! CHECK: fir.store %{{c2.*}} to %[[DIM0_STRT:.*]] : !fir.ref<index> | ||
| ! CHECK: fir.store %{{c9.*}} to %[[DIM0_EXT:.*]] : !fir.ref<index> | ||
|
|
||
| ! CHECK: omp.map.info | ||
| ! CHECK: omp.map.info | ||
| ! CHECK: omp.map.info | ||
|
|
||
| ! CHECK: omp.map.info | ||
| ! CHECK: omp.map.info | ||
|
|
||
| ! CHECK: %[[DIM0_STRT_MAP:.*]] = omp.map.info | ||
| ! CHECK-SAME: var_ptr(%[[DIM0_STRT]] : !fir.ref<index>, index) | ||
| ! CHECK-SAME: map_clauses(implicit, exit_release_or_enter_alloc) | ||
| ! CHECK-SAME: capture(ByCopy) -> !fir.ref<index> {name = "_QF{{.*}}Ea.start_idx.dim0"} | ||
|
|
||
| ! CHECK: %[[DIM0_EXT_MAP:.*]] = omp.map.info | ||
| ! CHECK-SAME: var_ptr(%[[DIM0_EXT]] : !fir.ref<index>, index) | ||
| ! CHECK-SAME: map_clauses(implicit, exit_release_or_enter_alloc) | ||
| ! CHECK-SAME: capture(ByCopy) -> !fir.ref<index> {name = "_QF{{.*}}Ea.extent.dim0"} | ||
|
|
||
| ! CHECK: omp.target host_eval({{.*}}) map_entries( | ||
| ! CHECK-SAME: %{{[^[:space:]]+}} -> %{{[^,]+}}, | ||
| ! CHECK-SAME: %{{[^[:space:]]+}} -> %{{[^,]+}}, | ||
| ! CHECK-SAME: %{{[^[:space:]]+}} -> %{{[^,]+}}, | ||
| ! CHECK-SAME: %{{[^[:space:]]+}} -> %{{[^,]+}}, | ||
| ! CHECK-SAME: %{{[^[:space:]]+}} -> %{{[^,]+}}, | ||
| ! CHECK-SAME: %[[DIM0_STRT_MAP]] -> %[[DIM0_STRT_ARG:[^,]+]], | ||
| ! CHECK-SAME: %[[DIM0_EXT_MAP]] -> %[[DIM0_EXT_ARG:[^,]+]] : {{.*}}) | ||
|
|
||
| ! CHECK-DAG: %[[DIM0_STRT_DEV:.*]] = fir.load %[[DIM0_STRT_ARG]] | ||
| ! CHECK-DAG: %[[DIM0_EXT_DEV:.*]] = fir.load %[[DIM0_EXT_ARG]] | ||
|
|
||
| ! CHECK: %[[SHAPE_SHIFT:.*]] = fir.shape_shift %[[DIM0_STRT_DEV]], %[[DIM0_EXT_DEV]] | ||
| ! CHECK: %{{.*}}:2 = hlfir.declare %{{.*}}(%[[SHAPE_SHIFT]]) {uniq_name = "_QF{{.*}}Ea"} | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
< NIT > I think this test would be more robust if you captured the names of the output values of ops that defined the constants and then matched them to make sure you are getting the 0th dim out of
fir.box_dimsor subtracting 1 in anarith.subiop.Same thing in map_shape_info.f90 below.
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.
Indeed. However, the difficulty of this is that there are constants spread across the IR. So I would have to match all the preceeding constants which will add noise to the test expectations.
Here, I chose instead to match against the constant names as printed by MLIR which I think is stable enough and should be clear that we are matching a 0 or 1 constant based on the name:
c0_...orc1_.... Let me know if you still think this is a bad idea.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.
Aah i see, that's fine then to leave it as is. Trying to match all the (redundant) definitions of the constants and to check that one of them matches this use is overkill. Your current approach is fine by me.