diff options
| author | Nicole Aschenbrenner <nicole.aschenbrenner@amd.com> | 2025-10-22 17:35:16 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-22 17:35:16 +0200 |
| commit | 16641ad8a29b6c877a3f934cd61d6acc9719e87e (patch) | |
| tree | a1067d685c9c55409135079a0e0f9da301f07363 /offload/libomptarget/OpenMP/API.cpp | |
| parent | 2936852d2f6b0e7af6237abe9796c494885b2aac (diff) | |
[OpenMP] Adds omp_target_is_accessible routine (#138294)
Adds omp_target_is_accessible routine.
Refactors common code from omp_target_is_present to work for both
routines.
---------
Co-authored-by: Shilei Tian <i@tianshilei.me>
Diffstat (limited to 'offload/libomptarget/OpenMP/API.cpp')
| -rw-r--r-- | offload/libomptarget/OpenMP/API.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/offload/libomptarget/OpenMP/API.cpp b/offload/libomptarget/OpenMP/API.cpp index b0f057383371..48b086d67128 100644 --- a/offload/libomptarget/OpenMP/API.cpp +++ b/offload/libomptarget/OpenMP/API.cpp @@ -196,6 +196,34 @@ EXTERN int omp_target_is_present(const void *Ptr, int DeviceNum) { return Rc; } +/// Check whether a pointer is accessible from a device. +/// Returns true when accessibility is guaranteed otherwise returns false. +EXTERN int omp_target_is_accessible(const void *Ptr, size_t Size, + int DeviceNum) { + TIMESCOPE(); + OMPT_IF_BUILT(ReturnAddressSetterRAII RA(__builtin_return_address(0))); + DP("Call to omp_target_is_accessible for device %d, address " DPxMOD + ", size %zu\n", + DeviceNum, DPxPTR(Ptr), Size); + + if (!Ptr) { + DP("Call to omp_target_is_accessible with NULL ptr returning false\n"); + return false; + } + + if (DeviceNum == omp_get_initial_device() || DeviceNum == -1) { + DP("Call to omp_target_is_accessible on host, returning true\n"); + return true; + } + + // The device number must refer to a valid device + auto DeviceOrErr = PM->getDevice(DeviceNum); + if (!DeviceOrErr) + FATAL_MESSAGE(DeviceNum, "%s", toString(DeviceOrErr.takeError()).c_str()); + + return DeviceOrErr->isAccessiblePtr(Ptr, Size); +} + EXTERN int omp_target_memcpy(void *Dst, const void *Src, size_t Length, size_t DstOffset, size_t SrcOffset, int DstDevice, int SrcDevice) { |
