[Libomptarget] Check errors when synchronizing the async queue
authorJoseph Huber <jhuber6@vols.utk.edu>
Thu, 16 Feb 2023 15:51:21 +0000 (09:51 -0600)
committerJoseph Huber <jhuber6@vols.utk.edu>
Thu, 16 Feb 2023 16:10:21 +0000 (10:10 -0600)
Currently when we synchronize the asynchronous queue for the plugins, we
ignore the return value. This is problematic because we will continue on
like nothing happened if the kernel fails.

Fixes https://github.com/llvm/llvm-project/issues/60814

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D144191

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

index 9df9e22..dd577e4 100644 (file)
@@ -17,6 +17,7 @@
 #include <cstdint>
 #include <deque>
 #include <functional>
+#include <optional>
 #include <stddef.h>
 #include <stdint.h>
 #include <type_traits>
@@ -247,8 +248,8 @@ public:
   /// functions will be executed once and unregistered afterwards.
   ///
   /// \returns true if there is no pending asynchronous operations, false
-  /// otherwise.
-  bool isDone();
+  /// otherwise. We return a null value in the case of an error from the plugin.
+  std::optional<bool> isDone();
 
   /// Add a new post-processing function to be executed after synchronization.
   ///
index beea0c2..79d465c 100644 (file)
@@ -412,9 +412,12 @@ EXTERN void __tgt_target_nowait_query(void **AsyncHandle) {
   if (QueryCounter.isAboveThreshold())
     AsyncInfo->SyncType = AsyncInfoTy::SyncTy::BLOCKING;
 
+  auto DoneOrErr = AsyncInfo->isDone();
+  if (!DoneOrErr)
+    FATAL_MESSAGE0(1, "Error while synchronizing the async queue\n");
   // If there are device operations still pending, return immediately without
   // deallocating the handle and increase the current thread query count.
-  if (!AsyncInfo->isDone()) {
+  if (!*DoneOrErr) {
     QueryCounter.increment();
     return;
   }
index b0d10df..8b32324 100644 (file)
@@ -51,8 +51,10 @@ void *&AsyncInfoTy::getVoidPtrLocation() {
   return BufferLocations.back();
 }
 
-bool AsyncInfoTy::isDone() {
-  synchronize();
+std::optional<bool> AsyncInfoTy::isDone() {
+  if (int Result = synchronize())
+    return std::nullopt;
+
   // The async info operations are completed when the internal queue is empty.
   return isQueueEmpty();
 }
index 9f15619..7d3f8b9 100644 (file)
@@ -250,9 +250,12 @@ public:
     if (AsyncInfo == &LocalAsyncInfo)
       return;
 
+    auto DoneOrErr = AsyncInfo->isDone();
+    if (!DoneOrErr)
+      FATAL_MESSAGE0(1, "Error while synchronizing the async queue\n");
     // If the are device operations still pending, return immediately without
     // deallocating the handle.
-    if (!AsyncInfo->isDone())
+    if (!*DoneOrErr)
       return;
 
     // Delete the handle and unset it from the OpenMP task data.