3#include "cuda_error.hpp"
31 TF_CHECK_CUDA(cudaEventCreate(&event),
"failed to create a CUDA event");
41 cudaEventCreateWithFlags(&event, flag),
42 "failed to create a CUDA event with flag=", flag
66 cudaEventDestroy(event);
81template <
typename Creator,
typename Deleter>
82class cudaEventBase :
public std::unique_ptr<std::remove_pointer_t<cudaEvent_t>, Deleter> {
84 static_assert(std::is_pointer_v<cudaEvent_t>,
"cudaEvent_t is not a pointer type");
94 using base_type = std::unique_ptr<std::remove_pointer_t<cudaEvent_t>, Deleter>;
103 template <
typename... ArgsT>
105 Creator{}(std::forward<ArgsT>(args)...), Deleter()
148 TF_CHECK_CUDA(cudaStreamCreate(&stream),
"failed to create a CUDA stream");
173 cudaStreamDestroy(stream);
188template <
typename Creator,
typename Deleter>
189class cudaStreamBase :
public std::unique_ptr<std::remove_pointer_t<cudaStream_t>, Deleter> {
191 static_assert(std::is_pointer_v<cudaStream_t>,
"cudaStream_t is not a pointer type");
201 using base_type = std::unique_ptr<std::remove_pointer_t<cudaStream_t>, Deleter>;
210 template <
typename... ArgsT>
212 Creator{}(std::forward<ArgsT>(args)...), Deleter()
234 cudaStreamSynchronize(this->get()),
"failed to synchronize a CUDA stream"
265 void begin_capture(cudaStreamCaptureMode m = cudaStreamCaptureModeGlobal)
const {
267 cudaStreamBeginCapture(this->get(), m),
268 "failed to begin capture on stream ", this->get(),
" with thread mode ", m
282 cudaGraph_t native_g;
284 cudaStreamEndCapture(this->get(), &native_g),
285 "failed to end capture on stream ", this->get()
298 cudaEventRecord(event, this->get()),
299 "failed to record event ", event,
" on stream ", this->get()
309 void wait(cudaEvent_t event)
const {
311 cudaStreamWaitEvent(this->get(), event, 0),
312 "failed to wait for event ", event,
" on stream ", this->get()
321 template <
typename C,
typename D>
class to create a CUDA event with unique ownership
Definition cuda_stream.hpp:82
std::unique_ptr< std::remove_pointer_t< cudaEvent_t >, Deleter > base_type
base type for the underlying unique pointer
Definition cuda_stream.hpp:94
cudaEventBase(cudaEventBase &&)=default
constructs a cudaEvent from the given rhs using move semantics
cudaEventBase & operator=(cudaEventBase &&)=default
assign the rhs to *this using move semantics
cudaEventBase(ArgsT &&... args)
constructs a cudaEvent object by passing the given arguments to the event creator
Definition cuda_stream.hpp:104
class to create functors that construct CUDA events
Definition cuda_stream.hpp:22
cudaEvent_t operator()() const
creates a new cudaEvent_t object using cudaEventCreate
Definition cuda_stream.hpp:29
class to create a functor that deletes a CUDA event
Definition cuda_stream.hpp:60
void operator()(cudaEvent_t event) const
deletes the given cudaEvent_t object using cudaEventDestroy
Definition cuda_stream.hpp:65
class to create an executable CUDA graph with unique ownership
Definition cuda_graph_exec.hpp:93
class to create a CUDA stream with unique ownership
Definition cuda_stream.hpp:189
cudaStreamBase(cudaStreamBase &&)=default
constructs a cudaStream from the given rhs using move semantics
cudaStreamBase & synchronize()
synchronizes the associated stream
Definition cuda_stream.hpp:232
void begin_capture(cudaStreamCaptureMode m=cudaStreamCaptureModeGlobal) const
begins graph capturing on the stream
Definition cuda_stream.hpp:265
cudaGraph_t end_capture() const
ends graph capturing on the stream
Definition cuda_stream.hpp:281
cudaStreamBase(ArgsT &&... args)
constructs a cudaStream object by passing the given arguments to the stream creator
Definition cuda_stream.hpp:211
void record(cudaEvent_t event) const
records an event on the stream
Definition cuda_stream.hpp:296
cudaStreamBase & run(const cudaGraphExecBase< C, D > &exec)
runs the given executable CUDA graph
void wait(cudaEvent_t event) const
waits on an event
Definition cuda_stream.hpp:309
cudaStreamBase & operator=(cudaStreamBase &&)=default
assign the rhs to *this using move semantics
cudaStreamBase & run(cudaGraphExec_t exec)
runs the given executable CUDA graph
Definition cuda_graph_exec.hpp:366
std::unique_ptr< std::remove_pointer_t< cudaStream_t >, Deleter > base_type
base type for the underlying unique pointer
Definition cuda_stream.hpp:201
class to create functors that construct CUDA streams
Definition cuda_stream.hpp:139
cudaStream_t operator()() const
constructs a new cudaStream_t object using cudaStreamCreate
Definition cuda_stream.hpp:146
class to create a functor that deletes a CUDA stream
Definition cuda_stream.hpp:165
void operator()(cudaStream_t stream) const
deletes the given cudaStream_t object
Definition cuda_stream.hpp:172
taskflow namespace
Definition small_vector.hpp:20
cudaEventBase< cudaEventCreator, cudaEventDeleter > cudaEvent
default smart pointer type to manage a cudaEvent_t object with unique ownership
Definition cuda_stream.hpp:128
cudaStreamBase< cudaStreamCreator, cudaStreamDeleter > cudaStream
default smart pointer type to manage a cudaStream_t object with unique ownership
Definition cuda_stream.hpp:340