Skip to content

Commit e2069be

Browse files
committed
[OpenMP] Make isDone lightweight without calling synchronize
~TaskAsyncInfoWrapperTy() calls isDone. With synchronize inside isDone, we need to handle the error return from synchronize in the destructor. The consumers of TaskAsyncInfoWrapperTy, targetDataMapper and targetKernel, both call AsyncInfo.synchronize() before exiting. For this reason in ~TaskAsyncInfoWrapperTy(), calling synchronize() via isDone() is redundant. This patch removes synchronize() call inside isDone() and makes it a lightweight check. __tgt_target_nowait_query needs to call synchronize() before checking isDone(). Differential Revision: https://reviews.llvm.org/D144315
1 parent c42eda5 commit e2069be

File tree

4 files changed

+8
-20
lines changed

4 files changed

+8
-20
lines changed

openmp/libomptarget/include/omptarget.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include <cstdint>
1818
#include <deque>
1919
#include <functional>
20-
#include <optional>
2120
#include <stddef.h>
2221
#include <stdint.h>
2322
#include <type_traits>
@@ -244,12 +243,12 @@ class AsyncInfoTy {
244243

245244
/// Check if all asynchronous operations are completed.
246245
///
247-
/// \note if the operations are completed, the registered post-processing
248-
/// functions will be executed once and unregistered afterwards.
246+
/// \note only a lightweight check. If needed, use synchronize() to query the
247+
/// status of AsyncInfo before checking.
249248
///
250249
/// \returns true if there is no pending asynchronous operations, false
251-
/// otherwise. We return a null value in the case of an error from the plugin.
252-
std::optional<bool> isDone();
250+
/// otherwise.
251+
bool isDone() const;
253252

254253
/// Add a new post-processing function to be executed after synchronization.
255254
///

openmp/libomptarget/src/interface.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,12 +412,11 @@ EXTERN void __tgt_target_nowait_query(void **AsyncHandle) {
412412
if (QueryCounter.isAboveThreshold())
413413
AsyncInfo->SyncType = AsyncInfoTy::SyncTy::BLOCKING;
414414

415-
auto DoneOrErr = AsyncInfo->isDone();
416-
if (!DoneOrErr)
415+
if (const int Rc = AsyncInfo->synchronize())
417416
FATAL_MESSAGE0(1, "Error while querying the async queue for completion.\n");
418417
// If there are device operations still pending, return immediately without
419418
// deallocating the handle and increase the current thread query count.
420-
if (!*DoneOrErr) {
419+
if (!AsyncInfo->isDone()) {
421420
QueryCounter.increment();
422421
return;
423422
}

openmp/libomptarget/src/omptarget.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,7 @@ void *&AsyncInfoTy::getVoidPtrLocation() {
5151
return BufferLocations.back();
5252
}
5353

54-
std::optional<bool> AsyncInfoTy::isDone() {
55-
if (synchronize() == OFFLOAD_FAIL)
56-
return std::nullopt;
57-
58-
// The async info operations are completed when the internal queue is empty.
59-
return isQueueEmpty();
60-
}
54+
bool AsyncInfoTy::isDone() const { return isQueueEmpty(); }
6155

6256
int32_t AsyncInfoTy::runPostProcessing() {
6357
size_t Size = PostProcessingFunctions.size();

openmp/libomptarget/src/private.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,9 @@ class TaskAsyncInfoWrapperTy {
250250
if (AsyncInfo == &LocalAsyncInfo)
251251
return;
252252

253-
auto DoneOrErr = AsyncInfo->isDone();
254-
if (!DoneOrErr)
255-
FATAL_MESSAGE0(1,
256-
"Error while querying the async queue for completion.\n");
257253
// If the are device operations still pending, return immediately without
258254
// deallocating the handle.
259-
if (!*DoneOrErr)
255+
if (!AsyncInfo->isDone())
260256
return;
261257

262258
// Delete the handle and unset it from the OpenMP task data.

0 commit comments

Comments
 (0)