[llvm-branch-commits] [openmp] babeb69 - [OpenMP] Make isDone lightweight without calling synchronize

Tobias Hieta via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Feb 20 00:34:42 PST 2023


Author: Ye Luo
Date: 2023-02-20T09:33:18+01:00
New Revision: babeb697ccd7d02a7e5674b3c850c8a8de34c2fe

URL: https://github.com/llvm/llvm-project/commit/babeb697ccd7d02a7e5674b3c850c8a8de34c2fe
DIFF: https://github.com/llvm/llvm-project/commit/babeb697ccd7d02a7e5674b3c850c8a8de34c2fe.diff

LOG: [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

(cherry picked from commit e2069be83ea88837e1d3bb710aff17cd84ee7b7e)

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/openmp/libomptarget/include/omptarget.h b/openmp/libomptarget/include/omptarget.h
index dd577e4051e2..4aab729190b9 100644
--- a/openmp/libomptarget/include/omptarget.h
+++ b/openmp/libomptarget/include/omptarget.h
@@ -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 @@ class AsyncInfoTy {
 
   /// 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.
   ///

diff  --git a/openmp/libomptarget/src/interface.cpp b/openmp/libomptarget/src/interface.cpp
index 45f499962e4d..b155d09dcf8c 100644
--- a/openmp/libomptarget/src/interface.cpp
+++ b/openmp/libomptarget/src/interface.cpp
@@ -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;
   }

diff  --git a/openmp/libomptarget/src/omptarget.cpp b/openmp/libomptarget/src/omptarget.cpp
index 221ba949b8eb..bbf1389429fe 100644
--- a/openmp/libomptarget/src/omptarget.cpp
+++ b/openmp/libomptarget/src/omptarget.cpp
@@ -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();

diff  --git a/openmp/libomptarget/src/private.h b/openmp/libomptarget/src/private.h
index fe55355e6218..9f156192e103 100644
--- a/openmp/libomptarget/src/private.h
+++ b/openmp/libomptarget/src/private.h
@@ -250,13 +250,9 @@ class TaskAsyncInfoWrapperTy {
     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.


        


More information about the llvm-branch-commits mailing list