ocl: force to use Khronos OpenCL headers
authorAlexander Alekhin <alexander.alekhin@itseez.com>
Fri, 11 Oct 2013 15:30:47 +0000 (19:30 +0400)
committerAlexander Alekhin <alexander.alekhin@itseez.com>
Fri, 18 Oct 2013 11:47:11 +0000 (15:47 +0400)
12 files changed:
CMakeLists.txt
cmake/OpenCVDetectOpenCL.cmake
cmake/checks/opencl.cpp [new file with mode: 0644]
cmake/checks/opencl11.cpp [deleted file]
cmake/checks/opencl12.cpp [deleted file]
cmake/templates/cvconfig.h.cmake
modules/ocl/CMakeLists.txt
modules/ocl/include/opencv2/ocl/cl_runtime/cl_runtime.hpp
modules/ocl/src/cl_runtime/cl_runtime.cpp
modules/ocl/src/cl_runtime/generator/generate.sh
modules/ocl/src/cl_runtime/generator/template/cl_runtime_opencl.hpp.in
modules/ocl/src/svm.cpp

index c30845e4f193d79dff0c73bf07e12f7465f28cb6..0679b3f9561d295345c268d8170cf0d3cc7a284a 100644 (file)
@@ -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)
index 7ed54b565dbc76ec6217f7f6c95221493a7afdda..f732546e515f1068e894854983495ab0e8914b19 100644 (file)
@@ -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/opencl.cpp b/cmake/checks/opencl.cpp
new file mode 100644 (file)
index 0000000..a46baf7
--- /dev/null
@@ -0,0 +1,15 @@
+#if defined __APPLE__
+#include <OpenCL/cl.h>
+#else
+#include <CL/cl.h>
+#endif
+
+int main(int argc, char** argv)
+{
+#ifdef CL_VERSION_1_2
+#error OpenCL is valid
+#else
+#error OpenCL check failed
+#endif
+    return 0;
+}
diff --git a/cmake/checks/opencl11.cpp b/cmake/checks/opencl11.cpp
deleted file mode 100644 (file)
index b17889d..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-#if defined __APPLE__
-#include <OpenCL/cl.h>
-#else
-#include <CL/cl.h>
-#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/checks/opencl12.cpp b/cmake/checks/opencl12.cpp
deleted file mode 100644 (file)
index 639502e..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-#if defined __APPLE__
-#include <OpenCL/cl.h>
-#else
-#include <CL/cl.h>
-#endif
-
-int main(int argc, char** argv)
-{
-#ifdef CL_VERSION_1_2
-#else
-#error OpenCL 1.2 not found
-#endif
-    return 0;
-}
index 14eb519d01af0201ea13228ad84647424fb83ef4..88c307dd983cb4b9131ae1063e13386f7a0cec90 100644 (file)
 
 /* OpenCL Support */
 #cmakedefine HAVE_OPENCL
-#cmakedefine HAVE_OPENCL11
-#cmakedefine HAVE_OPENCL12
+#cmakedefine HAVE_OPENCL_STATIC
 
 /* OpenEXR codec */
 #cmakedefine HAVE_OPENEXR
index 21e0b30858ab2ab357c1f4c9489d1f89b7dd34f8..a35aea0e2de1d9f4f0d0ee8f2e8c071af836455e 100644 (file)
@@ -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)
index 3e62edec92add80668788be64b761c24b44bdd23..86e7ebcc3938c15a65e9ca8faaefe9d5f260174a 100644 (file)
@@ -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 <OpenCL/cl.h>
 #else
-#error Invalid OpenCL configuration
+#include <CL/cl.h>
 #endif
 
-#endif
+#else // HAVE_OPENCL_STATIC
+
+#include "cl_runtime_opencl.hpp"
+
+#endif // HAVE_OPENCL_STATIC
+
+#endif // HAVE_OPENCL
 
 #endif // __OPENCV_OCL_CL_RUNTIME_HPP__
index c237afe74c486fdd951ce14a533de3637df2cc63..a0d967c0b94bc0d20566b33050ce302183e7d589 100644 (file)
@@ -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
index 5be039dfef7a4831096e469acae3ab12cefccae9..bc2d8d0fb7ca87f2c85eae9c247271cf824f6577 100644 (file)
@@ -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"
index 0079cb696d8556a88e577c5620dc496a29fd0f20..86690af8681cef3b0db9fdc7dac6d2019c323c82 100644 (file)
@@ -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 <OpenCL/cl.h>
-#else
-
 @CL_REMAP_ORIGIN@
 
 #if defined __APPLE__
@@ -27,8 +21,4 @@
 
 @CL_FN_DECLARATIONS@
 
-#endif
-
-#endif
-
 #endif // __OPENCV_OCL_CL_RUNTIME_OPENCL_HPP__
index ca81128ed7f9ec3143f81ec479d768c185d73c21..9239ddfac855879583ef2cfdbe53c82fef7a856d 100644 (file)
@@ -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