18 # include <cuda_runtime.h>
22 #include <boost/fiber/cuda/waitfor.hpp>
23 #include <boost/fiber/mutex.hpp>
24 #include <boost/fiber/recursive_mutex.hpp>
37 using Stream_t = cudaStream_t;
45 void push(
const Stream_t&
s ) {
52 bool pop( Stream_t&
s ) {
54 if (
queue.empty() ) {
return false; }
63 cudaStreamDestroy(
s );
68 StreamList available_streams{};
70 const char* errname = cudaGetErrorName( err );
71 const char* errstr = cudaGetErrorString( err );
73 std::format(
"Encountered CUDA error {} [{}]: {} on {}:{}", errname,
int( err ), errstr, file,
line );
78 : m_stream(
nullptr ), m_parent( parent ), m_dependents( 0 ) {
79 if ( !available_streams.pop(
m_stream ) ) {
80 cudaError_t err = cudaStreamCreate( &
m_stream );
81 if ( err != cudaSuccess ) {
85 err = cudaStreamSynchronize(
m_stream );
86 if ( err != cudaSuccess ) {
103 auto res = boost::fibers::cuda::waitfor_all(
m_stream );
104 cudaError_t temp_error = std::get<1>( res );
105 if ( ( temp_error ) != cudaSuccess ) {
107 std::string errmsg = err_fmt( temp_error, __FILE__, __LINE__ );