Generalized OpenCL handling (#15253)
* Squashed commit of the following: commit 62c992f6a0bc3a2f559faac6912be9c5632a359f Author: Ilya Lavrenov <ilya.lavrenov@intel.com> Date: Sun Jan 22 11:38:18 2023 +0400 Generalized OpenCL handling * Updates * Fixes * Update thirdparty/CMakeLists.txt test * Fixed build with CL/cl2.hpp * Fixes * Fixes * Fixed compilation flags * Fixed build with target OpenCL 120 * Don't use cache
This commit is contained in:
@@ -90,69 +90,62 @@ endif()
|
||||
if(SAMPLES_ENABLE_OPENCL)
|
||||
find_package(OpenCL QUIET)
|
||||
if(NOT OpenCL_FOUND)
|
||||
MESSAGE(WARNING "OpenCL is disabled or not found, ${TARGET_NAME} will be built without OpenCL support. Install OpenCL.")
|
||||
message(WARNING "OpenCL is disabled or not found, ${TARGET_NAME} will be built without OpenCL support. Install OpenCL.")
|
||||
endif()
|
||||
|
||||
set(opencl_header_search_params
|
||||
HINTS
|
||||
${opencl_root_hints}
|
||||
PATHS
|
||||
ENV "PROGRAMFILES(X86)"
|
||||
ENV AMDAPPSDKROOT
|
||||
ENV INTELOCLSDKROOT
|
||||
ENV NVSDKCOMPUTE_ROOT
|
||||
ENV CUDA_PATH
|
||||
ENV ATISTREAMSDKROOT
|
||||
ENV OCL_ROOT
|
||||
PATH_SUFFIXES
|
||||
"include"
|
||||
"OpenCL/common/inc"
|
||||
"AMD APP/include")
|
||||
|
||||
find_path(OpenCL_HPP_INCLUDE_DIR
|
||||
NAMES
|
||||
CL/opencl.hpp OpenCL/opencl.hpp
|
||||
HINTS
|
||||
${opencl_root_hints}
|
||||
ENV "PROGRAMFILES(X86)"
|
||||
ENV AMDAPPSDKROOT
|
||||
ENV INTELOCLSDKROOT
|
||||
ENV NVSDKCOMPUTE_ROOT
|
||||
ENV CUDA_PATH
|
||||
ENV ATISTREAMSDKROOT
|
||||
ENV OCL_ROOT
|
||||
PATH_SUFFIXES
|
||||
include
|
||||
OpenCL/common/inc
|
||||
"AMD APP/include")
|
||||
CL/opencl.hpp OpenCL/opencl.hpp
|
||||
${opencl_header_search_params})
|
||||
|
||||
find_path(CL2_HPP_INCLUDE_DIR
|
||||
NAMES
|
||||
CL/cl2.hpp OpenCL/cl2.hpp
|
||||
HINTS
|
||||
${opencl_root_hints}
|
||||
ENV "PROGRAMFILES(X86)"
|
||||
ENV AMDAPPSDKROOT
|
||||
ENV INTELOCLSDKROOT
|
||||
ENV NVSDKCOMPUTE_ROOT
|
||||
ENV CUDA_PATH
|
||||
ENV ATISTREAMSDKROOT
|
||||
ENV OCL_ROOT
|
||||
PATH_SUFFIXES
|
||||
include
|
||||
OpenCL/common/inc
|
||||
"AMD APP/include")
|
||||
CL/cl2.hpp OpenCL/cl2.hpp
|
||||
${opencl_header_search_params})
|
||||
|
||||
if(OpenCL_FOUND AND (OpenCL_HPP_INCLUDE_DIR OR CL2_HPP_INCLUDE_DIR))
|
||||
set(OpenCL_DEFINITIONS HAVE_GPU_DEVICE_MEM_SUPPORT)
|
||||
|
||||
if(TARGET OpenCL)
|
||||
# Use OpenCL CPP headers from sources if present
|
||||
set(OpenCL_HEADERS ${OPENCL_HEADERS_DIR})
|
||||
set(OpenCL_LIB "OpenCL")
|
||||
elseif(OpenCL_HPP_INCLUDE_DIR OR CL2_HPP_INCLUDE_DIR)
|
||||
# Append OpenCL CPP headers to C headers and use both
|
||||
set(OpenCL_HEADERS ${OpenCL_INCLUDE_DIR})
|
||||
if (OpenCL_HPP_INCLUDE_DIR)
|
||||
list(APPEND ${OpenCL_HEADERS} ${OpenCL_HPP_INCLUDE_DIR})
|
||||
endif()
|
||||
if (CL2_HPP_INCLUDE_DIR)
|
||||
list(APPEND ${OpenCL_HEADERS} ${CL2_HPP_INCLUDE_DIR})
|
||||
endif()
|
||||
set(OpenCL_LIB "OpenCL::OpenCL")
|
||||
else()
|
||||
MESSAGE(WARNING "OpenCL CPP header is not found, ${TARGET_NAME} will be built without OpenCL support. Download it from: https://github.com/KhronosGroup/OpenCL-CLHPP and set -Dopencl_root_hints=[PATH]/OpenCL-CLHPP/include to cmake.")
|
||||
endif()
|
||||
|
||||
if(OpenCL_FOUND AND OpenCL_HEADERS)
|
||||
target_link_libraries(${TARGET_NAME} PRIVATE ${OpenCL_LIB})
|
||||
target_include_directories(${TARGET_NAME} PRIVATE ${OpenCL_HEADERS})
|
||||
target_compile_definitions(${TARGET_NAME} PRIVATE HAVE_GPU_DEVICE_MEM_SUPPORT)
|
||||
if (OpenCL_HPP_INCLUDE_DIR OR OPENCL_HEADERS_DIR)
|
||||
if(OpenCL_HPP_INCLUDE_DIR)
|
||||
list(APPEND OpenCL_HEADERS ${OpenCL_HPP_INCLUDE_DIR})
|
||||
# the macro below is defined when opencl.hpp is found to suppress deprecation message from cl2.hpp
|
||||
target_compile_definitions(${TARGET_NAME} PRIVATE OV_GPU_USE_OPENCL_HPP)
|
||||
list(APPEND OpenCL_DEFINITIONS OV_GPU_USE_OPENCL_HPP)
|
||||
endif()
|
||||
if(CL2_HPP_INCLUDE_DIR)
|
||||
list(APPEND OpenCL_HEADERS ${CL2_HPP_INCLUDE_DIR})
|
||||
endif()
|
||||
|
||||
# cmake cannot set properties for imported targets
|
||||
get_target_property(opencl_target OpenCL::OpenCL ALIASED_TARGET)
|
||||
if(NOT TARGET ${opencl_target})
|
||||
set(opencl_target OpenCL::OpenCL)
|
||||
endif()
|
||||
|
||||
set_property(TARGET ${opencl_target} APPEND PROPERTY
|
||||
INTERFACE_INCLUDE_DIRECTORIES ${OpenCL_HEADERS})
|
||||
set_property(TARGET ${opencl_target} APPEND PROPERTY
|
||||
INTERFACE_COMPILE_DEFINITIONS ${OpenCL_DEFINITIONS})
|
||||
|
||||
target_link_libraries(${TARGET_NAME} PRIVATE OpenCL::OpenCL)
|
||||
else()
|
||||
message(WARNING "OpenCL CPP header is not found, ${TARGET_NAME} will be built without OpenCL support. Download it from: https://github.com/KhronosGroup/OpenCL-CLHPP and set -Dopencl_root_hints=[PATH]/OpenCL-CLHPP/include to cmake.")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user