[OpenMP] Make isDone lightweight without calling synchronize
authorYe Luo <yeluo@anl.gov>
Sat, 18 Feb 2023 01:55:40 +0000 (19:55 -0600)
committerYe Luo <yeluo@anl.gov>
Sat, 18 Feb 2023 02:45:43 +0000 (20:45 -0600)
~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

openmp/libomptarget/include/omptarget.h
openmp/libomptarget/src/interface.cpp
openmp/libomptarget/src/omptarget.cpp
openmp/libomptarget/src/private.h

index dd577e4051e21149d97e831a32ebafe3571abde9..4aab729190b9c465dff9364c133611217c33d8b4 100644 (file)
@@ -17,7 +17,6 @@
 #include <cstdint>
 #include <deque>
 #include <functional>
-#include <optional>
 #include <stddef.h>
 #include <stdint.h>
 #include <type_traits>
@@ -244,12 +243,12 @@ public:
 
   /// Check if all asynchronous operations are completed.
   ///
-  /// \note if the operations are completed, the registered post-processing
-  /// functions will be executed once and unregistered afterwards.
+  /// \note only a lightweight check. If needed, use synchronize() to query the
+  /// status of AsyncInfo before checking.
   ///
   /// \returns true if there is no pending asynchronous operations, false
-  /// otherwise. We return a null value in the case of an error from the plugin.
-  std::optional<bool> isDone();
+  /// otherwise.
+  bool isDone() const;
 
   /// Add a new post-processing function to be executed after synchronization.
   ///
index 45f499962e4d1206c6796aa1a67580d7e9c8b82f..b155d09dcf8c73e8ac9fddfcb957ef5c2d757cd0 100644 (file)
@@ -412,12 +412,11 @@ EXTERN void __tgt_target_nowait_query(void **AsyncHandle) {
   if (QueryCounter.isAboveThreshold())
     AsyncInfo->SyncType = AsyncInfoTy::SyncTy::BLOCKING;
 
-  auto DoneOrErr = AsyncInfo->isDone();
-  if (!DoneOrErr)
+  if (const int Rc = AsyncInfo->synchronize())
     FATAL_MESSAGE0(1, "Error while querying the async queue for completion.\n");
   // If there are device operations still pending, return immediately without
   // deallocating the handle and increase the current thread query count.
-  if (!*DoneOrErr) {
+  if (!AsyncInfo->isDone()) {
     QueryCounter.increment();
     return;
   }
index da91a9ab859faf09dd293cb2f354828270f2f946..441da7c452434be3823a30543cf8a9e3d2e9a8f0 100644 (file)
@@ -51,13 +51,7 @@ void *&AsyncInfoTy::getVoidPtrLocation() {
   return BufferLocations.back();
 }
 
-std::optional<bool> AsyncInfoTy::isDone() {
-  if (synchronize() == OFFLOAD_FAIL)
-    return std::nullopt;
-
-  // The async info operations are completed when the internal queue is empty.
-  return isQueueEmpty();
-}
+bool AsyncInfoTy::isDone() const { return isQueueEmpty(); }
 
 int32_t AsyncInfoTy::runPostProcessing() {
   size_t Size = PostProcessingFunctions.size();
index fe55355e62187c1e1ee1d719c55bcb5cfce178f1..9f156192e10363e753f3220cfc18a89b7f9cf178 100644 (file)
@@ -250,13 +250,9 @@ public:
     if (AsyncInfo == &LocalAsyncInfo)
       return;
 
-    auto DoneOrErr = AsyncInfo->isDone();
-    if (!DoneOrErr)
-      FATAL_MESSAGE0(1,
-                     "Error while querying the async queue for completion.\n");
     // If the are device operations still pending, return immediately without
     // deallocating the handle.
-    if (!*DoneOrErr)
+    if (!AsyncInfo->isDone())
       return;
 
     // Delete the handle and unset it from the OpenMP task data.