Skip to content

Commit

Permalink
Add preview of the OpenCL adapter to the adapters branch
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiomestre committed Aug 18, 2023
1 parent 2b81136 commit 1495efe
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ option(UMF_ENABLE_POOL_TRACKING "Build UMF with pool tracking" OFF)
option(UR_BUILD_ADAPTER_L0 "build level 0 adapter from SYCL" OFF)
option(UR_BUILD_ADAPTER_CUDA "build cuda adapter from SYCL" OFF)
option(UR_BUILD_ADAPTER_HIP "build hip adapter from SYCL" OFF)
option(UR_BUILD_ADAPTER_OPENCL "build opencl adapter from SYCL" OFF)

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
Expand Down
11 changes: 11 additions & 0 deletions source/adapters/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ if(UR_BUILD_ADAPTER_L0 OR UR_BUILD_ADAPTER_CUDA OR UR_BUILD_ADAPTER_HIP)
FetchSource(https://github.com/intel/llvm.git nightly-2023-08-01 "sycl/plugins/unified_runtime/ur" ${SYCL_ADAPTER_DIR})
endif()

# Temporarily fetch the opencl adapter from a fork until the PR has been merged.
if(UR_BUILD_ADAPTER_OPENCL)
# fetch adapter sources from SYCL
set(SYCL_ADAPTER_DIR "${CMAKE_CURRENT_SOURCE_DIR}/external")
FetchSource(https://github.com/fabiomestre/llvm.git opencl_adapter_unofficial "sycl/plugins/unified_runtime/ur" ${SYCL_ADAPTER_DIR})
endif()

if(UR_BUILD_ADAPTER_L0)
add_subdirectory(level_zero)
endif()
Expand All @@ -47,3 +54,7 @@ endif()
if(UR_BUILD_ADAPTER_HIP)
add_subdirectory(hip)
endif()

if(UR_BUILD_ADAPTER_OPENCL)
add_subdirectory(opencl)
endif()
90 changes: 90 additions & 0 deletions source/adapters/opencl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Copyright (C) 2023 Intel Corporation
# Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
# See LICENSE.TXT
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

set(OPENCL_DIR "${SYCL_ADAPTER_DIR}/sycl/plugins/unified_runtime/ur/adapters/opencl" CACHE PATH "OpenCL adapter directory")

set(TARGET_NAME ur_adapter_opencl)

add_ur_adapter(${TARGET_NAME}
SHARED
${OPENCL_DIR}/ur_interface_loader.cpp
${OPENCL_DIR}/adapter.hpp
${OPENCL_DIR}/adapter.cpp
${OPENCL_DIR}/command_buffer.hpp
${OPENCL_DIR}/command_buffer.cpp
${OPENCL_DIR}/common.hpp
${OPENCL_DIR}/common.cpp
${OPENCL_DIR}/context.cpp
${OPENCL_DIR}/context.hpp
${OPENCL_DIR}/device.cpp
${OPENCL_DIR}/device.hpp
${OPENCL_DIR}/enqueue.cpp
${OPENCL_DIR}/event.cpp
${OPENCL_DIR}/image.cpp
${OPENCL_DIR}/kernel.cpp
${OPENCL_DIR}/memory.cpp
${OPENCL_DIR}/platform.cpp
${OPENCL_DIR}/platform.hpp
${OPENCL_DIR}/program.cpp
${OPENCL_DIR}/queue.cpp
${OPENCL_DIR}/sampler.cpp
${OPENCL_DIR}/usm.cpp
${OPENCL_DIR}/usm_p2p.cpp
${OPENCL_DIR}/../../ur.cpp
${OPENCL_DIR}/../../ur.hpp
${OPENCL_DIR}/../../ur.hpp
)

set_target_properties(${TARGET_NAME} PROPERTIES
VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}"
SOVERSION "${PROJECT_VERSION_MAJOR}"
)

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.")
find_package(OpenCL REQUIRED)
endif()

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

if (NOT OpenCL_HEADERS)
FetchContent_Declare(ocl-headers
GIT_REPOSITORY ${OCL_HEADERS_REPO}
GIT_TAG ${OCL_HEADERS_TAG}
)
endif()

# 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
)

target_include_directories(${TARGET_NAME} PRIVATE
${OPENCL_DIR}/../../../
${OpenCL_INCLUDE_DIR}
)

0 comments on commit 1495efe

Please sign in to comment.