diff --git a/CMakeLists.txt b/CMakeLists.txt index c30845e4f1..0679b3f956 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -862,11 +862,10 @@ endif() if(HAVE_OPENCL) status("") status(" OpenCL:") - set(__opencl_ver "invalid") - if(HAVE_OPENCL12) - set(__opencl_ver "1.2") - elseif(HAVE_OPENCL11) - set(__opencl_ver "1.1") + if(HAVE_OPENCL_STATIC) + set(__opencl_ver "static") + else() + set(__opencl_ver "dynamic") endif() status(" Version:" ${__opencl_ver}) if(OPENCL_INCLUDE_DIR) diff --git a/cmake/OpenCVDetectOpenCL.cmake b/cmake/OpenCVDetectOpenCL.cmake index 7ed54b565d..f732546e51 100644 --- a/cmake/OpenCVDetectOpenCL.cmake +++ b/cmake/OpenCVDetectOpenCL.cmake @@ -3,58 +3,37 @@ if(APPLE) set(OPENCL_LIBRARY "-framework OpenCL" CACHE STRING "OpenCL library") set(OPENCL_INCLUDE_DIR "" CACHE STRING "OpenCL include directory") mark_as_advanced(OPENCL_INCLUDE_DIR OPENCL_LIBRARY) + set(HAVE_OPENCL_STATIC ON) else(APPLE) - #find_package(OpenCL QUIET) - - if(NOT OPENCL_FOUND) - find_path(OPENCL_ROOT_DIR - NAMES OpenCL/cl.h CL/cl.h include/CL/cl.h include/nvidia-current/CL/cl.h - PATHS ENV OCLROOT ENV AMDAPPSDKROOT ENV CUDA_PATH ENV INTELOCLSDKROOT - DOC "OpenCL root directory" - NO_DEFAULT_PATH) - - find_path(OPENCL_INCLUDE_DIR - NAMES OpenCL/cl.h CL/cl.h - HINTS ${OPENCL_ROOT_DIR} - PATH_SUFFIXES include include/nvidia-current - DOC "OpenCL include directory" - NO_DEFAULT_PATH) - - set(OPENCL_LIBRARY "OPENCL_DYNAMIC_LOAD") - - mark_as_advanced(OPENCL_INCLUDE_DIR OPENCL_LIBRARY) - include(FindPackageHandleStandardArgs) - FIND_PACKAGE_HANDLE_STANDARD_ARGS(OPENCL DEFAULT_MSG OPENCL_LIBRARY OPENCL_INCLUDE_DIR ) - endif() + set(OPENCL_FOUND YES) + set(HAVE_OPENCL_STATIC OFF) + set(OPENCL_INCLUDE_DIR "${OpenCV_SOURCE_DIR}/3rdparty/include/opencl/1.2") endif(APPLE) if(OPENCL_FOUND) - try_compile(HAVE_OPENCL11 - "${OpenCV_BINARY_DIR}" - "${OpenCV_SOURCE_DIR}/cmake/checks/opencl11.cpp" - CMAKE_FLAGS "-DINCLUDE_DIRECTORIES:STRING=${OPENCL_INCLUDE_DIR}" - ) - if(NOT HAVE_OPENCL11) - message(STATUS "OpenCL 1.1 not found, ignore OpenCL SDK") - return() - endif() - try_compile(HAVE_OPENCL12 - "${OpenCV_BINARY_DIR}" - "${OpenCV_SOURCE_DIR}/cmake/checks/opencl12.cpp" - CMAKE_FLAGS "-DINCLUDE_DIRECTORIES:STRING=${OPENCL_INCLUDE_DIR}" - ) - if(NOT HAVE_OPENCL12) - message(STATUS "OpenCL 1.2 not found, will use OpenCL 1.1") + if(NOT HAVE_OPENCL_STATIC) + try_compile(__VALID_OPENCL + "${OpenCV_BINARY_DIR}" + "${OpenCV_SOURCE_DIR}/cmake/checks/opencl.cpp" + CMAKE_FLAGS "-DINCLUDE_DIRECTORIES:STRING=${OPENCL_INCLUDE_DIR}" + OUTPUT_VARIABLE TRY_OUT + ) + if(NOT TRY_OUT MATCHES "OpenCL is valid") + message(WARNING "Can't use OpenCL") + return() + endif() endif() set(HAVE_OPENCL 1) - set(OPENCL_INCLUDE_DIRS ${OPENCL_INCLUDE_DIR}) - if(OPENCL_LIBRARY MATCHES "OPENCL_DYNAMIC_LOAD") - unset(OPENCL_LIBRARIES) - else() + + if(HAVE_OPENCL_STATIC) set(OPENCL_LIBRARIES "${OPENCL_LIBRARY}") + else() + unset(OPENCL_LIBRARIES) endif() + set(OPENCL_INCLUDE_DIRS ${OPENCL_INCLUDE_DIR}) + if(WITH_OPENCLAMDFFT) find_path(CLAMDFFT_ROOT_DIR NAMES include/clAmdFft.h diff --git a/cmake/checks/opencl12.cpp b/cmake/checks/opencl.cpp similarity index 76% rename from cmake/checks/opencl12.cpp rename to cmake/checks/opencl.cpp index 639502e02a..a46baf756a 100644 --- a/cmake/checks/opencl12.cpp +++ b/cmake/checks/opencl.cpp @@ -7,8 +7,9 @@ int main(int argc, char** argv) { #ifdef CL_VERSION_1_2 +#error OpenCL is valid #else -#error OpenCL 1.2 not found +#error OpenCL check failed #endif return 0; } diff --git a/cmake/checks/opencl11.cpp b/cmake/checks/opencl11.cpp deleted file mode 100644 index b17889d1d4..0000000000 --- a/cmake/checks/opencl11.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#if defined __APPLE__ -#include -#else -#include -#endif - -int main(int argc, char** argv) -{ -#ifdef CL_VERSION_1_1 -#else -#error OpenCL 1.1 not found -#endif - return 0; -} diff --git a/cmake/templates/cvconfig.h.cmake b/cmake/templates/cvconfig.h.cmake index 14eb519d01..88c307dd98 100644 --- a/cmake/templates/cvconfig.h.cmake +++ b/cmake/templates/cvconfig.h.cmake @@ -108,8 +108,7 @@ /* OpenCL Support */ #cmakedefine HAVE_OPENCL -#cmakedefine HAVE_OPENCL11 -#cmakedefine HAVE_OPENCL12 +#cmakedefine HAVE_OPENCL_STATIC /* OpenEXR codec */ #cmakedefine HAVE_OPENEXR diff --git a/modules/ocl/CMakeLists.txt b/modules/ocl/CMakeLists.txt index 21e0b30858..a35aea0e2d 100644 --- a/modules/ocl/CMakeLists.txt +++ b/modules/ocl/CMakeLists.txt @@ -5,4 +5,4 @@ endif() set(the_description "OpenCL-accelerated Computer Vision") ocv_define_module(ocl opencv_core opencv_imgproc opencv_features2d opencv_objdetect opencv_video opencv_calib3d opencv_ml "${OPENCL_LIBRARIES}") -ocv_warnings_disable(CMAKE_CXX_FLAGS -Wshadow) +ocv_warnings_disable(CMAKE_CXX_FLAGS -Wshadow -Wundef) diff --git a/modules/ocl/include/opencv2/ocl/cl_runtime/cl_runtime.hpp b/modules/ocl/include/opencv2/ocl/cl_runtime/cl_runtime.hpp index 3e62edec92..86e7ebcc39 100644 --- a/modules/ocl/include/opencv2/ocl/cl_runtime/cl_runtime.hpp +++ b/modules/ocl/include/opencv2/ocl/cl_runtime/cl_runtime.hpp @@ -3,14 +3,20 @@ #ifdef HAVE_OPENCL -#if defined(HAVE_OPENCL12) -#include "cl_runtime_opencl12.hpp" -#elif defined(HAVE_OPENCL11) -#include "cl_runtime_opencl11.hpp" +#if defined(HAVE_OPENCL_STATIC) + +#if defined __APPLE__ +#include #else -#error Invalid OpenCL configuration +#include #endif -#endif +#else // HAVE_OPENCL_STATIC + +#include "cl_runtime_opencl.hpp" + +#endif // HAVE_OPENCL_STATIC + +#endif // HAVE_OPENCL #endif // __OPENCV_OCL_CL_RUNTIME_HPP__ diff --git a/modules/ocl/src/cl_runtime/cl_runtime.cpp b/modules/ocl/src/cl_runtime/cl_runtime.cpp index c237afe74c..a0d967c0b9 100644 --- a/modules/ocl/src/cl_runtime/cl_runtime.cpp +++ b/modules/ocl/src/cl_runtime/cl_runtime.cpp @@ -1,13 +1,6 @@ #include "precomp.hpp" -#if defined(HAVE_OPENCL) && (!defined(__APPLE__) || defined(IOS)) - -#if defined(BUILD_SHARED_LIBS) && (defined WIN32 || defined _WIN32 || defined WINCE) -#define CL_RUNTIME_EXPORT __declspec(dllexport) -#else -#define CL_RUNTIME_EXPORT -#endif - +#if defined(HAVE_OPENCL) && !defined(HAVE_OPENCL_STATIC) #include "opencv2/ocl/cl_runtime/cl_runtime.hpp" @@ -94,12 +87,6 @@ static void* opencl_check_fn(int ID) return func; } -#if defined(HAVE_OPENCL12) -#include "cl_runtime_opencl12_impl.hpp" -#elif defined(HAVE_OPENCL11) -#include "cl_runtime_opencl11_impl.hpp" -#else -#error Invalid OpenCL configuration -#endif +#include "cl_runtime_opencl_impl.hpp" #endif diff --git a/modules/ocl/src/cl_runtime/generator/generate.sh b/modules/ocl/src/cl_runtime/generator/generate.sh index 5be039dfef..bc2d8d0fb7 100644 --- a/modules/ocl/src/cl_runtime/generator/generate.sh +++ b/modules/ocl/src/cl_runtime/generator/generate.sh @@ -1,7 +1,6 @@ #!/bin/bash -e echo "Generate files for CL runtime..." -cat sources/opencl11/cl.h | python parser_cl.py cl_runtime_opencl11 -cat sources/opencl12/cl.h | python parser_cl.py cl_runtime_opencl12 +cat sources/cl.h | python parser_cl.py cl_runtime_opencl cat sources/clAmdBlas.h | python parser_clamdblas.py cat sources/clAmdFft.h | python parser_clamdfft.py echo "Generate files for CL runtime... Done" diff --git a/modules/ocl/src/cl_runtime/generator/template/cl_runtime_opencl.hpp.in b/modules/ocl/src/cl_runtime/generator/template/cl_runtime_opencl.hpp.in index 0079cb696d..86690af868 100644 --- a/modules/ocl/src/cl_runtime/generator/template/cl_runtime_opencl.hpp.in +++ b/modules/ocl/src/cl_runtime/generator/template/cl_runtime_opencl.hpp.in @@ -1,12 +1,6 @@ #ifndef __OPENCV_OCL_CL_RUNTIME_OPENCL_HPP__ #define __OPENCV_OCL_CL_RUNTIME_OPENCL_HPP__ -#ifdef HAVE_OPENCL - -#if defined __APPLE__ && !defined(IOS) -#include -#else - @CL_REMAP_ORIGIN@ #if defined __APPLE__ @@ -27,8 +21,4 @@ @CL_FN_DECLARATIONS@ -#endif - -#endif - #endif // __OPENCV_OCL_CL_RUNTIME_OPENCL_HPP__ diff --git a/modules/ocl/src/svm.cpp b/modules/ocl/src/svm.cpp index ca81128ed7..9239ddfac8 100644 --- a/modules/ocl/src/svm.cpp +++ b/modules/ocl/src/svm.cpp @@ -46,7 +46,7 @@ #include "opencl_kernels.hpp" // TODO Remove this after HAVE_CLAMDBLAS eliminating -#ifdef __GNUC__ +#if defined(__GNUC__) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 8) # pragma GCC diagnostic ignored "-Wunused-but-set-variable" #endif