diff options
Diffstat (limited to 'offload/plugins-nextgen/common/src/PluginInterface.cpp')
-rw-r--r-- | offload/plugins-nextgen/common/src/PluginInterface.cpp | 111 |
1 files changed, 102 insertions, 9 deletions
diff --git a/offload/plugins-nextgen/common/src/PluginInterface.cpp b/offload/plugins-nextgen/common/src/PluginInterface.cpp index 94a050b5..083d416 100644 --- a/offload/plugins-nextgen/common/src/PluginInterface.cpp +++ b/offload/plugins-nextgen/common/src/PluginInterface.cpp @@ -815,8 +815,11 @@ Error GenericDeviceTy::init(GenericPluginTy &Plugin) { // Enable the memory manager if required. auto [ThresholdMM, EnableMM] = MemoryManagerTy::getSizeThresholdFromEnv(); - if (EnableMM) + if (EnableMM) { + if (ThresholdMM == 0) + ThresholdMM = getMemoryManagerSizeThreshold(); MemoryManager = new MemoryManagerTy(*this, ThresholdMM); + } return Plugin::success(); } @@ -1332,18 +1335,25 @@ Error PinnedAllocationMapTy::unlockUnmappedHostBuffer(void *HstPtr) { return eraseEntry(*Entry); } -Error GenericDeviceTy::synchronize(__tgt_async_info *AsyncInfo) { - if (!AsyncInfo || !AsyncInfo->Queue) - return Plugin::error(ErrorCode::INVALID_ARGUMENT, - "invalid async info queue"); +Error GenericDeviceTy::synchronize(__tgt_async_info *AsyncInfo, + bool ReleaseQueue) { + SmallVector<void *> AllocsToDelete{}; + { + std::lock_guard<std::mutex> AllocationGuard{AsyncInfo->Mutex}; - if (auto Err = synchronizeImpl(*AsyncInfo)) - return Err; + if (!AsyncInfo || !AsyncInfo->Queue) + return Plugin::error(ErrorCode::INVALID_ARGUMENT, + "invalid async info queue"); + + if (auto Err = synchronizeImpl(*AsyncInfo, ReleaseQueue)) + return Err; - for (auto *Ptr : AsyncInfo->AssociatedAllocations) + std::swap(AllocsToDelete, AsyncInfo->AssociatedAllocations); + } + + for (auto *Ptr : AllocsToDelete) if (auto Err = dataDelete(Ptr, TargetAllocTy::TARGET_ALLOC_DEVICE)) return Err; - AsyncInfo->AssociatedAllocations.clear(); return Plugin::success(); } @@ -1623,6 +1633,21 @@ Error GenericDeviceTy::waitEvent(void *EventPtr, __tgt_async_info *AsyncInfo) { return Err; } +Expected<bool> GenericDeviceTy::hasPendingWork(__tgt_async_info *AsyncInfo) { + AsyncInfoWrapperTy AsyncInfoWrapper(*this, AsyncInfo); + auto Res = hasPendingWorkImpl(AsyncInfoWrapper); + if (auto Err = Res.takeError()) { + AsyncInfoWrapper.finalize(Err); + return Err; + } + + auto Err = Plugin::success(); + AsyncInfoWrapper.finalize(Err); + if (Err) + return Err; + return Res; +} + Error GenericDeviceTy::syncEvent(void *EventPtr) { return syncEventImpl(EventPtr); } @@ -2231,3 +2256,71 @@ int32_t GenericPluginTy::get_function(__tgt_device_binary Binary, *KernelPtr = &Kernel; return OFFLOAD_SUCCESS; } + +/// Create OpenMP interop with the given interop context +omp_interop_val_t * +GenericPluginTy::create_interop(int32_t ID, int32_t InteropContext, + interop_spec_t *InteropSpec) { + assert(InteropSpec && "Interop spec is null"); + auto &Device = getDevice(ID); + auto InteropOrErr = Device.createInterop(InteropContext, *InteropSpec); + if (!InteropOrErr) { + REPORT("Failure to create interop object for device " DPxMOD ": %s\n", + DPxPTR(InteropSpec), toString(InteropOrErr.takeError()).c_str()); + return nullptr; + } + return *InteropOrErr; +} + +/// Release OpenMP interop object +int32_t GenericPluginTy::release_interop(int32_t ID, + omp_interop_val_t *Interop) { + assert(Interop && "Interop is null"); + assert(Interop->device_id == ID && "Interop does not match device id"); + auto &Device = getDevice(ID); + auto Err = Device.releaseInterop(Interop); + if (Err) { + REPORT("Failure to release interop object " DPxMOD ": %s\n", + DPxPTR(Interop), toString(std::move(Err)).c_str()); + return OFFLOAD_FAIL; + } + return OFFLOAD_SUCCESS; +} + +/// Flush the queue associated with the interop object if necessary +int32_t GenericPluginTy::flush_queue(omp_interop_val_t *Interop) { + assert(Interop && "Interop is null"); + auto Err = flushQueueImpl(Interop); + if (Err) { + REPORT("Failure to flush interop object " DPxMOD " queue: %s\n", + DPxPTR(Interop), toString(std::move(Err)).c_str()); + return OFFLOAD_FAIL; + } + return OFFLOAD_SUCCESS; +} + +/// Perform a host synchronization with the queue associated with the interop +/// object and wait for it to complete. +int32_t GenericPluginTy::sync_barrier(omp_interop_val_t *Interop) { + assert(Interop && "Interop is null"); + auto Err = syncBarrierImpl(Interop); + if (Err) { + REPORT("Failure to synchronize interop object " DPxMOD ": %s\n", + DPxPTR(Interop), toString(std::move(Err)).c_str()); + return OFFLOAD_FAIL; + } + return OFFLOAD_SUCCESS; +} + +/// Queue an asynchronous barrier in the queue associated with the interop +/// object and return immediately. +int32_t GenericPluginTy::async_barrier(omp_interop_val_t *Interop) { + assert(Interop && "Interop is null"); + auto Err = asyncBarrierImpl(Interop); + if (Err) { + REPORT("Failure to queue barrier in interop object " DPxMOD ": %s\n", + DPxPTR(Interop), toString(std::move(Err)).c_str()); + return OFFLOAD_FAIL; + } + return OFFLOAD_SUCCESS; +} |