summaryrefslogtreecommitdiffstats
path: root/xmrstak/backend/nvidia/nvcc_code/cuda_device.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'xmrstak/backend/nvidia/nvcc_code/cuda_device.hpp')
-rw-r--r--xmrstak/backend/nvidia/nvcc_code/cuda_device.hpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/xmrstak/backend/nvidia/nvcc_code/cuda_device.hpp b/xmrstak/backend/nvidia/nvcc_code/cuda_device.hpp
new file mode 100644
index 0000000..078c165
--- /dev/null
+++ b/xmrstak/backend/nvidia/nvcc_code/cuda_device.hpp
@@ -0,0 +1,30 @@
+
+#pragma once
+
+#include <cuda_runtime.h>
+#include <stdexcept>
+#include <iostream>
+#include <string>
+
+/** execute and check a CUDA api command
+ *
+ * @param id gpu id (thread id)
+ * @param ... CUDA api command
+ */
+#define CUDA_CHECK(id, ...) { \
+ cudaError_t error = __VA_ARGS__; \
+ if(error!=cudaSuccess){ \
+ std::cerr << "[CUDA] Error gpu " << id << ": <" << __FILE__ << ">:" << __LINE__ << std::endl; \
+ throw std::runtime_error(std::string("[CUDA] Error: ") + std::string(cudaGetErrorString(error))); \
+ } \
+} \
+( (void) 0 )
+
+/** execute and check a CUDA kernel
+ *
+ * @param id gpu id (thread id)
+ * @param ... CUDA kernel call
+ */
+#define CUDA_CHECK_KERNEL(id, ...) \
+ __VA_ARGS__; \
+ CUDA_CHECK(id, cudaGetLastError())
OpenPOWER on IntegriCloud