19#include <cuda_runtime.h>
39 template <
bool flag = false>
41 static_assert(flag,
"Using device functionality without gpu support! Configure project with -DCudaSupport=ON.");
59 if (success != cudaSuccess) {
60 NDA_RUNTIME_ERROR <<
"Cuda runtime error: " <<
std::to_string(success) <<
"\n"
61 <<
" message: " << message <<
"\n"
62 <<
" cudaGetErrorName: " << std::string(cudaGetErrorName(success)) <<
"\n"
63 <<
" cudaGetErrorString: " << std::string(cudaGetErrorString(success)) <<
"\n";
73 inline void cuda_device_sync(
bool do_sync =
true, std::string_view func =
"") {
75 std::string msg =
"cudaDeviceSynchronize failed";
77 msg +=
" after call to ";
95 inline cublasOperation_t get_cublas_op(
char op) {
97 case 'N':
return CUBLAS_OP_N;
98 case 'T':
return CUBLAS_OP_T;
99 case 'C':
return CUBLAS_OP_C;
100 default: std::terminate();
return {};
109 template <FloatOrDouble T>
110 using cuda_complex_t = std::conditional_t<std::is_same_v<T, float>, cuComplex, cuDoubleComplex>;
123 template <FloatOrDouble T>
124 cuda_complex_t<T> cucplx(std::complex<T> c) {
125 return {c.real(), c.imag()};
139 template <FloatOrDouble T>
140 cuda_complex_t<T> *cucplx(std::complex<T> *c) {
141 return reinterpret_cast<cuda_complex_t<T> *
>(c);
155 template <FloatOrDouble T>
156 cuda_complex_t<T>
const *cucplx(std::complex<T>
const *c) {
157 return reinterpret_cast<cuda_complex_t<T>
const *
>(c);
171 template <FloatOrDouble T>
172 cuda_complex_t<T> **cucplx(std::complex<T> **c) {
173 return reinterpret_cast<cuda_complex_t<T> **
>(c);
188 template <FloatOrDouble T>
189 cuda_complex_t<T>
const **cucplx(std::complex<T>
const **c) {
190 return reinterpret_cast<cuda_complex_t<T>
const **
>(c);
196#define device_error_check(ARG1, ARG2) compile_error_no_gpu()
205 inline void cuda_device_sync([[maybe_unused]]
bool do_sync =
true, [[maybe_unused]] std::string_view func =
"") {}
Provides concepts for the nda library.
Provides a custom runtime error class and macros to assert conditions and throw exceptions.
static constexpr bool have_cuda
Constexpr variable that is true if the project is configured with CUDA support.
#define device_error_check(ARG1, ARG2)
Trigger a compilation error every time the nda::device_error_check function is called.
static constexpr bool have_device
Constexpr variable that is true if the project is configured with GPU support.
void compile_error_no_gpu()
Trigger a compilation error in case GPU specific functionality is used without configuring the projec...
void cuda_device_sync(bool do_sync=true, std::string_view func="")
Empty function if CudaSupport is not enabled.
std::string to_string(std::array< T, R > const &a)
Get a string representation of a std::array.