1
0
Fork 0
This commit is contained in:
Pcornat 2024-03-21 16:21:05 +01:00
parent 9f1e9881d6
commit 87f1181a1a
Signed by: Pcornat
GPG key ID: E0326CC678A00BDD
4 changed files with 52 additions and 0 deletions

View file

@ -0,0 +1,13 @@
#include "stream_related.h"
namespace safe_cuda {
returnType<std::unique_ptr<CUstream_st, streamDestroyType>> create_stream() noexcept {
cudaStream_t stream = nullptr;
const cudaError_t error = cudaStreamCreate(&stream);
if (error != cudaSuccess) {
return error;
}
return std::unique_ptr<CUstream_st, streamDestroyType>{ stream, cudaStreamDestroy };
}
}

View file

@ -0,0 +1,21 @@
#ifndef RAIISAFECUDA_STREAM_RELATED_H
#define RAIISAFECUDA_STREAM_RELATED_H
#include <memory>
#include <cuda_runtime_api.h>
#include <variant>
namespace safe_cuda {
template<typename T>
using returnType = std::variant<T, cudaError_t>;
using streamDestroyType = decltype(&cudaStreamDestroy);
/**
* \brief It tries to create a stream, putting it in a smart pointer with its correct destructor.
* \return smart pointer if creation is OK, else the CUDA error
*/
returnType<std::unique_ptr<CUstream_st, streamDestroyType>> create_stream() noexcept;
}
#endif //RAIISAFECUDA_STREAM_RELATED_H