19#include <cuproj/assert.cuh>
21#include <cuda_runtime_api.h>
41 logic_error(
char const*
const message) : std::logic_error(message) {}
42 logic_error(std::string
const& message) : std::logic_error(message) {}
49 cuda_error(std::string
const& message) : std::runtime_error(message) {}
58#define CUPROJ_STRINGIFY_DETAIL(x) #x
59#define CUPROJ_STRINGIFY(x) CUPROJ_STRINGIFY_DETAIL(x)
76#define CUPROJ_EXPECTS(cond, reason) \
77 (!!(cond)) ? static_cast<void>(0) \
78 : throw cuproj::logic_error("cuProj failure at: " __FILE__ \
79 ":" CUPROJ_STRINGIFY(__LINE__) ": " reason)
102#define CUPROJ_HOST_DEVICE_EXPECTS(cond, reason) CUPROJ_EXPECTS(cond, reason)
104#define CUPROJ_HOST_DEVICE_EXPECTS(cond, reason) cuproj_assert(cond&& reason)
120#define CUPROJ_FAIL(reason) \
121 throw cuproj::logic_error("cuProj failure at: " __FILE__ ":" CUPROJ_STRINGIFY( \
128inline void throw_cuda_error(cudaError_t error,
const char* file,
unsigned int line)
130 throw cuproj::cuda_error(std::string{
"CUDA error encountered at: " + std::string{file} +
":" +
131 std::to_string(line) +
": " + std::to_string(error) +
" " +
132 cudaGetErrorName(error) +
" " + cudaGetErrorString(error)});
145#define CUPROJ_CUDA_TRY(call) \
147 cudaError_t const status = (call); \
148 if (cudaSuccess != status) { \
149 cudaGetLastError(); \
150 cuproj::detail::throw_cuda_error(status, __FILE__, __LINE__); \
168#define CUPROJ_CHECK_CUDA(stream) \
170 CUPROJ_CUDA_TRY(cudaStreamSynchronize(stream)); \
171 CUPROJ_CUDA_TRY(cudaPeekAtLastError()); \
174#define CUPROJ_CHECK_CUDA(stream) CUPROJ_CUDA_TRY(cudaPeekAtLastError());
Exception thrown when a CUDA error is encountered.
Exception thrown when logical precondition is violated.