[Openmp-commits] [openmp] 9b98497 - [OpenMP] Add omp_target_is_accessible() to header files
Hansang Bae via Openmp-commits
openmp-commits at lists.llvm.org
Fri Apr 16 05:54:41 PDT 2021
Author: Hansang Bae
Date: 2021-04-16T07:54:15-05:00
New Revision: 9b98497b44580f4ef00d1f98da7cc651ebce39cc
URL: https://github.com/llvm/llvm-project/commit/9b98497b44580f4ef00d1f98da7cc651ebce39cc
DIFF: https://github.com/llvm/llvm-project/commit/9b98497b44580f4ef00d1f98da7cc651ebce39cc.diff
LOG: [OpenMP] Add omp_target_is_accessible() to header files
-- Added omp_target_is_accessible to the header files
-- Added missing const qualifier to device memory routines
Differential Revision: https://reviews.llvm.org/D100420
Added:
Modified:
openmp/libomptarget/include/omptarget.h
openmp/libomptarget/src/api.cpp
openmp/runtime/src/include/omp.h.var
openmp/runtime/src/include/omp_lib.f90.var
openmp/runtime/src/include/omp_lib.h.var
Removed:
################################################################################
diff --git a/openmp/libomptarget/include/omptarget.h b/openmp/libomptarget/include/omptarget.h
index 9e3667ee2b872..105de6d1396cf 100644
--- a/openmp/libomptarget/include/omptarget.h
+++ b/openmp/libomptarget/include/omptarget.h
@@ -184,18 +184,19 @@ int omp_get_num_devices(void);
int omp_get_initial_device(void);
void *omp_target_alloc(size_t size, int device_num);
void omp_target_free(void *device_ptr, int device_num);
-int omp_target_is_present(void *ptr, int device_num);
-int omp_target_memcpy(void *dst, void *src, size_t length, size_t dst_offset,
- size_t src_offset, int dst_device, int src_device);
-int omp_target_memcpy_rect(void *dst, void *src, size_t element_size,
+int omp_target_is_present(const void *ptr, int device_num);
+int omp_target_memcpy(void *dst, const void *src, size_t length,
+ size_t dst_offset, size_t src_offset, int dst_device,
+ int src_device);
+int omp_target_memcpy_rect(void *dst, const void *src, size_t element_size,
int num_dims, const size_t *volume,
const size_t *dst_offsets, const size_t *src_offsets,
const size_t *dst_dimensions,
const size_t *src_dimensions, int dst_device,
int src_device);
-int omp_target_associate_ptr(void *host_ptr, void *device_ptr, size_t size,
- size_t device_offset, int device_num);
-int omp_target_disassociate_ptr(void *host_ptr, int device_num);
+int omp_target_associate_ptr(const void *host_ptr, const void *device_ptr,
+ size_t size, size_t device_offset, int device_num);
+int omp_target_disassociate_ptr(const void *host_ptr, int device_num);
/// Explicit target memory allocators
/// Using the llvm_ prefix until they become part of the OpenMP standard.
diff --git a/openmp/libomptarget/src/api.cpp b/openmp/libomptarget/src/api.cpp
index 3c6142a36904f..ed641106c3a09 100644
--- a/openmp/libomptarget/src/api.cpp
+++ b/openmp/libomptarget/src/api.cpp
@@ -78,7 +78,7 @@ EXTERN void omp_target_free(void *device_ptr, int device_num) {
DP("omp_target_free deallocated device ptr\n");
}
-EXTERN int omp_target_is_present(void *ptr, int device_num) {
+EXTERN int omp_target_is_present(const void *ptr, int device_num) {
TIMESCOPE();
DP("Call to omp_target_is_present for device %d and address " DPxMOD "\n",
device_num, DPxPTR(ptr));
@@ -105,7 +105,8 @@ EXTERN int omp_target_is_present(void *ptr, int device_num) {
DeviceTy &Device = PM->Devices[device_num];
bool IsLast; // not used
bool IsHostPtr;
- void *TgtPtr = Device.getTgtPtrBegin(ptr, 0, IsLast, false, IsHostPtr);
+ void *TgtPtr = Device.getTgtPtrBegin(const_cast<void *>(ptr), 0, IsLast,
+ false, IsHostPtr);
int rc = (TgtPtr != NULL);
// Under unified memory the host pointer can be returned by the
// getTgtPtrBegin() function which means that there is no device
@@ -117,7 +118,7 @@ EXTERN int omp_target_is_present(void *ptr, int device_num) {
return rc;
}
-EXTERN int omp_target_memcpy(void *dst, void *src, size_t length,
+EXTERN int omp_target_memcpy(void *dst, const void *src, size_t length,
size_t dst_offset, size_t src_offset,
int dst_device, int src_device) {
TIMESCOPE();
@@ -148,7 +149,7 @@ EXTERN int omp_target_memcpy(void *dst, void *src, size_t length,
}
int rc = OFFLOAD_SUCCESS;
- void *srcAddr = (char *)src + src_offset;
+ void *srcAddr = (char *)const_cast<void *>(src) + src_offset;
void *dstAddr = (char *)dst + dst_offset;
if (src_device == omp_get_initial_device() &&
@@ -196,13 +197,11 @@ EXTERN int omp_target_memcpy(void *dst, void *src, size_t length,
return rc;
}
-EXTERN int omp_target_memcpy_rect(void *dst, void *src, size_t element_size,
- int num_dims, const size_t *volume,
- const size_t *dst_offsets,
- const size_t *src_offsets,
- const size_t *dst_dimensions,
- const size_t *src_dimensions, int dst_device,
- int src_device) {
+EXTERN int omp_target_memcpy_rect(
+ void *dst, const void *src, size_t element_size, int num_dims,
+ const size_t *volume, const size_t *dst_offsets, const size_t *src_offsets,
+ const size_t *dst_dimensions, const size_t *src_dimensions, int dst_device,
+ int src_device) {
TIMESCOPE();
DP("Call to omp_target_memcpy_rect, dst device %d, src device %d, "
"dst addr " DPxMOD ", src addr " DPxMOD ", dst offsets " DPxMOD ", "
@@ -242,9 +241,10 @@ EXTERN int omp_target_memcpy_rect(void *dst, void *src, size_t element_size,
for (size_t i = 0; i < volume[0]; ++i) {
rc = omp_target_memcpy_rect(
(char *)dst + dst_off + dst_slice_size * i,
- (char *)src + src_off + src_slice_size * i, element_size,
- num_dims - 1, volume + 1, dst_offsets + 1, src_offsets + 1,
- dst_dimensions + 1, src_dimensions + 1, dst_device, src_device);
+ (char *)const_cast<void *>(src) + src_off + src_slice_size * i,
+ element_size, num_dims - 1, volume + 1, dst_offsets + 1,
+ src_offsets + 1, dst_dimensions + 1, src_dimensions + 1, dst_device,
+ src_device);
if (rc) {
DP("Recursive call to omp_target_memcpy_rect returns unsuccessfully\n");
@@ -257,9 +257,9 @@ EXTERN int omp_target_memcpy_rect(void *dst, void *src, size_t element_size,
return rc;
}
-EXTERN int omp_target_associate_ptr(void *host_ptr, void *device_ptr,
- size_t size, size_t device_offset,
- int device_num) {
+EXTERN int omp_target_associate_ptr(const void *host_ptr,
+ const void *device_ptr, size_t size,
+ size_t device_offset, int device_num) {
TIMESCOPE();
DP("Call to omp_target_associate_ptr with host_ptr " DPxMOD ", "
"device_ptr " DPxMOD ", size %zu, device_offset %zu, device_num %d\n",
@@ -282,12 +282,13 @@ EXTERN int omp_target_associate_ptr(void *host_ptr, void *device_ptr,
DeviceTy &Device = PM->Devices[device_num];
void *device_addr = (void *)((uint64_t)device_ptr + (uint64_t)device_offset);
- int rc = Device.associatePtr(host_ptr, device_addr, size);
+ int rc = Device.associatePtr(const_cast<void *>(host_ptr),
+ const_cast<void *>(device_addr), size);
DP("omp_target_associate_ptr returns %d\n", rc);
return rc;
}
-EXTERN int omp_target_disassociate_ptr(void *host_ptr, int device_num) {
+EXTERN int omp_target_disassociate_ptr(const void *host_ptr, int device_num) {
TIMESCOPE();
DP("Call to omp_target_disassociate_ptr with host_ptr " DPxMOD ", "
"device_num %d\n",
@@ -310,7 +311,7 @@ EXTERN int omp_target_disassociate_ptr(void *host_ptr, int device_num) {
}
DeviceTy &Device = PM->Devices[device_num];
- int rc = Device.disassociatePtr(host_ptr);
+ int rc = Device.disassociatePtr(const_cast<void *>(host_ptr));
DP("omp_target_disassociate_ptr returns %d\n", rc);
return rc;
}
diff --git a/openmp/runtime/src/include/omp.h.var b/openmp/runtime/src/include/omp.h.var
index c269fa6359cdd..804aa01389dd1 100644
--- a/openmp/runtime/src/include/omp.h.var
+++ b/openmp/runtime/src/include/omp.h.var
@@ -141,12 +141,12 @@
extern int __KAI_KMPC_CONVENTION omp_get_initial_device (void);
extern void* __KAI_KMPC_CONVENTION omp_target_alloc(size_t, int);
extern void __KAI_KMPC_CONVENTION omp_target_free(void *, int);
- extern int __KAI_KMPC_CONVENTION omp_target_is_present(void *, int);
- extern int __KAI_KMPC_CONVENTION omp_target_memcpy(void *, void *, size_t, size_t, size_t, int, int);
- extern int __KAI_KMPC_CONVENTION omp_target_memcpy_rect(void *, void *, size_t, int, const size_t *,
+ extern int __KAI_KMPC_CONVENTION omp_target_is_present(const void *, int);
+ extern int __KAI_KMPC_CONVENTION omp_target_memcpy(void *, const void *, size_t, size_t, size_t, int, int);
+ extern int __KAI_KMPC_CONVENTION omp_target_memcpy_rect(void *, const void *, size_t, int, const size_t *,
const size_t *, const size_t *, const size_t *, const size_t *, int, int);
- extern int __KAI_KMPC_CONVENTION omp_target_associate_ptr(void *, void *, size_t, size_t, int);
- extern int __KAI_KMPC_CONVENTION omp_target_disassociate_ptr(void *, int);
+ extern int __KAI_KMPC_CONVENTION omp_target_associate_ptr(const void *, const void *, size_t, size_t, int);
+ extern int __KAI_KMPC_CONVENTION omp_target_disassociate_ptr(const void *, int);
/* OpenMP 5.0 */
extern int __KAI_KMPC_CONVENTION omp_get_device_num (void);
@@ -230,6 +230,7 @@
* The `omp_get_mapped_ptr` routine returns the device pointer that is associated with a host pointer for a given device.
*/
extern void * __KAI_KMPC_CONVENTION omp_get_mapped_ptr(const void *, int);
+ extern int __KAI_KMPC_CONVENTION omp_target_is_accessible(const void *, size_t, int);
/* kmp API functions */
extern int __KAI_KMPC_CONVENTION kmp_get_stacksize (void);
diff --git a/openmp/runtime/src/include/omp_lib.f90.var b/openmp/runtime/src/include/omp_lib.f90.var
index 4b39f1af54a07..7763e5dca14ce 100644
--- a/openmp/runtime/src/include/omp_lib.f90.var
+++ b/openmp/runtime/src/include/omp_lib.f90.var
@@ -629,6 +629,15 @@
integer(c_int), value :: device_num
end function omp_target_disassociate_ptr
+ function omp_target_is_accessible(ptr, size, device_num) bind(c)
+ use omp_lib_kinds
+ use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t, c_int
+ integer(c_int) omp_target_is_accessible
+ type(c_ptr), value :: ptr
+ integer(c_size_t), value :: size
+ integer(c_int), value :: device_num
+ end function omp_target_is_accessible
+
! ***
! *** kmp_* entry points
! ***
diff --git a/openmp/runtime/src/include/omp_lib.h.var b/openmp/runtime/src/include/omp_lib.h.var
index 50c8ecb9d1e34..7496c038162f2 100644
--- a/openmp/runtime/src/include/omp_lib.h.var
+++ b/openmp/runtime/src/include/omp_lib.h.var
@@ -715,6 +715,14 @@
integer(c_int), value :: device_num
end function omp_target_disassociate_ptr
+ function omp_target_is_accessible(ptr, size, device_num) bind(c)
+ use, intrinsic :: iso_c_binding, only : c_ptr, c_size_t, c_int
+ integer(c_int) omp_target_is_accessible
+ type(c_ptr), value :: ptr
+ integer(c_size_t), value :: size
+ integer(c_int), value :: device_num
+ end function omp_target_is_accessible
+
! ***
! *** kmp_* entry points
! ***
More information about the Openmp-commits
mailing list