refactor repo
This commit is contained in:
		
					parent
					
						
							
								22ebb857eb
							
						
					
				
			
			
				commit
				
					
						24a83dfa08
					
				
			
		
					 5 changed files with 32 additions and 10 deletions
				
			
		| 
						 | 
					@ -5,7 +5,15 @@ option(ENABLE_TESTS "Enable tests' cmake target." ON)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
find_package(CUDAToolkit REQUIRED)
 | 
					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_definitions(raiiSafeCuda PRIVATE $<$<CONFIG:Debug>:_GLIBCXX_DEBUG>)
 | 
				
			||||||
target_compile_options(raiiSafeCuda PRIVATE -pipe -Wall -Wextra -pedantic)
 | 
					target_compile_options(raiiSafeCuda PRIVATE -pipe -Wall -Wextra -pedantic)
 | 
				
			||||||
target_link_libraries(raiiSafeCuda CUDA::cudart)
 | 
					target_link_libraries(raiiSafeCuda CUDA::cudart)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										12
									
								
								include/malloc_unmanagef.hpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								include/malloc_unmanagef.hpp
									
										
									
									
									
										Normal 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
 | 
				
			||||||
| 
						 | 
					@ -1,21 +1,18 @@
 | 
				
			||||||
#ifndef RAIISAFECUDA_STREAM_RELATED_H
 | 
					#ifndef RAIISAFECUDA_STREAM_RELATED_HPP
 | 
				
			||||||
#define RAIISAFECUDA_STREAM_RELATED_H
 | 
					#define RAIISAFECUDA_STREAM_RELATED_HPP
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <memory>
 | 
					#include <memory>
 | 
				
			||||||
#include <cuda_runtime_api.h>
 | 
					#include <cuda_runtime_api.h>
 | 
				
			||||||
#include <variant>
 | 
					#include <variant>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace safe_cuda {
 | 
					namespace safe_cuda {
 | 
				
			||||||
    template<typename T>
 | 
					 | 
				
			||||||
    using returnType = std::variant<T, cudaError_t>;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    using streamDestroyType = decltype(&cudaStreamDestroy);
 | 
					    using streamDestroyType = decltype(&cudaStreamDestroy);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * \brief It tries to create a stream, putting it in a smart pointer with its correct destructor.
 | 
					     * \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
 | 
					     * \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
									
								
							
							
						
						
									
										5
									
								
								src/malloc_unmanagef.cpp
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,5 @@
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					// Created by postaron on 25/03/24.
 | 
				
			||||||
 | 
					//
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#include "malloc_unmanagef.hpp"
 | 
				
			||||||
| 
						 | 
					@ -1,7 +1,7 @@
 | 
				
			||||||
#include "stream_related.h"
 | 
					#include "stream_related.hpp"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace safe_cuda {
 | 
					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;
 | 
					        cudaStream_t stream = nullptr;
 | 
				
			||||||
        const cudaError_t error = cudaStreamCreate(&stream);
 | 
					        const cudaError_t error = cudaStreamCreate(&stream);
 | 
				
			||||||
        if (error != cudaSuccess) {
 | 
					        if (error != cudaSuccess) {
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue