[llvm-branch-commits] [flang] [llvm] [mlir] [MLIR][OpenMP] Add OpenMPToLLVMIRTranslation support for is_device_ptr (PR #169367)
@@ -0,0 +1,46 @@ +! Validate that a device pointer obtained via omp_get_mapped_ptr can be used +! inside a TARGET region with the is_device_ptr clause. +! REQUIRES: flang, amdgcn-amd-amdhsa + +! RUN: %libomptarget-compile-fortran-run-and-check-generic + +program is_device_ptr_target + use iso_c_binding, only : c_ptr, c_loc + implicit none + + interface +function omp_get_mapped_ptr(host_ptr, device_num) & +bind(C, name="omp_get_mapped_ptr") + use iso_c_binding, only : c_ptr, c_int + type(c_ptr) :: omp_get_mapped_ptr + type(c_ptr), value :: host_ptr + integer(c_int), value :: device_num +end function omp_get_mapped_ptr + end interface + + integer, parameter :: n = 4 + integer, parameter :: dev = 0 + integer, target :: a(n) + type(c_ptr) :: dptr + integer :: flag + + a = [2, 4, 6, 8] + flag = 0 + + !$omp target data map(tofrom: a, flag) +dptr = omp_get_mapped_ptr(c_loc(a), dev) + +!$omp target is_device_ptr(dptr) map(tofrom: flag) + flag = flag + 1 abhinavgaba wrote: `dptr` is still not used inside the target construct. Is your goal to validate that `dptr` is correctly passed into the `target`, or just that this doesn't cause a segfault/offload-failure? If it's the former, then one way to do it is by calling c_f_pointer inside the target region, and reading/writing the pointee via the fortran pointer. Another way is to `transfer` dptr into an `INTEGER(C_INTPTR_T)` both inside and outside the target region, print it, and CHECK that the two addresses printed are identical. https://github.com/llvm/llvm-project/pull/169367 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] [llvm] [mlir] [MLIR][OpenMP] Add OpenMPToLLVMIRTranslation support for is_device_ptr (PR #169367)
@@ -0,0 +1,79 @@ +! Validate that a device pointer allocated via OpenMP runtime APIs can be +! consumed by a TARGET region using the is_device_ptr clause. +! REQUIRES: flang, amdgcn-amd-amdhsa +! UNSUPPORTED: nvptx64-nvidia-cuda +! UNSUPPORTED: nvptx64-nvidia-cuda-LTO +! UNSUPPORTED: aarch64-unknown-linux-gnu abhinavgaba wrote: Is there a technical reason a lot of these offloading/fortran tests are disabled on other architectures? Keeping them enabled, at least on cpu targets, would let a lot more people who work on libomptarget but don't have an AMD GPU, test the impact of their changes on these tests locally, without relying on post-commit buildbot testing. https://github.com/llvm/llvm-project/pull/169367 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] [llvm] [mlir] [MLIR][OpenMP] Add OpenMPToLLVMIRTranslation support for is_device_ptr (PR #169367)
@@ -0,0 +1,79 @@ +! Validate that a device pointer allocated via OpenMP runtime APIs can be +! consumed by a TARGET region using the is_device_ptr clause. +! 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-unknown-linux-gnu +! UNSUPPORTED: x86_64-unknown-linux-gnu-LTO + +! RUN: %libomptarget-compile-fortran-run-and-check-generic + +program is_device_ptr_target + use omp_lib + use iso_c_binding + implicit none + + integer, parameter :: n = 4 + integer, target :: host(n) + type(c_ptr) :: device_ptr + integer(c_int) :: rc + integer :: i + + do i = 1, n +host(i) = i + end do + + device_ptr = omp_target_alloc(int(n, c_size_t) * int(c_sizeof(host(1)), c_size_t), & +omp_get_default_device()) + if (.not. c_associated(device_ptr)) then +print *, "device alloc failed" +stop 1 + end if + + rc = omp_target_memcpy(device_ptr, c_loc(host), & + int(n, c_size_t) * int(c_sizeof(host(1)), c_size_t), & + 0_c_size_t, 0_c_size_t, & + omp_get_default_device(), omp_get_initial_device()) + if (rc .ne. 0) then +print *, "host->device memcpy failed" +call omp_target_free(device_ptr, omp_get_default_device()) +stop 1 + end if + + call fill_on_device(device_ptr) + + rc = omp_target_memcpy(c_loc(host), device_ptr, & + int(n, c_size_t) * int(c_sizeof(host(1)), c_size_t), & + 0_c_size_t, 0_c_size_t, & + omp_get_initial_device(), omp_get_default_device()) + call omp_target_free(device_ptr, omp_get_default_device()) + + if (rc .ne. 0) then +print *, "device->host memcpy failed" +stop 1 + end if + + if (all(host == [2, 4, 6, 8])) then +print *, "PASS" + else +print *, "FAIL", host + end if + +contains + subroutine fill_on_device(ptr) +type(c_ptr) :: ptr +integer, pointer :: p(:) +call c_f_pointer(ptr, p, [n]) + +!$omp target is_device_ptr(ptr) + p(1) = 2 abhinavgaba wrote: `c_f_pointer` should be called inside the target region, if the goal is to test whether the argument for `ptr` was set correctly. The uninitialized `p` can then be made `private` on the `target` construct. https://github.com/llvm/llvm-project/pull/169367 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
