From 1cd7bac18718b46d9484e582972aa135dd641b3d Mon Sep 17 00:00:00 2001 From: Gallo Alejandro Date: Mon, 12 Sep 2022 18:36:01 +0200 Subject: [PATCH] Add macros to check CUerror and cublasStatus_t --- include/atrip/CUDA.hpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/include/atrip/CUDA.hpp b/include/atrip/CUDA.hpp index 9610986..3f87e12 100644 --- a/include/atrip/CUDA.hpp +++ b/include/atrip/CUDA.hpp @@ -1,5 +1,13 @@ #pragma once +#include + +#if defined(HAVE_CUDA) +#include +#endif + +#include + #if defined(HAVE_CUDA) && defined(__CUDACC__) # define __MAYBE_GLOBAL__ __global__ # define __MAYBE_DEVICE__ __device__ @@ -7,3 +15,31 @@ # define __MAYBE_GLOBAL__ # define __MAYBE_DEVICE__ #endif + +#define _CHECK_CUDA_SUCCESS(message, ...) \ + do { \ + CUresult result = __VA_ARGS__; \ + if (result != CUDA_SUCCESS) { \ + auto msg = _FORMAT("\t!!CUDA_ERROR(%d): %s:%d\v%s", \ + result, \ + __FILE__, \ + __LINE__, \ + message); \ + std::cerr << msg; \ + throw msg; \ + } \ + } while (0) + +#define _CHECK_CUBLAS_SUCCESS(message, ...) \ + do { \ + cublasStatus_t result = __VA_ARGS__; \ + if (result != 0) { \ + auto msg = _FORMAT("\t!!CUBLAS_ERROR(%d): %s:%d\v%s", \ + result, \ + __FILE__, \ + __LINE__, \ + message); \ + std::cerr << msg; \ + throw msg; \ + } \ + } while (0)