@@ -39,6 +39,8 @@ EXTERN void ompx_dump_mapping_tables() {
3939using namespace llvm ::omp::target::ompt;
4040#endif
4141
42+ int checkTargetAddressMapping (const void *Ptr, size_t Size, int DeviceNum, const char *Name);
43+
4244void *targetAllocExplicit (size_t Size, int DeviceNum, int Kind,
4345 const char *Name);
4446void targetFreeExplicit (void *DevicePtr, int DeviceNum, int Kind,
@@ -168,33 +170,25 @@ EXTERN int omp_target_is_present(const void *Ptr, int DeviceNum) {
168170 DP (" Call to omp_target_is_present for device %d and address " DPxMOD " \n " ,
169171 DeviceNum, DPxPTR (Ptr));
170172
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-
185173 // omp_target_is_present tests whether a host pointer refers to storage that
186174 // is mapped to a given device. However, due to the lack of the storage size,
187175 // only check 1 byte. Cannot set size 0 which checks whether the pointer (zero
188176 // 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" );
196178}
197179
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+
198192EXTERN int omp_target_memcpy (void *Dst, const void *Src, size_t Length,
199193 size_t DstOffset, size_t SrcOffset, int DstDevice,
200194 int SrcDevice) {
0 commit comments