From 90ff3dd9906f494b0194172519d292fe54863115 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Wed, 19 Oct 2011 11:49:44 +0000 Subject: [PATCH] added cublasSafeCall --- modules/gpu/src/cuda/safe_call.hpp | 10 ++++++++++ modules/gpu/src/error.cpp | 25 ++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/modules/gpu/src/cuda/safe_call.hpp b/modules/gpu/src/cuda/safe_call.hpp index 6e0c219e19..6a7d577293 100644 --- a/modules/gpu/src/cuda/safe_call.hpp +++ b/modules/gpu/src/cuda/safe_call.hpp @@ -45,6 +45,7 @@ #include "cuda_runtime_api.h" #include "cufft.h" +#include "cublas.h" #include "NCV.hpp" #if defined(__GNUC__) @@ -52,11 +53,13 @@ #define nppSafeCall(expr) ___nppSafeCall(expr, __FILE__, __LINE__, __func__) #define ncvSafeCall(expr) ___ncvSafeCall(expr, __FILE__, __LINE__, __func__) #define cufftSafeCall(expr) ___cufftSafeCall(expr, __FILE__, __LINE__, __func__) + #define cublasSafeCall(expr) ___cublasSafeCall(expr, __FILE__, __LINE__, __func__) #else /* defined(__CUDACC__) || defined(__MSVC__) */ #define cudaSafeCall(expr) ___cudaSafeCall(expr, __FILE__, __LINE__) #define nppSafeCall(expr) ___nppSafeCall(expr, __FILE__, __LINE__) #define ncvSafeCall(expr) ___ncvSafeCall(expr, __FILE__, __LINE__) #define cufftSafeCall(expr) ___cufftSafeCall(expr, __FILE__, __LINE__) + #define cublasSafeCall(expr) ___cublasSafeCall(expr, __FILE__, __LINE__) #endif namespace cv @@ -67,6 +70,7 @@ namespace cv void nppError(int err, const char *file, const int line, const char *func = ""); void ncvError(int err, const char *file, const int line, const char *func = ""); void cufftError(int err, const char *file, const int line, const char *func = ""); + void cublasError(int err, const char *file, const int line, const char *func = ""); static inline void ___cudaSafeCall(cudaError_t err, const char *file, const int line, const char *func = "") { @@ -91,6 +95,12 @@ namespace cv if (CUFFT_SUCCESS != err) cv::gpu::cufftError(err, file, line, func); } + + static inline void ___cublasSafeCall(cublasStatus_t err, const char *file, const int line, const char *func = "") + { + if (CUBLAS_STATUS_SUCCESS != err) + cv::gpu::cublasError(err, file, line, func); + } } } diff --git a/modules/gpu/src/error.cpp b/modules/gpu/src/error.cpp index e5090dbc3b..74aa4a87ba 100644 --- a/modules/gpu/src/error.cpp +++ b/modules/gpu/src/error.cpp @@ -178,7 +178,7 @@ namespace error_entry( NPPST_MEM_INTERNAL_ERROR ) }; - const size_t ncv_error_num = sizeof(npp_errors) / sizeof(npp_errors[0]); + const size_t ncv_error_num = sizeof(ncv_errors) / sizeof(ncv_errors[0]); ////////////////////////////////////////////////////////////////////////// // CUFFT errors @@ -197,6 +197,23 @@ namespace }; const int cufft_error_num = sizeof(cufft_errors) / sizeof(cufft_errors[0]); + + ////////////////////////////////////////////////////////////////////////// + // CUBLAS errors + + const ErrorEntry cublas_errors[] = + { + error_entry( CUBLAS_STATUS_SUCCESS ), + error_entry( CUBLAS_STATUS_NOT_INITIALIZED ), + error_entry( CUBLAS_STATUS_ALLOC_FAILED ), + error_entry( CUBLAS_STATUS_INVALID_VALUE ), + error_entry( CUBLAS_STATUS_ARCH_MISMATCH ), + error_entry( CUBLAS_STATUS_MAPPING_ERROR ), + error_entry( CUBLAS_STATUS_EXECUTION_FAILED ), + error_entry( CUBLAS_STATUS_INTERNAL_ERROR ) + }; + + const int cublas_error_num = sizeof(cublas_errors) / sizeof(cublas_errors[0]); } namespace cv @@ -236,6 +253,12 @@ namespace cv string msg = getErrorString(code, cufft_errors, cufft_error_num); cv::gpu::error(msg.c_str(), file, line, func); } + + void cublasError(int code, const char *file, const int line, const char *func) + { + string msg = getErrorString(code, cublas_errors, cublas_error_num); + cv::gpu::error(msg.c_str(), file, line, func); + } } }