Skip to content

Commit f57f59e

Browse files
jhuber6tru
authored andcommitted
[Libomptarget] Check errors when synchronizing the async queue
Summary: 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 #60814 Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D144191 (cherry picked from commit 5172877)
1 parent 2e6db25 commit f57f59e

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

openmp/libomptarget/include/omptarget.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <cstdint>
1818
#include <deque>
1919
#include <functional>
20+
#include <optional>
2021
#include <stddef.h>
2122
#include <stdint.h>
2223
#include <type_traits>
@@ -247,8 +248,8 @@ class AsyncInfoTy {
247248
/// functions will be executed once and unregistered afterwards.
248249
///
249250
/// \returns true if there is no pending asynchronous operations, false
250-
/// otherwise.
251-
bool isDone();
251+
/// otherwise. We return a null value in the case of an error from the plugin.
252+
std::optional<bool> isDone();
252253

253254
/// Add a new post-processing function to be executed after synchronization.
254255
///

openmp/libomptarget/src/interface.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,12 @@ 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)
417+
FATAL_MESSAGE0(1, "Error while querying the async queue for completion.\n");
415418
// If there are device operations still pending, return immediately without
416419
// deallocating the handle and increase the current thread query count.
417-
if (!AsyncInfo->isDone()) {
420+
if (!*DoneOrErr) {
418421
QueryCounter.increment();
419422
return;
420423
}

openmp/libomptarget/src/omptarget.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@ void *&AsyncInfoTy::getVoidPtrLocation() {
5151
return BufferLocations.back();
5252
}
5353

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

openmp/libomptarget/src/private.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,13 @@ 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");
253257
// If the are device operations still pending, return immediately without
254258
// deallocating the handle.
255-
if (!AsyncInfo->isDone())
259+
if (!*DoneOrErr)
256260
return;
257261

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

0 commit comments

Comments
 (0)