Skip to content

Commit

Permalink
[OpenMP][libomptarget][NFC] Remove error data member from AsyncInfoWr…
Browse files Browse the repository at this point in the history
…apperTy

This patch removes the Err data member from the AsyncInfoWrapperTy class. Now the error
is stored externally, in the caller side, and it is explicitly passed to the
AsyncInfoWrapperTy::finalize() function as a reference.

Differential Revision: https://reviews.llvm.org/D148027
  • Loading branch information
kevinsala committed Apr 18, 2023
1 parent 37a867a commit 2213509
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,27 +202,21 @@ struct RecordReplayTy {

AsyncInfoWrapperTy::AsyncInfoWrapperTy(GenericDeviceTy &Device,
__tgt_async_info *AsyncInfoPtr)
: Err(Plugin::success()), Device(Device),
AsyncInfoPtr(AsyncInfoPtr ? AsyncInfoPtr : &LocalAsyncInfo) {
// Mark the success as checked. Otherwise, it would produce an error when
// re-assigned another error value.
(void)!Err;
}
: Device(Device),
AsyncInfoPtr(AsyncInfoPtr ? AsyncInfoPtr : &LocalAsyncInfo) {}

Error AsyncInfoWrapperTy::finalize() {
void AsyncInfoWrapperTy::finalize(Error &Err) {
assert(AsyncInfoPtr && "AsyncInfoWrapperTy already finalized");

// If we used a local async info object we want synchronous behavior.
// In that case, and assuming the current status code is OK, we will
// synchronize explicitly when the object is deleted.
// If we used a local async info object we want synchronous behavior. In that
// case, and assuming the current status code is correct, we will synchronize
// explicitly when the object is deleted. Update the error with the result of
// the synchronize operation.
if (AsyncInfoPtr == &LocalAsyncInfo && LocalAsyncInfo.Queue && !Err)
Err = Device.synchronize(&LocalAsyncInfo);

// Invalidate the wrapper object.
AsyncInfoPtr = nullptr;

// Return the error associated to the async operations and the synchronize.
return std::move(Err);
}

Error GenericKernelTy::init(GenericDeviceTy &GenericDevice,
Expand Down Expand Up @@ -931,28 +925,28 @@ Error GenericDeviceTy::dataSubmit(void *TgtPtr, const void *HstPtr,
int64_t Size, __tgt_async_info *AsyncInfo) {
AsyncInfoWrapperTy AsyncInfoWrapper(*this, AsyncInfo);

auto &Err = AsyncInfoWrapper.getError();
Err = dataSubmitImpl(TgtPtr, HstPtr, Size, AsyncInfoWrapper);
return AsyncInfoWrapper.finalize();
auto Err = dataSubmitImpl(TgtPtr, HstPtr, Size, AsyncInfoWrapper);
AsyncInfoWrapper.finalize(Err);
return Err;
}

Error GenericDeviceTy::dataRetrieve(void *HstPtr, const void *TgtPtr,
int64_t Size, __tgt_async_info *AsyncInfo) {
AsyncInfoWrapperTy AsyncInfoWrapper(*this, AsyncInfo);

auto &Err = AsyncInfoWrapper.getError();
Err = dataRetrieveImpl(HstPtr, TgtPtr, Size, AsyncInfoWrapper);
return AsyncInfoWrapper.finalize();
auto Err = dataRetrieveImpl(HstPtr, TgtPtr, Size, AsyncInfoWrapper);
AsyncInfoWrapper.finalize(Err);
return Err;
}

Error GenericDeviceTy::dataExchange(const void *SrcPtr, GenericDeviceTy &DstDev,
void *DstPtr, int64_t Size,
__tgt_async_info *AsyncInfo) {
AsyncInfoWrapperTy AsyncInfoWrapper(*this, AsyncInfo);

auto &Err = AsyncInfoWrapper.getError();
Err = dataExchangeImpl(SrcPtr, DstDev, DstPtr, Size, AsyncInfoWrapper);
return AsyncInfoWrapper.finalize();
auto Err = dataExchangeImpl(SrcPtr, DstDev, DstPtr, Size, AsyncInfoWrapper);
AsyncInfoWrapper.finalize(Err);
return Err;
}

Error GenericDeviceTy::launchKernel(void *EntryPtr, void **ArgPtrs,
Expand All @@ -970,16 +964,16 @@ Error GenericDeviceTy::launchKernel(void *EntryPtr, void **ArgPtrs,
KernelArgs.NumTeams[0], KernelArgs.ThreadLimit[0], KernelArgs.Tripcount,
AsyncInfoWrapper);

auto &Err = AsyncInfoWrapper.getError();
Err = GenericKernel.launch(*this, ArgPtrs, ArgOffsets, KernelArgs,
AsyncInfoWrapper);
auto Err = GenericKernel.launch(*this, ArgPtrs, ArgOffsets, KernelArgs,
AsyncInfoWrapper);

if (RecordReplay.isRecordingOrReplaying() &&
RecordReplay.isSaveOutputEnabled())
RecordReplay.saveKernelOutputInfo(GenericKernel.getName(),
AsyncInfoWrapper);

return AsyncInfoWrapper.finalize();
AsyncInfoWrapper.finalize(Err);
return Err;
}

Error GenericDeviceTy::initAsyncInfo(__tgt_async_info **AsyncInfoPtr) {
Expand All @@ -989,9 +983,9 @@ Error GenericDeviceTy::initAsyncInfo(__tgt_async_info **AsyncInfoPtr) {

AsyncInfoWrapperTy AsyncInfoWrapper(*this, *AsyncInfoPtr);

auto &Err = AsyncInfoWrapper.getError();
Err = initAsyncInfoImpl(AsyncInfoWrapper);
return AsyncInfoWrapper.finalize();
auto Err = initAsyncInfoImpl(AsyncInfoWrapper);
AsyncInfoWrapper.finalize(Err);
return Err;
}

Error GenericDeviceTy::initDeviceInfo(__tgt_device_info *DeviceInfo) {
Expand All @@ -1017,17 +1011,17 @@ Error GenericDeviceTy::recordEvent(void *EventPtr,
__tgt_async_info *AsyncInfo) {
AsyncInfoWrapperTy AsyncInfoWrapper(*this, AsyncInfo);

auto &Err = AsyncInfoWrapper.getError();
Err = recordEventImpl(EventPtr, AsyncInfoWrapper);
return AsyncInfoWrapper.finalize();
auto Err = recordEventImpl(EventPtr, AsyncInfoWrapper);
AsyncInfoWrapper.finalize(Err);
return Err;
}

Error GenericDeviceTy::waitEvent(void *EventPtr, __tgt_async_info *AsyncInfo) {
AsyncInfoWrapperTy AsyncInfoWrapper(*this, AsyncInfo);

auto &Err = AsyncInfoWrapper.getError();
Err = waitEventImpl(EventPtr, AsyncInfoWrapper);
return AsyncInfoWrapper.finalize();
auto Err = waitEventImpl(EventPtr, AsyncInfoWrapper);
AsyncInfoWrapper.finalize(Err);
return Err;
}

Error GenericDeviceTy::syncEvent(void *EventPtr) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,15 @@ struct AsyncInfoWrapperTy {
/// Indicate whether there is queue.
bool hasQueue() const { return (AsyncInfoPtr->Queue != nullptr); }

// Get a reference to the error associated with the asycnhronous operations
// related to the async info wrapper.
Error &getError() { return Err; }

/// Synchronize with the __tgt_async_info's pending operations if it's the
/// internal async info and return the error associated with the async
/// operations. This function must be called before destroying the object.
Error finalize();
/// internal async info. The error associated to the aysnchronous operations
/// issued in this queue must be provided in \p Err. This function will update
/// the error parameter with the result of the synchronization if it was
/// actually executed. This function must be called before destroying the
/// object and only once.
void finalize(Error &Err);

private:
Error Err;
GenericDeviceTy &Device;
__tgt_async_info LocalAsyncInfo;
__tgt_async_info *AsyncInfoPtr;
Expand Down

0 comments on commit 2213509

Please sign in to comment.