X-Git-Url: http://www.fmaj7b5.info/git?p=cuda.git;a=blobdiff_plain;f=libutils%2Fcuda%2FStream.h;fp=libutils%2Fcuda%2FStream.h;h=791cfb11a50624b642c8d0305ff1c51089faf5da;hp=0000000000000000000000000000000000000000;hb=474dc4b3cd13aea3ccaae408eac81bbb616c056b;hpb=9c4ea7a2596620dcb156a00d12bc55c07ba03339 diff --git a/libutils/cuda/Stream.h b/libutils/cuda/Stream.h new file mode 100644 index 0000000..791cfb1 --- /dev/null +++ b/libutils/cuda/Stream.h @@ -0,0 +1,85 @@ +/* + Copyright (C) 2012, 2013 fmaj7b5.info + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#ifndef FM7b5_CUDA_STREAM_H +#define FM7b5_CUDA_STREAM_H + +#include +#include + +class Stream +{ +public: + Stream(); + ~Stream(); + operator cudaStream_t(); + + cudaError_t query() const; + cudaError_t synchronize() const; + cudaError_t wait_event(cudaEvent_t event, unsigned int flags) const; + +protected: + cudaStream_t m_stream; +}; + +Stream::Stream() +{ + cudaError_t status; + + status = cudaStreamCreate(&m_stream); + + if (status != cudaSuccess) { + throw std::runtime_error(cudaGetErrorString(status)); + } +} + +Stream::~Stream() +{ + cudaError_t status; + + status = cudaStreamDestroy(m_stream); + + if (status != cudaSuccess) { + throw std::runtime_error(cudaGetErrorString(status)); + } +} + +Stream::operator cudaStream_t() +{ + return m_stream; +} + +cudaError_t +Stream::query() const +{ + return cudaStreamQuery(m_stream); +} + +cudaError_t +Stream::synchronize() const +{ + return cudaStreamSynchronize(m_stream); + +} + +cudaError_t +Stream::wait_event(cudaEvent_t event, unsigned int flags) const +{ + return cudaStreamWaitEvent(m_stream, event, flags); +} + +#endif /* FM7b5_CUDA_STREAM_H */