1
0

refactor repo

This commit is contained in:
Pcornat 2024-03-25 18:13:16 +01:00
parent 22ebb857eb
commit 24a83dfa08
Signed by: Pcornat
GPG Key ID: E0326CC678A00BDD
5 changed files with 32 additions and 10 deletions

View File

@ -5,7 +5,15 @@ option(ENABLE_TESTS "Enable tests' cmake target." ON)
find_package(CUDAToolkit REQUIRED)
add_library(raiiSafeCuda SHARED safe_cuda/stream_related.cpp)
file(GLOB_RECURSE SAFE_CUDA_HEADERS include/*.hpp)
file(GLOB_RECURSE SAFE_CUDA_SOURCES src/*.cpp)
add_library(raiiSafeCuda SHARED
${SAFE_CUDA_HEADERS}
${SAFE_CUDA_SOURCES}
)
target_precompile_headers(raiiSafeCuda PRIVATE ${SAFE_CUDA_HEADERS})
target_compile_definitions(raiiSafeCuda PRIVATE $<$<CONFIG:Debug>:_GLIBCXX_DEBUG>)
target_compile_options(raiiSafeCuda PRIVATE -pipe -Wall -Wextra -pedantic)
target_link_libraries(raiiSafeCuda CUDA::cudart)

View File

@ -0,0 +1,12 @@
//
// Created by postaron on 25/03/24.
//
#ifndef RAIISAFECUDA_MALLOC_UNMANAGEF_HPP
#define RAIISAFECUDA_MALLOC_UNMANAGEF_HPP
namespace safe_cuda {
}
#endif //RAIISAFECUDA_MALLOC_UNMANAGEF_HPP

View File

@ -1,21 +1,18 @@
#ifndef RAIISAFECUDA_STREAM_RELATED_H
#define RAIISAFECUDA_STREAM_RELATED_H
#ifndef RAIISAFECUDA_STREAM_RELATED_HPP
#define RAIISAFECUDA_STREAM_RELATED_HPP
#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;
std::variant<std::unique_ptr<CUstream_st, streamDestroyType>, cudaError_t> create_stream() noexcept;
}
#endif //RAIISAFECUDA_STREAM_RELATED_H
#endif //RAIISAFECUDA_STREAM_RELATED_HPP

5
src/malloc_unmanagef.cpp Normal file
View File

@ -0,0 +1,5 @@
//
// Created by postaron on 25/03/24.
//
#include "malloc_unmanagef.hpp"

View File

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