@@ -298,12 +298,20 @@ int __tgt_interop_use(ident_t *LocRef, omp_interop_val_t *Interop,
298298 }
299299 }
300300
301+ auto DeviceOrErr = Interop->getDevice ();
302+ if (!DeviceOrErr) {
303+ REPORT (" Failed to get device for interop " DPxMOD " : %s\n " ,
304+ DPxPTR (Interop), toString (DeviceOrErr.takeError ()).c_str ());
305+ return OFFLOAD_FAIL;
306+ }
307+ auto &IOPDevice = *DeviceOrErr;
308+
301309 if (Interop->async_info && Interop->async_info ->Queue ) {
302310 if (Nowait)
303- Interop->asyncBarrier ( );
311+ Interop->async_barrier (IOPDevice );
304312 else {
305- Interop->flush ();
306- Interop->syncBarrier ( );
313+ Interop->flush (IOPDevice );
314+ Interop->sync_barrier (IOPDevice );
307315 Interop->markClean ();
308316 }
309317 }
@@ -328,7 +336,14 @@ int __tgt_interop_release(ident_t *LocRef, omp_interop_val_t *Interop,
328336 }
329337 }
330338
331- return Interop->release ();
339+ auto DeviceOrErr = Interop->getDevice ();
340+ if (!DeviceOrErr) {
341+ REPORT (" Failed to get device for interop " DPxMOD " : %s\n " ,
342+ DPxPTR (Interop), toString (DeviceOrErr.takeError ()).c_str ());
343+ return OFFLOAD_FAIL;
344+ }
345+
346+ return Interop->release (*DeviceOrErr);
332347}
333348
334349EXTERN int ompx_interop_add_completion_callback (omp_interop_val_t *Interop,
@@ -348,6 +363,10 @@ EXTERN int ompx_interop_add_completion_callback(omp_interop_val_t *Interop,
348363
349364} // extern "C"
350365
366+ llvm::Expected<DeviceTy &> omp_interop_val_t::getDevice () const {
367+ return PM->getDevice (device_id);
368+ }
369+
351370bool omp_interop_val_t::isCompatibleWith (int32_t InteropType,
352371 const interop_spec_t &Spec) {
353372 if (interop_type != InteropType)
@@ -394,44 +413,12 @@ int32_t omp_interop_val_t::async_barrier(DeviceTy &Device) {
394413
395414int32_t omp_interop_val_t::release (DeviceTy &Device) {
396415 if (async_info != nullptr && (!hasOwner () || !isClean ())) {
397- flush ();
398- syncBarrier ( );
416+ flush (Device );
417+ sync_barrier (Device );
399418 }
400419 return Device.RTL ->release_interop (device_id, this );
401420}
402421
403- int32_t omp_interop_val_t::flush () {
404- auto DeviceOrErr = PM->getDevice (device_id);
405- if (!DeviceOrErr)
406- FATAL_MESSAGE (device_id, " %s" , toString (DeviceOrErr.takeError ()).c_str ());
407- DeviceTy &Device = *DeviceOrErr;
408- return flush (Device);
409- }
410-
411- int32_t omp_interop_val_t::syncBarrier () {
412- auto DeviceOrErr = PM->getDevice (device_id);
413- if (!DeviceOrErr)
414- FATAL_MESSAGE (device_id, " %s" , toString (DeviceOrErr.takeError ()).c_str ());
415- DeviceTy &Device = *DeviceOrErr;
416- return sync_barrier (Device);
417- }
418-
419- int32_t omp_interop_val_t::asyncBarrier () {
420- auto DeviceOrErr = PM->getDevice (device_id);
421- if (!DeviceOrErr)
422- FATAL_MESSAGE (device_id, " %s" , toString (DeviceOrErr.takeError ()).c_str ());
423- DeviceTy &Device = *DeviceOrErr;
424- return async_barrier (Device);
425- }
426-
427- int32_t omp_interop_val_t::release () {
428- auto DeviceOrErr = PM->getDevice (device_id);
429- if (!DeviceOrErr)
430- FATAL_MESSAGE (device_id, " %s" , toString (DeviceOrErr.takeError ()).c_str ());
431- DeviceTy &Device = *DeviceOrErr;
432- return release (Device);
433- }
434-
435422void syncImplicitInterops (int Gtid, void *Event) {
436423 if (PM->InteropTbl .size () == 0 )
437424 return ;
@@ -443,8 +430,16 @@ void syncImplicitInterops(int Gtid, void *Event) {
443430 if (iop->async_info && iop->async_info ->Queue && iop->isOwnedBy (Gtid) &&
444431 !iop->isClean ()) {
445432
446- iop->flush ();
447- iop->syncBarrier ();
433+ auto DeviceOrErr = iop->getDevice ();
434+ if (!DeviceOrErr) {
435+ REPORT (" Failed to get device for interop " DPxMOD " : %s\n " ,
436+ DPxPTR (iop), toString (DeviceOrErr.takeError ()).c_str ());
437+ continue ;
438+ }
439+ auto &IOPDevice = *DeviceOrErr;
440+
441+ iop->flush (IOPDevice);
442+ iop->sync_barrier (IOPDevice);
448443 iop->markClean ();
449444
450445 // TODO: Alternate implementation option
@@ -464,5 +459,13 @@ void syncImplicitInterops(int Gtid, void *Event) {
464459
465460void InteropTblTy::clear () {
466461 DP (" Clearing Interop Table\n " );
467- PerThreadTable::clear ([](auto &IOP) { IOP->release (); });
462+ PerThreadTable::clear ([](auto &IOP) {
463+ auto DeviceOrErr = IOP->getDevice ();
464+ if (!DeviceOrErr) {
465+ REPORT (" Failed to get device for interop " DPxMOD " : %s\n " ,
466+ DPxPTR (IOP), toString (DeviceOrErr.takeError ()).c_str ());
467+ return ;
468+ }
469+ IOP->release (*DeviceOrErr);
470+ });
468471}
0 commit comments