stream.h 505 Bytes
Newer Older
Nianchen Deng's avatar
sync    
Nianchen Deng committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <cuda_runtime.h>
#include <memory>

namespace utils::cuda {
    class Stream {
    public:
        Stream() : _p_stream(std::make_shared<cudaStream_t>()) {
            cudaStreamCreate(_p_stream.get());
        }

        virtual ~Stream() {
            if (_p_stream.use_count() == 1)
                cudaStreamDestroy(*_p_stream);
        }

        operator cudaStream_t() { return *_p_stream; }

    private:
        std::shared_ptr<cudaStream_t> _p_stream;
    };
} // namespace utils::cuda