Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement hipEventQuery() #56

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/hip/hip_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {})
{
Expand Down
11 changes: 11 additions & 0 deletions src/include/hip/detail/api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
22 changes: 21 additions & 1 deletion src/include/hip/detail/event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
};

Expand Down Expand Up @@ -134,11 +141,24 @@ 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
{
return time_;
}
// END STRUCT EVENT
} // Namespace hip::detail.
} // Namespace hip.
} // Namespace hip.