Skip to content

[openmp][flang] Add tests for map clause #70394

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 1 commit into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
! REQUIRES: flang, amdgcn-amd-amdhsa
! UNSUPPORTED: nvptx64-nvidia-cuda
! UNSUPPORTED: nvptx64-nvidia-cuda-LTO
! UNSUPPORTED: aarch64-unknown-linux-gnu
! UNSUPPORTED: aarch64-unknown-linux-gnu-LTO
! UNSUPPORTED: x86_64-pc-linux-gnu
! UNSUPPORTED: x86_64-pc-linux-gnu-LTO

! RUN: %libomptarget-compile-fortran-run-and-check-generic
! XFAIL: *

program main
use omp_lib
integer :: devices(2), var1
common var1
var1 = 10
print *, "var1 before target = ", var1
devices(1) = omp_get_device_num()
!$omp target map(tofrom:devices) map(tofrom:var1)
var1 = 20
devices(2) = omp_get_device_num()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome to see this working! :D admittedly have never tried it

!$omp end target
print *, "var1 after target = ", var1
print *, "devices: ", devices
end program

! CHECK: var1 before target = 10
! CHECK: var1 after target = 20
! CHECK: devices: 1 0
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
! REQUIRES: flang, amdgcn-amd-amdhsa
! UNSUPPORTED: nvptx64-nvidia-cuda
! UNSUPPORTED: nvptx64-nvidia-cuda-LTO
! UNSUPPORTED: aarch64-unknown-linux-gnu
! UNSUPPORTED: aarch64-unknown-linux-gnu-LTO
! UNSUPPORTED: x86_64-pc-linux-gnu
! UNSUPPORTED: x86_64-pc-linux-gnu-LTO

! RUN: %libomptarget-compile-fortran-run-and-check-generic
! XFAIL: *

program main
use omp_lib
integer :: tmp, var4
common var4
var4 = 24
tmp = 12
print *, "var4 before target = ", var4
!$omp target map(tofrom:var4)
var4 = tmp
!$omp end target
print *, "var4 after target = ", var4
end program

! CHECK: var4 before target = 24
! CHECK: var4 after target = 12

Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
! Basic offloading test with a target region
! REQUIRES: flang, amdgcn-amd-amdhsa
! UNSUPPORTED: nvptx64-nvidia-cuda
! UNSUPPORTED: nvptx64-nvidia-cuda-LTO
! UNSUPPORTED: aarch64-unknown-linux-gnu
! UNSUPPORTED: aarch64-unknown-linux-gnu-LTO
! UNSUPPORTED: x86_64-pc-linux-gnu
! UNSUPPORTED: x86_64-pc-linux-gnu-LTO

! RUN: %libomptarget-compile-fortran-run-and-check-generic

! Testing simple variables in common block.
program main
call check_device
call commonblock_simple_with_implicit_type
call commonblock_simple_with_integer
call commonblock_simple_with_real
end program main

!-----

subroutine check_device
use omp_lib
integer :: devices(2)
devices(1) = omp_get_device_num()
!$omp target map(tofrom:devices)
devices(2) = omp_get_device_num()
!$omp end target
print *, "devices: ", devices
end subroutine check_device

!CHECK: devices: 1 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, this will sooner or later blow up. You assume there is only one GPU. I'd recommend to do something like:

print omp_get_num_devices()
!CHECK: [[ND:[0-9]*]]
print omp_get_default_device()
!CHECK: [[DD:[0-9]*]]
!CHECK: devices: [[ND]] [[DD]]

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing this out.

If possible, I'd like to do something like this, and make sure this runs only if there is a device. Is it possible to do this with LIT directives to ensure this test runs when there is atleast one device, and doesn't run (unsupported) otherwise?

print omp_get_num_devices()
!CHECK: [[ND:[1-9]*]]


!-----

subroutine commonblock_simple_with_implicit_type
use omp_lib
common var1
var1 = 10
print *, "var1 before target = ", var1
!$omp target map(tofrom:var1)
var1 = 20
!$omp end target
print *, "var1 after target = ", var1
end subroutine

! CHECK: var1 before target = 10
! CHECK: var1 after target = 20

! -----

subroutine commonblock_simple_with_integer
use omp_lib
integer :: var2
common var2
var2 = 10
print *, "var2 before target = ", var2
!$omp target map(tofrom:var2)
var2 = 20
!$omp end target
print *, "var2 after target = ", var2
end subroutine

! CHECK: var2 before target = 10
! CHECK: var2 after target = 20

! -----

subroutine commonblock_simple_with_real
use omp_lib
real :: var3
common var3
var3 = 12.5
print *, "var3 before target = ", var3
!$omp target map(tofrom:var3)
var3 = 14.5
!$omp end target
print *, "var3 after target = ", var3
end subroutine

! CHECK: var3 before target = 12.5
! CHECK: var3 after target = 14.5