@@ -39,6 +39,8 @@ EXTERN void ompx_dump_mapping_tables() {
39
39
using namespace llvm ::omp::target::ompt;
40
40
#endif
41
41
42
+ int checkTargetAddressMapping (const void *Ptr , size_t Size , int DeviceNum, const char *Name);
43
+
42
44
void *targetAllocExplicit (size_t Size , int DeviceNum, int Kind,
43
45
const char *Name);
44
46
void targetFreeExplicit (void *DevicePtr, int DeviceNum, int Kind,
@@ -168,33 +170,25 @@ EXTERN int omp_target_is_present(const void *Ptr, int DeviceNum) {
168
170
DP (" Call to omp_target_is_present for device %d and address " DPxMOD " \n " ,
169
171
DeviceNum, DPxPTR (Ptr ));
170
172
171
- if (!Ptr ) {
172
- DP (" Call to omp_target_is_present with NULL ptr, returning false\n " );
173
- return false ;
174
- }
175
-
176
- if (DeviceNum == omp_get_initial_device ()) {
177
- DP (" Call to omp_target_is_present on host, returning true\n " );
178
- return true ;
179
- }
180
-
181
- auto DeviceOrErr = PM->getDevice (DeviceNum);
182
- if (!DeviceOrErr)
183
- FATAL_MESSAGE (DeviceNum, " %s" , toString (DeviceOrErr.takeError ()).c_str ());
184
-
185
173
// omp_target_is_present tests whether a host pointer refers to storage that
186
174
// is mapped to a given device. However, due to the lack of the storage size,
187
175
// only check 1 byte. Cannot set size 0 which checks whether the pointer (zero
188
176
// length array) is mapped instead of the referred storage.
189
- TargetPointerResultTy TPR =
190
- DeviceOrErr->getMappingInfo ().getTgtPtrBegin (const_cast <void *>(Ptr ), 1 ,
191
- /* UpdateRefCount=*/ false ,
192
- /* UseHoldRefCount=*/ false );
193
- int Rc = TPR.isPresent ();
194
- DP (" Call to omp_target_is_present returns %d\n " , Rc);
195
- return Rc;
177
+ return checkTargetAddressMapping (Ptr , 1 , DeviceNum, " omp_target_is_present" );
196
178
}
197
179
180
+ EXTERN int omp_target_is_accessible (const void *Ptr , size_t Size , int DeviceNum) {
181
+ OMPT_IF_BUILT (ReturnAddressSetterRAII RA (__builtin_return_address (0 )));
182
+ DP (" Call to omp_target_is_accessible for device %d and address " DPxMOD
183
+ " with size %zu\n " ,
184
+ DeviceNum, DPxPTR (Ptr ), Size );
185
+
186
+ // omp_target_is_accessible tests whether a host pointer refers to storage
187
+ // that is mapped to a given device and is accessible from the device. The
188
+ // storage size is provided.
189
+ return checkTargetAddressMapping (Ptr , Size , DeviceNum, " omp_target_is_accessible" );
190
+ }
191
+
198
192
EXTERN int omp_target_memcpy (void *Dst, const void *Src, size_t Length,
199
193
size_t DstOffset, size_t SrcOffset, int DstDevice,
200
194
int SrcDevice) {
0 commit comments