diff --git a/include/hip/hip_api.h b/include/hip/hip_api.h index 48e3fdb..217a4eb 100644 --- a/include/hip/hip_api.h +++ b/include/hip/hip_api.h @@ -281,6 +281,12 @@ hipError_t hipEventElapsedTime(float* ms, hipEvent_t start, hipEvent_t stop) return hip::detail::delta_time(ms, start, stop); } +inline +hipError_t hipEventQuery(hipEvent_t event) +{ + return hip::detail::query_event(event); +} + inline hipError_t hipEventRecord(hipEvent_t event, hipStream_t stream = {}) { diff --git a/src/include/hip/detail/api.hpp b/src/include/hip/detail/api.hpp index 0053df2..894c5bd 100644 --- a/src/include/hip/detail/api.hpp +++ b/src/include/hip/detail/api.hpp @@ -362,6 +362,17 @@ namespace hip return hipSuccess; } + inline + hipError_t query_event(Event* e) + { + if (!e) return hipErrorInvalidHandle; + //if (!is_done(*e).valid()) return hipErrorInvalidHandle; + + if (!is_ready(*e)) return hipErrorNotReady; + + return hipSuccess; + } + inline hipError_t query_stream(Stream* s) { diff --git a/src/include/hip/detail/event.hpp b/src/include/hip/detail/event.hpp index 01c72d5..5d924fe 100644 --- a/src/include/hip/detail/event.hpp +++ b/src/include/hip/detail/event.hpp @@ -66,6 +66,12 @@ namespace hip } friend inline + decltype(auto) is_ready(const Event& x) noexcept + { + return x.is_ready(); + } + friend + inline decltype(auto) timestamp(const Event& x) noexcept { return x.timestamp(); @@ -93,6 +99,7 @@ namespace hip // ACCESSORS bool is_all_synchronising() const noexcept; const awaitable_type& is_done() const noexcept; + bool is_ready() const noexcept; time_type timestamp() const noexcept; }; @@ -134,6 +141,19 @@ namespace hip return is_done_; } + inline + bool Event::is_ready() const noexcept + { + // a default-constructed event does not correspond to any work, + // so it is considered "ready" + if (not is_done_.valid()) + return true; + + // check if the event is "ready" + return is_done_.wait_for(std::chrono::seconds(0)) + == std::future_status::ready; + } + inline Event::time_type Event::timestamp() const noexcept { @@ -141,4 +161,4 @@ namespace hip } // END STRUCT EVENT } // Namespace hip::detail. -} // Namespace hip. \ No newline at end of file +} // Namespace hip.