Skip to content

Commit 2213509

Browse files
committed
[OpenMP][libomptarget][NFC] Remove error data member from AsyncInfoWrapperTy
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
1 parent 37a867a commit 2213509

File tree

2 files changed

+35
-43
lines changed

2 files changed

+35
-43
lines changed

openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.cpp

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -202,27 +202,21 @@ struct RecordReplayTy {
202202

203203
AsyncInfoWrapperTy::AsyncInfoWrapperTy(GenericDeviceTy &Device,
204204
__tgt_async_info *AsyncInfoPtr)
205-
: Err(Plugin::success()), Device(Device),
206-
AsyncInfoPtr(AsyncInfoPtr ? AsyncInfoPtr : &LocalAsyncInfo) {
207-
// Mark the success as checked. Otherwise, it would produce an error when
208-
// re-assigned another error value.
209-
(void)!Err;
210-
}
205+
: Device(Device),
206+
AsyncInfoPtr(AsyncInfoPtr ? AsyncInfoPtr : &LocalAsyncInfo) {}
211207

212-
Error AsyncInfoWrapperTy::finalize() {
208+
void AsyncInfoWrapperTy::finalize(Error &Err) {
213209
assert(AsyncInfoPtr && "AsyncInfoWrapperTy already finalized");
214210

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

221218
// Invalidate the wrapper object.
222219
AsyncInfoPtr = nullptr;
223-
224-
// Return the error associated to the async operations and the synchronize.
225-
return std::move(Err);
226220
}
227221

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

934-
auto &Err = AsyncInfoWrapper.getError();
935-
Err = dataSubmitImpl(TgtPtr, HstPtr, Size, AsyncInfoWrapper);
936-
return AsyncInfoWrapper.finalize();
928+
auto Err = dataSubmitImpl(TgtPtr, HstPtr, Size, AsyncInfoWrapper);
929+
AsyncInfoWrapper.finalize(Err);
930+
return Err;
937931
}
938932

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

943-
auto &Err = AsyncInfoWrapper.getError();
944-
Err = dataRetrieveImpl(HstPtr, TgtPtr, Size, AsyncInfoWrapper);
945-
return AsyncInfoWrapper.finalize();
937+
auto Err = dataRetrieveImpl(HstPtr, TgtPtr, Size, AsyncInfoWrapper);
938+
AsyncInfoWrapper.finalize(Err);
939+
return Err;
946940
}
947941

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

953-
auto &Err = AsyncInfoWrapper.getError();
954-
Err = dataExchangeImpl(SrcPtr, DstDev, DstPtr, Size, AsyncInfoWrapper);
955-
return AsyncInfoWrapper.finalize();
947+
auto Err = dataExchangeImpl(SrcPtr, DstDev, DstPtr, Size, AsyncInfoWrapper);
948+
AsyncInfoWrapper.finalize(Err);
949+
return Err;
956950
}
957951

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

973-
auto &Err = AsyncInfoWrapper.getError();
974-
Err = GenericKernel.launch(*this, ArgPtrs, ArgOffsets, KernelArgs,
975-
AsyncInfoWrapper);
967+
auto Err = GenericKernel.launch(*this, ArgPtrs, ArgOffsets, KernelArgs,
968+
AsyncInfoWrapper);
976969

977970
if (RecordReplay.isRecordingOrReplaying() &&
978971
RecordReplay.isSaveOutputEnabled())
979972
RecordReplay.saveKernelOutputInfo(GenericKernel.getName(),
980973
AsyncInfoWrapper);
981974

982-
return AsyncInfoWrapper.finalize();
975+
AsyncInfoWrapper.finalize(Err);
976+
return Err;
983977
}
984978

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

990984
AsyncInfoWrapperTy AsyncInfoWrapper(*this, *AsyncInfoPtr);
991985

992-
auto &Err = AsyncInfoWrapper.getError();
993-
Err = initAsyncInfoImpl(AsyncInfoWrapper);
994-
return AsyncInfoWrapper.finalize();
986+
auto Err = initAsyncInfoImpl(AsyncInfoWrapper);
987+
AsyncInfoWrapper.finalize(Err);
988+
return Err;
995989
}
996990

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

1020-
auto &Err = AsyncInfoWrapper.getError();
1021-
Err = recordEventImpl(EventPtr, AsyncInfoWrapper);
1022-
return AsyncInfoWrapper.finalize();
1014+
auto Err = recordEventImpl(EventPtr, AsyncInfoWrapper);
1015+
AsyncInfoWrapper.finalize(Err);
1016+
return Err;
10231017
}
10241018

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

1028-
auto &Err = AsyncInfoWrapper.getError();
1029-
Err = waitEventImpl(EventPtr, AsyncInfoWrapper);
1030-
return AsyncInfoWrapper.finalize();
1022+
auto Err = waitEventImpl(EventPtr, AsyncInfoWrapper);
1023+
AsyncInfoWrapper.finalize(Err);
1024+
return Err;
10311025
}
10321026

10331027
Error GenericDeviceTy::syncEvent(void *EventPtr) {

openmp/libomptarget/plugins-nextgen/common/PluginInterface/PluginInterface.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,15 @@ struct AsyncInfoWrapperTy {
7070
/// Indicate whether there is queue.
7171
bool hasQueue() const { return (AsyncInfoPtr->Queue != nullptr); }
7272

73-
// Get a reference to the error associated with the asycnhronous operations
74-
// related to the async info wrapper.
75-
Error &getError() { return Err; }
76-
7773
/// Synchronize with the __tgt_async_info's pending operations if it's the
78-
/// internal async info and return the error associated with the async
79-
/// operations. This function must be called before destroying the object.
80-
Error finalize();
74+
/// internal async info. The error associated to the aysnchronous operations
75+
/// issued in this queue must be provided in \p Err. This function will update
76+
/// the error parameter with the result of the synchronization if it was
77+
/// actually executed. This function must be called before destroying the
78+
/// object and only once.
79+
void finalize(Error &Err);
8180

8281
private:
83-
Error Err;
8482
GenericDeviceTy &Device;
8583
__tgt_async_info LocalAsyncInfo;
8684
__tgt_async_info *AsyncInfoPtr;

0 commit comments

Comments
 (0)