From: Alexander Alekhin Date: Thu, 21 Nov 2013 09:05:32 +0000 (+0400) Subject: core/ocl: replace dynamic runtime X-Git-Tag: accepted/tizen/6.0/unified/20201030.111113~3635^2~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d0114b24e0c60b574a00a562cccb0479a2ee2da3;p=platform%2Fupstream%2Fopencv.git core/ocl: replace dynamic runtime --- diff --git a/modules/core/include/opencv2/core/opencl/runtime/ocl_runtime.hpp b/modules/core/include/opencv2/core/opencl/runtime/ocl_runtime.hpp new file mode 100644 index 0000000..8191e23 --- /dev/null +++ b/modules/core/include/opencv2/core/opencl/runtime/ocl_runtime.hpp @@ -0,0 +1,34 @@ +#ifndef __OPENCV_CORE_OCL_RUNTIME_HPP__ +#define __OPENCV_CORE_OCL_RUNTIME_HPP__ + +#ifdef HAVE_OPENCL + +#if defined(HAVE_OPENCL_STATIC) + +#if defined __APPLE__ +#include +#else +#include +#endif + +#else // HAVE_OPENCL_STATIC + +#include "ocl_runtime_opencl.hpp" + +#endif // HAVE_OPENCL_STATIC + +#ifndef CL_DEVICE_DOUBLE_FP_CONFIG +#define CL_DEVICE_DOUBLE_FP_CONFIG 0x1032 +#endif + +#ifndef CL_DEVICE_HALF_FP_CONFIG +#define CL_DEVICE_HALF_FP_CONFIG 0x1033 +#endif + +#ifndef CL_VERSION_1_2 +#define CV_REQUIRE_OPENCL_1_2_ERROR CV_ErrorNoReturn(cv::Error::OpenCLApiCallError, "OpenCV compiled without OpenCL v1.2 support, so we can't use functionality from OpenCL v1.2") +#endif + +#endif // HAVE_OPENCL + +#endif // __OPENCV_CORE_OCL_RUNTIME_HPP__ diff --git a/modules/core/src/ocl.cpp b/modules/core/src/ocl.cpp index 96a006f..6681e81 100644 --- a/modules/core/src/ocl.cpp +++ b/modules/core/src/ocl.cpp @@ -42,6 +42,11 @@ #include "precomp.hpp" #include +#ifdef HAVE_OPENCL +#include "opencv2/core/opencl/runtime/opencl_core.hpp" +#else +// TODO FIXIT: This file can't be build without OPENCL + /* Part of the file is an extract from the standard OpenCL headers from Khronos site. Below is the original copyright. @@ -1220,6 +1225,12 @@ OCL_FUNC(cl_int, clReleaseEvent, (cl_event event), (event)) #endif +#ifndef CL_VERSION_1_2 +#define CL_VERSION_1_2 +#endif + +#endif + namespace cv { namespace ocl { struct UMat2D @@ -1298,10 +1309,31 @@ inline bool operator < (const HashKey& h1, const HashKey& h2) return h1.a < h2.a || (h1.a == h2.a && h1.b < h2.b); } +static bool g_isInitialized = false; +static bool g_isOpenCLAvailable = false; bool haveOpenCL() { - initOpenCLAndLoad(0); - return g_haveOpenCL; + if (!g_isInitialized) + { + if (!g_isInitialized) + { + try + { + cl_uint n = 0; + cl_int err = ::clGetPlatformIDs(0, NULL, &n); + if (err != CL_SUCCESS) + g_isOpenCLAvailable = false; + else + g_isOpenCLAvailable = true; + } + catch (...) + { + g_isOpenCLAvailable = false; + } + g_isInitialized = true; + } + } + return g_isOpenCLAvailable; } bool useOpenCL() @@ -1549,7 +1581,11 @@ bool Device::compilerAvailable() const { return p ? p->getBoolProp(CL_DEVICE_COMPILER_AVAILABLE) : false; } bool Device::linkerAvailable() const +#ifdef CL_VERSION_1_2 { return p ? p->getBoolProp(CL_DEVICE_LINKER_AVAILABLE) : false; } +#else +{ CV_REQUIRE_OPENCL_1_2_ERROR; } +#endif int Device::doubleFPConfig() const { return p ? p->getProp(CL_DEVICE_DOUBLE_FP_CONFIG) : 0; } @@ -1558,7 +1594,11 @@ int Device::singleFPConfig() const { return p ? p->getProp(CL_DEVICE_SINGLE_FP_CONFIG) : 0; } int Device::halfFPConfig() const +#ifdef CL_VERSION_1_2 { return p ? p->getProp(CL_DEVICE_HALF_FP_CONFIG) : 0; } +#else +{ CV_REQUIRE_OPENCL_1_2_ERROR; } +#endif bool Device::endianLittle() const { return p ? p->getBoolProp(CL_DEVICE_ENDIAN_LITTLE) : false; } @@ -1609,10 +1649,18 @@ size_t Device::image3DMaxDepth() const { return p ? p->getProp(CL_DEVICE_IMAGE3D_MAX_DEPTH) : 0; } size_t Device::imageMaxBufferSize() const +#ifdef CL_VERSION_1_2 { return p ? p->getProp(CL_DEVICE_IMAGE_MAX_BUFFER_SIZE) : 0; } +#else +{ CV_REQUIRE_OPENCL_1_2_ERROR; } +#endif size_t Device::imageMaxArraySize() const +#ifdef CL_VERSION_1_2 { return p ? p->getProp(CL_DEVICE_IMAGE_MAX_ARRAY_SIZE) : 0; } +#else +{ CV_REQUIRE_OPENCL_1_2_ERROR; } +#endif int Device::maxClockFrequency() const { return p ? p->getProp(CL_DEVICE_MAX_CLOCK_FREQUENCY) : 0; } @@ -1704,7 +1752,12 @@ int Device::preferredVectorWidthHalf() const { return p ? p->getProp(CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF) : 0; } size_t Device::printfBufferSize() const +#ifdef CL_VERSION_1_2 { return p ? p->getProp(CL_DEVICE_PRINTF_BUFFER_SIZE) : 0; } +#else +{ CV_REQUIRE_OPENCL_1_2_ERROR; } +#endif + size_t Device::profilingTimerResolution() const { return p ? p->getProp(CL_DEVICE_PROFILING_TIMER_RESOLUTION) : 0; }