1 // This file is part of OpenCV project. 2 // It is subject to the license terms in the LICENSE file found in the top-level directory 3 // of this distribution and at http://opencv.org/license.html. 4 5 // Copyright (C) 2014, Advanced Micro Devices, Inc., all rights reserved. 6 // Third party copyrights are property of their respective owners. 7 8 #ifndef OPENCV_CORE_OPENCL_DEFS_HPP 9 #define OPENCV_CORE_OPENCL_DEFS_HPP 10 11 #include "opencv2/core/utility.hpp" 12 #include "cvconfig.h" 13 14 namespace cv { namespace ocl { 15 #ifdef HAVE_OPENCL 16 /// Call is similar to useOpenCL() but doesn't try to load OpenCL runtime or create OpenCL context 17 CV_EXPORTS bool isOpenCLActivated(); 18 #else 19 static inline bool isOpenCLActivated() { return false; } 20 #endif 21 }} // namespace 22 23 24 //#define CV_OPENCL_RUN_ASSERT 25 26 #ifdef HAVE_OPENCL 27 28 #ifdef CV_OPENCL_RUN_VERBOSE 29 #define CV_OCL_RUN_(condition, func, ...) \ 30 { \ 31 if (cv::ocl::isOpenCLActivated() && (condition) && func) \ 32 { \ 33 printf("%s: OpenCL implementation is running\n", CV_Func); \ 34 fflush(stdout); \ 35 CV_IMPL_ADD(CV_IMPL_OCL); \ 36 return __VA_ARGS__; \ 37 } \ 38 else \ 39 { \ 40 printf("%s: Plain implementation is running\n", CV_Func); \ 41 fflush(stdout); \ 42 } \ 43 } 44 #elif defined CV_OPENCL_RUN_ASSERT 45 #define CV_OCL_RUN_(condition, func, ...) \ 46 { \ 47 if (cv::ocl::isOpenCLActivated() && (condition)) \ 48 { \ 49 if(func) \ 50 { \ 51 CV_IMPL_ADD(CV_IMPL_OCL); \ 52 } \ 53 else \ 54 { \ 55 CV_Error(cv::Error::StsAssert, #func); \ 56 } \ 57 return __VA_ARGS__; \ 58 } \ 59 } 60 #else 61 #define CV_OCL_RUN_(condition, func, ...) \ 62 try \ 63 { \ 64 if (cv::ocl::isOpenCLActivated() && (condition) && func) \ 65 { \ 66 CV_IMPL_ADD(CV_IMPL_OCL); \ 67 return __VA_ARGS__; \ 68 } \ 69 } \ 70 catch (const cv::Exception& e) \ 71 { \ 72 CV_UNUSED(e); /* TODO: Add some logging here */ \ 73 } 74 #endif 75 76 #else 77 #define CV_OCL_RUN_(condition, func, ...) 78 #endif 79 80 #define CV_OCL_RUN(condition, func) CV_OCL_RUN_(condition, func) 81 82 #endif // OPENCV_CORE_OPENCL_DEFS_HPP 83