Skip to content

Commit be7c1cb

Browse files
authored
[SYCL][CUDA] Use cuEventQuery to check event completion status (#3544)
Previously the completion status of a PI CUDA event (returned by a `get_info` query for `info::event::command_execution_status`) would only be changed to `command_execution_status::complete` once the event had been waited upon. This changes the mechanism to query the underlying event's execution status using `cuEventQuery` if the event has not been waited upon.
1 parent ba9f76c commit be7c1cb

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

sycl/plugins/cuda/pi_cuda.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,9 @@ pi_result cuda_piEventRetain(pi_event event);
322322
/// \endcond
323323

324324
_pi_event::_pi_event(pi_command_type type, pi_context context, pi_queue queue)
325-
: commandType_{type}, refCount_{1}, isCompleted_{false}, isRecorded_{false},
326-
isStarted_{false}, evEnd_{nullptr}, evStart_{nullptr}, evQueued_{nullptr},
327-
queue_{queue}, context_{context} {
325+
: commandType_{type}, refCount_{1}, hasBeenWaitedOn_{false},
326+
isRecorded_{false}, isStarted_{false}, evEnd_{nullptr}, evStart_{nullptr},
327+
evQueued_{nullptr}, queue_{queue}, context_{context} {
328328

329329
bool profilingEnabled = queue_->properties_ & PI_QUEUE_PROFILING_ENABLE;
330330

@@ -367,6 +367,23 @@ pi_result _pi_event::start() {
367367
return result;
368368
}
369369

370+
bool _pi_event::is_completed() const noexcept {
371+
if (!isRecorded_) {
372+
return false;
373+
}
374+
if (!hasBeenWaitedOn_) {
375+
const CUresult ret = cuEventQuery(evEnd_);
376+
if (ret != CUDA_SUCCESS && ret != CUDA_ERROR_NOT_READY) {
377+
PI_CHECK_ERROR(ret);
378+
return false;
379+
}
380+
if (ret == CUDA_ERROR_NOT_READY) {
381+
return false;
382+
}
383+
}
384+
return true;
385+
}
386+
370387
pi_uint64 _pi_event::get_queued_time() const {
371388
float miliSeconds = 0.0f;
372389
assert(is_started());
@@ -428,7 +445,7 @@ pi_result _pi_event::wait() {
428445
pi_result retErr;
429446
try {
430447
retErr = PI_CHECK_ERROR(cuEventSynchronize(evEnd_));
431-
isCompleted_ = true;
448+
hasBeenWaitedOn_ = true;
432449
} catch (pi_result error) {
433450
retErr = error;
434451
}

sycl/plugins/cuda/pi_cuda.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ class _pi_event {
410410

411411
bool is_started() const noexcept { return isStarted_; }
412412

413-
bool is_completed() const noexcept { return isCompleted_; };
413+
bool is_completed() const noexcept;
414414

415415
pi_int32 get_execution_status() const noexcept {
416416

@@ -462,8 +462,9 @@ class _pi_event {
462462

463463
std::atomic_uint32_t refCount_; // Event reference count.
464464

465-
bool isCompleted_; // Signifies whether the operations have completed
466-
//
465+
bool hasBeenWaitedOn_; // Signifies whether the event has been waited
466+
// on through a call to wait(), which implies
467+
// that it has completed.
467468

468469
bool isRecorded_; // Signifies wether a native CUDA event has been recorded
469470
// yet.

0 commit comments

Comments
 (0)