timed_event#

class timed_event : public event#

An owning wrapper for a cudaEvent_t with timing enabled.

Public Types

using value_type = ::cudaEvent_t#

Public Functions

inline explicit timed_event(
stream_ref __stream,
event_flags __flags = event_flags::none,
)#

Construct a new timed_event object with the specified flags and record the event on the specified stream.

Throws:

cuda_error – if the event creation fails.

inline explicit timed_event(
device_ref __device,
event_flags __flags = event_flags::none,
)#

Construct a new timed_event object with the specified flags.

The event can only be recorded on streams from the specified device.

Throws:

cuda_error – if the event creation fails.

inline explicit constexpr timed_event(no_init_t) noexcept#

Construct a new timed_event object into the moved-from state.

Post:

get() returns cudaEvent_t().

timed_event(timed_event&&) noexcept = default#
timed_event(const timed_event&) = delete#
timed_event &operator=(timed_event&&) noexcept = default#
timed_event &operator=(const timed_event&) = delete#
inline constexpr ::cudaEvent_t release() noexcept#

Retrieve the native cudaEvent_t handle and give up ownership.

Returns:

cudaEvent_t The native handle being held by the event object.

Post:

The event object is in a moved-from state.

inline void record(stream_ref __stream) const#

Records an event on the specified stream.

Parameters:

__stream

Throws:

cuda_error – if the event record fails

inline void sync() const#

Synchronizes the event.

Throws:

cuda_error – if waiting for the event fails

inline bool is_done() const#

Checks if all the work in the stream prior to the record of the event has completed.

If is_done returns true, calling sync() on this event will return immediately

Throws:

cuda_error – if the event query fails

inline constexpr ::cudaEvent_t get() const noexcept#

Retrieve the native cudaEvent_t handle.

Returns:

cudaEvent_t The native handle being held by the event_ref object.

inline explicit constexpr operator bool() const noexcept#

Checks if the event_ref is valid.

Returns:

true if the event_ref is valid, false otherwise.

Public Static Functions

static inline timed_event from_native_handle(
::cudaEvent_t __evnt,
) noexcept#

Construct a timed_event object from a native cudaEvent_t handle.

Note

The constructed timed_event object takes ownership of the native handle.

Parameters:

__evnt – The native handle

Returns:

timed_event The constructed timed_event object

static timed_event from_native_handle(int) = delete#
static timed_event from_native_handle(::cuda::std::nullptr_t) = delete#

Friends

inline friend ::cuda::std::chrono::nanoseconds operator-(
const timed_event &__end,
const timed_event &__start,
)#

Compute the time elapsed between two timed_event objects.

Note

The elapsed time has a resolution of approximately 0.5 microseconds.

Throws:

cuda_error – if the query for the elapsed time fails.

Parameters:
  • __end – The timed_event object representing the end time.

  • __start – The timed_event object representing the start time.

Returns:

cuda::std::chrono::nanoseconds The elapsed time in nanoseconds.