[llvm-branch-commits] [flang] [llvm] [mlir] [MLIR][OpenMP] Add OpenMPToLLVMIRTranslation support for is_device_ptr (PR #169367)
Akash Banerjee via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Nov 27 12:33:28 PST 2025
================
@@ -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
----------------
TIFitis wrote:
I tried adding the call to c_f_pointer inside the target region in the previous test. But it causes a runtime failure, and I'm not sure if the failure is directly related to the is_device_ptr implementation or some other mapping bug.
If you're happy with the current simpler test for this PR, then I can work on debugging a fix for that failure when I return from vacation in the new year. Otherwise, I'll put this PR on hold until I can come up with a working version of that test with a call to c_f_pointer inside the target region.
Let me know which you prefer, thanks.
https://github.com/llvm/llvm-project/pull/169367
More information about the llvm-branch-commits
mailing list