Skip to content

Commit

Permalink
Add preview of the OpenCL adapter to the adapters branch (oneapi-src#809
Browse files Browse the repository at this point in the history
)
  • Loading branch information
fabiomestre authored and omarahmed1111 committed Oct 23, 2023
1 parent 1a6ea96 commit 1174b36
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 17 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(VAL_USE_LIBBACKTRACE_BACKTRACE "enable libbacktrace validation backtrace for linux" OFF)
option(UR_BUILD_TOOLS "build ur tools" ON)
option(UR_BUILD_ADAPTER_L0 "build level 0 adapter from SYCL" OFF)
option(UR_BUILD_ADAPTER_OPENCL "build opencl 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)

Expand Down
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,23 +113,23 @@ $ make

List of options provided by CMake:

| Name | Description | Values | Default |
| - | - | - | - |
| UR_BUILD_TESTS | Build the tests | ON/OFF | ON |
| UR_BUILD_TOOLS | Build tools | ON/OFF | ON |
| UR_FORMAT_CPP_STYLE | Format code style | ON/OFF | OFF |
| UR_DEVELOPER_MODE | Treat warnings as errors and enables additional checks | ON/OFF | OFF |
| UR_USE_ASAN | Enable AddressSanitizer | ON/OFF | OFF |
| UR_USE_TSAN | Enable ThreadSanitizer | ON/OFF | OFF |
| UR_USE_UBSAN | Enable UndefinedBehavior Sanitizer | ON/OFF | OFF |
| UR_USE_MSAN | Enable MemorySanitizer (clang only) | ON/OFF | OFF |
| UR_ENABLE_TRACING | Enable XPTI-based tracing layer | ON/OFF | OFF |
| UR_CONFORMANCE_TARGET_TRIPLES | SYCL triples to build CTS device binaries for | Comma-separated list | spir64 |
| UR_BUILD_TOOLS | Build tools | ON/OFF | ON |
| UR_BUILD_ADAPTER_L0 | Fetch and use level-zero adapter from SYCL | ON/OFF | OFF |
| UR_BUILD_ADAPTER_CUDA | Fetch and use cuda adapter from SYCL | ON/OFF | OFF |
| UR_BUILD_ADAPTER_HIP | Fetch and use hip adapter from SYCL | ON/OFF | OFF |
| UR_HIP_PLATFORM | Build hip adapter for AMD or NVIDIA platform | AMD/NVIDIA | AMD |
| Name | Description | Values | Default |
|-------------------------------|--------------------------------------------------------|----------------------|---------|
| UR_BUILD_TESTS | Build the tests | ON/OFF | ON |
| UR_BUILD_TOOLS | Build tools | ON/OFF | ON |
| UR_FORMAT_CPP_STYLE | Format code style | ON/OFF | OFF |
| UR_DEVELOPER_MODE | Treat warnings as errors and enables additional checks | ON/OFF | OFF |
| UR_USE_ASAN | Enable AddressSanitizer | ON/OFF | OFF |
| UR_USE_TSAN | Enable ThreadSanitizer | ON/OFF | OFF |
| UR_USE_UBSAN | Enable UndefinedBehavior Sanitizer | ON/OFF | OFF |
| UR_USE_MSAN | Enable MemorySanitizer (clang only) | ON/OFF | OFF |
| UR_ENABLE_TRACING | Enable XPTI-based tracing layer | ON/OFF | OFF |
| UR_CONFORMANCE_TARGET_TRIPLES | SYCL triples to build CTS device binaries for | Comma-separated list | spir64 |
| UR_BUILD_ADAPTER_L0 | Fetch and use level-zero adapter from SYCL | ON/OFF | OFF |
| UR_BUILD_ADAPTER_OPENCL | Fetch and use opencl adapter from SYCL | ON/OFF | OFF |
| UR_BUILD_ADAPTER_CUDA | Fetch and use cuda adapter from SYCL | ON/OFF | OFF |
| UR_BUILD_ADAPTER_HIP | Fetch and use hip adapter from SYCL | ON/OFF | OFF |
| UR_HIP_PLATFORM | Build hip adapter for AMD or NVIDIA platform | AMD/NVIDIA | AMD |

### Additional make targets
To run automated code formatting, configure CMake with `UR_FORMAT_CPP_STYLE` option
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()
86 changes: 86 additions & 0 deletions source/adapters/opencl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# 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
)

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}")

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

# 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 1174b36

Please sign in to comment.