aboutsummaryrefslogtreecommitdiff
path: root/offload/libomptarget/OpenMP/API.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'offload/libomptarget/OpenMP/API.cpp')
-rw-r--r--offload/libomptarget/OpenMP/API.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/offload/libomptarget/OpenMP/API.cpp b/offload/libomptarget/OpenMP/API.cpp
index b0f0573..48b086d 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) {