diff --git a/openmp/libomptarget/include/omptarget.h b/openmp/libomptarget/include/omptarget.h --- a/openmp/libomptarget/include/omptarget.h +++ b/openmp/libomptarget/include/omptarget.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -247,8 +248,8 @@ /// 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 isDone(); /// 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 --- a/openmp/libomptarget/src/interface.cpp +++ b/openmp/libomptarget/src/interface.cpp @@ -412,9 +412,12 @@ 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; } diff --git a/openmp/libomptarget/src/omptarget.cpp b/openmp/libomptarget/src/omptarget.cpp --- a/openmp/libomptarget/src/omptarget.cpp +++ b/openmp/libomptarget/src/omptarget.cpp @@ -51,8 +51,10 @@ return BufferLocations.back(); } -bool AsyncInfoTy::isDone() { - synchronize(); +std::optional AsyncInfoTy::isDone() { + if (int Result = synchronize()) + return std::nullopt; + // The async info operations are completed when the internal queue is empty. return isQueueEmpty(); } diff --git a/openmp/libomptarget/src/private.h b/openmp/libomptarget/src/private.h --- a/openmp/libomptarget/src/private.h +++ b/openmp/libomptarget/src/private.h @@ -250,9 +250,12 @@ 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.