From ebe7ff991f971131d7483858e96dcd8cff4e62b5 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Thu, 18 Jul 2013 11:24:34 +0400 Subject: [PATCH] fixed compilation without CUBLAS and CUFFT --- modules/gpu/src/cuda/imgproc.cu | 8 +++ modules/gpu/src/cuda/safe_call.hpp | 95 +++++++++++++++++++++--------- modules/gpu/src/error.cpp | 8 +++ modules/gpu/src/imgproc.cpp | 31 +++++++++- 4 files changed, 114 insertions(+), 28 deletions(-) diff --git a/modules/gpu/src/cuda/imgproc.cu b/modules/gpu/src/cuda/imgproc.cu index b23e0a6653..067dfaf640 100644 --- a/modules/gpu/src/cuda/imgproc.cu +++ b/modules/gpu/src/cuda/imgproc.cu @@ -619,6 +619,7 @@ namespace cv { namespace gpu { namespace device ////////////////////////////////////////////////////////////////////////// // mulSpectrums +#ifdef HAVE_CUFFT __global__ void mulSpectrumsKernel(const PtrStep a, const PtrStep b, PtrStepSz c) { const int x = blockIdx.x * blockDim.x + threadIdx.x; @@ -642,11 +643,13 @@ namespace cv { namespace gpu { namespace device if (stream == 0) cudaSafeCall( cudaDeviceSynchronize() ); } +#endif ////////////////////////////////////////////////////////////////////////// // mulSpectrums_CONJ +#ifdef HAVE_CUFFT __global__ void mulSpectrumsKernel_CONJ(const PtrStep a, const PtrStep b, PtrStepSz c) { const int x = blockIdx.x * blockDim.x + threadIdx.x; @@ -670,11 +673,13 @@ namespace cv { namespace gpu { namespace device if (stream == 0) cudaSafeCall( cudaDeviceSynchronize() ); } +#endif ////////////////////////////////////////////////////////////////////////// // mulAndScaleSpectrums +#ifdef HAVE_CUFFT __global__ void mulAndScaleSpectrumsKernel(const PtrStep a, const PtrStep b, float scale, PtrStepSz c) { const int x = blockIdx.x * blockDim.x + threadIdx.x; @@ -699,11 +704,13 @@ namespace cv { namespace gpu { namespace device if (stream) cudaSafeCall( cudaDeviceSynchronize() ); } +#endif ////////////////////////////////////////////////////////////////////////// // mulAndScaleSpectrums_CONJ +#ifdef HAVE_CUFFT __global__ void mulAndScaleSpectrumsKernel_CONJ(const PtrStep a, const PtrStep b, float scale, PtrStepSz c) { const int x = blockIdx.x * blockDim.x + threadIdx.x; @@ -728,6 +735,7 @@ namespace cv { namespace gpu { namespace device if (stream == 0) cudaSafeCall( cudaDeviceSynchronize() ); } +#endif ////////////////////////////////////////////////////////////////////////// // buildWarpMaps diff --git a/modules/gpu/src/cuda/safe_call.hpp b/modules/gpu/src/cuda/safe_call.hpp index 7fae710820..53d691f7cc 100644 --- a/modules/gpu/src/cuda/safe_call.hpp +++ b/modules/gpu/src/cuda/safe_call.hpp @@ -43,53 +43,94 @@ #ifndef __OPENCV_CUDA_SAFE_CALL_HPP__ #define __OPENCV_CUDA_SAFE_CALL_HPP__ +#include "cvconfig.h" + #include -#include -#include -#include "NCV.hpp" -#if defined(__GNUC__) - #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 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__) +#ifdef HAVE_CUFFT +# include #endif -namespace cv { namespace gpu -{ - 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 = ""); +#ifdef HAVE_CUBLAS +# include +#endif + +#include "NCV.hpp" + +namespace cv { namespace gpu { + +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 = ""); + +#ifdef HAVE_CUFFT void cufftError(int err, const char *file, const int line, const char *func = ""); +#endif + +#ifdef HAVE_CUBLAS void cublasError(int err, const char *file, const int line, const char *func = ""); +#endif + }} +// nppSafeCall + static inline void ___nppSafeCall(int err, const char *file, const int line, const char *func = "") { if (err < 0) cv::gpu::nppError(err, file, line, func); } +#if defined(__GNUC__) + #define nppSafeCall(expr) ___nppSafeCall(expr, __FILE__, __LINE__, __func__) +#else + #define nppSafeCall(expr) ___nppSafeCall(expr, __FILE__, __LINE__) +#endif + +// ncvSafeCall + static inline void ___ncvSafeCall(int err, const char *file, const int line, const char *func = "") { if (NCV_SUCCESS != err) cv::gpu::ncvError(err, file, line, func); } -static inline void ___cufftSafeCall(cufftResult_t err, const char *file, const int line, const char *func = "") -{ - if (CUFFT_SUCCESS != err) - cv::gpu::cufftError(err, file, line, func); -} +#if defined(__GNUC__) + #define ncvSafeCall(expr) ___ncvSafeCall(expr, __FILE__, __LINE__, __func__) +#else + #define ncvSafeCall(expr) ___ncvSafeCall(expr, __FILE__, __LINE__) +#endif -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); -} +// cufftSafeCall + +#ifdef HAVE_CUFFT + static inline void ___cufftSafeCall(cufftResult_t err, const char *file, const int line, const char *func = "") + { + if (CUFFT_SUCCESS != err) + cv::gpu::cufftError(err, file, line, func); + } + + #if defined(__GNUC__) + #define cufftSafeCall(expr) ___cufftSafeCall(expr, __FILE__, __LINE__, __func__) + #else + #define cufftSafeCall(expr) ___cufftSafeCall(expr, __FILE__, __LINE__) + #endif +#endif + +// cublasSafeCall + +#ifdef HAVE_CUBLAS + 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); + } + + #if defined(__GNUC__) + #define cublasSafeCall(expr) ___cublasSafeCall(expr, __FILE__, __LINE__, __func__) + #else + #define cublasSafeCall(expr) ___cublasSafeCall(expr, __FILE__, __LINE__) + #endif +#endif #endif /* __OPENCV_CUDA_SAFE_CALL_HPP__ */ diff --git a/modules/gpu/src/error.cpp b/modules/gpu/src/error.cpp index 7f5d5f38d5..ff0cadb75f 100644 --- a/modules/gpu/src/error.cpp +++ b/modules/gpu/src/error.cpp @@ -224,6 +224,7 @@ namespace ////////////////////////////////////////////////////////////////////////// // CUFFT errors +#ifdef HAVE_CUFFT const ErrorEntry cufft_errors[] = { error_entry( CUFFT_INVALID_PLAN ), @@ -238,10 +239,12 @@ namespace }; const int cufft_error_num = sizeof(cufft_errors) / sizeof(cufft_errors[0]); +#endif ////////////////////////////////////////////////////////////////////////// // CUBLAS errors +#ifdef HAVE_CUBLAS const ErrorEntry cublas_errors[] = { error_entry( CUBLAS_STATUS_SUCCESS ), @@ -255,6 +258,7 @@ namespace }; const int cublas_error_num = sizeof(cublas_errors) / sizeof(cublas_errors[0]); +#endif } namespace cv @@ -273,17 +277,21 @@ namespace cv cv::gpu::error(msg.c_str(), file, line, func); } +#ifdef HAVE_CUFFT void cufftError(int code, const char *file, const int line, const char *func) { string msg = getErrorString(code, cufft_errors, cufft_error_num); cv::gpu::error(msg.c_str(), file, line, func); } +#endif +#ifdef HAVE_CUBLAS 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); } +#endif } } diff --git a/modules/gpu/src/imgproc.cpp b/modules/gpu/src/imgproc.cpp index 97c7c766c0..8e452b4a1e 100644 --- a/modules/gpu/src/imgproc.cpp +++ b/modules/gpu/src/imgproc.cpp @@ -1136,6 +1136,8 @@ void cv::gpu::cornerMinEigenVal(const GpuMat& src, GpuMat& dst, GpuMat& Dx, GpuM ////////////////////////////////////////////////////////////////////////////// // mulSpectrums +#ifdef HAVE_CUFFT + namespace cv { namespace gpu { namespace device { namespace imgproc @@ -1146,9 +1148,20 @@ namespace cv { namespace gpu { namespace device } }}} +#endif + void cv::gpu::mulSpectrums(const GpuMat& a, const GpuMat& b, GpuMat& c, int flags, bool conjB, Stream& stream) { - (void)flags; +#ifndef HAVE_CUFFT + (void) a; + (void) b; + (void) c; + (void) flags; + (void) conjB; + (void) stream; + throw_nogpu(); +#else + (void) flags; using namespace ::cv::gpu::device::imgproc; typedef void (*Caller)(const PtrStep, const PtrStep, PtrStepSz, cudaStream_t stream); @@ -1162,11 +1175,14 @@ void cv::gpu::mulSpectrums(const GpuMat& a, const GpuMat& b, GpuMat& c, int flag Caller caller = callers[(int)conjB]; caller(a, b, c, StreamAccessor::getStream(stream)); +#endif } ////////////////////////////////////////////////////////////////////////////// // mulAndScaleSpectrums +#ifdef HAVE_CUFFT + namespace cv { namespace gpu { namespace device { namespace imgproc @@ -1177,8 +1193,20 @@ namespace cv { namespace gpu { namespace device } }}} +#endif + void cv::gpu::mulAndScaleSpectrums(const GpuMat& a, const GpuMat& b, GpuMat& c, int flags, float scale, bool conjB, Stream& stream) { +#ifndef HAVE_CUFFT + (void) a; + (void) b; + (void) c; + (void) flags; + (void) scale; + (void) conjB; + (void) stream; + throw_nogpu(); +#else (void)flags; using namespace ::cv::gpu::device::imgproc; @@ -1192,6 +1220,7 @@ void cv::gpu::mulAndScaleSpectrums(const GpuMat& a, const GpuMat& b, GpuMat& c, Caller caller = callers[(int)conjB]; caller(a, b, scale, c, StreamAccessor::getStream(stream)); +#endif } //////////////////////////////////////////////////////////////////////////////