Skip to content

Commit

Permalink
[OpenCL] Allow upstream to manually set the OpenCL target (#969)
Browse files Browse the repository at this point in the history
- Upstream CI is unable to use find_package() for OpenCL. This
commit allows it to set the target manually and skip the call to
find_package().
- This commit also changes UR to use the OpenCL::OpenCL target.
It provides a simpler alternative to import the opencl library
without having to use add_library().
  • Loading branch information
fabiomestre committed Oct 18, 2023
1 parent f0de2f4 commit 3653e58
Showing 1 changed file with 6 additions and 23 deletions.
29 changes: 6 additions & 23 deletions source/adapters/opencl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,41 +43,24 @@ set_target_properties(${TARGET_NAME} PROPERTIES

find_package(Threads REQUIRED)

if (NOT DEFINED OpenCL_LIBRARY OR NOT DEFINED OpenCL_INCLUDE_DIR)
message(WARNING "OpenCL_LIBRARY and OpenCL_INCLUDE_DIR are not set. Using find_package() to find an OpenCL installation in the system.")
# The OpenCL target can be set manually on upstream cmake to avoid using find_package().
if (NOT UR_OPENCL_ICD_LOADER_LIBRARY)
find_package(OpenCL REQUIRED)
message(STATUS "OpenCL_LIBRARY: ${OpenCL_LIBRARY}")
message(STATUS "OpenCL_INCLUDE_DIR: ${OpenCL_INCLUDE_DIR}")
set(UR_OPENCL_ICD_LOADER_LIBRARY OpenCL::OpenCL)
endif()

message(STATUS "OpenCL_LIBRARY: ${OpenCL_LIBRARY}")
message(STATUS "OpenCL_INCLUDE_DIR: ${OpenCL_INCLUDE_DIR}")

# Suppress a compiler message about undefined CL_TARGET_OPENCL_VERSION.
# Define all symbols up to OpenCL 3.0.
target_compile_definitions(ur_adapter_opencl PRIVATE CL_TARGET_OPENCL_VERSION=300 CL_USE_DEPRECATED_OPENCL_1_2_APIS)

# Make imported library global to use it within the project.
add_library(OpenCL-ICD SHARED IMPORTED GLOBAL)

if (WIN32)
set_target_properties(
OpenCL-ICD PROPERTIES
IMPORTED_IMPLIB ${OpenCL_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${OpenCL_INCLUDE_DIR}
)
else()
set_target_properties(
OpenCL-ICD PROPERTIES
IMPORTED_LOCATION ${OpenCL_LIBRARY}
INTERFACE_INCLUDE_DIRECTORIES ${OpenCL_INCLUDE_DIR}
)
endif()

target_link_libraries(${TARGET_NAME} PRIVATE
${PROJECT_NAME}::headers
${PROJECT_NAME}::common
${PROJECT_NAME}::unified_malloc_framework
Threads::Threads
OpenCL-ICD
${UR_OPENCL_ICD_LOADER_LIBRARY}
)

target_include_directories(${TARGET_NAME} PRIVATE
Expand Down

0 comments on commit 3653e58

Please sign in to comment.