Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OpenCL runtime #796

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ include(HandleLLVMOptions)

set(IMEX_INCLUDE_TESTS 1 CACHE BOOL "Include targets for IMEX tests")
set(IMEX_ENABLE_SYCL_RUNTIME 0 CACHE BOOL "Enable the Sycl Runtime")
set(IMEX_ENABLE_OPENCL_RUNTIME 0 CACHE BOOL "Enable the OpenCL Runtime")
set(IMEX_ENABLE_L0_RUNTIME 0 CACHE BOOL "Enable the Level Zero Runtime")
set(IMEX_ENABLE_BENCHMARK 0 CACHE BOOL "Enable the IMEX Benchmark (Depending on SYCL Runtime)")
# Useful when building IMEX as an LLVM external project.
Expand All @@ -192,6 +193,12 @@ else ()
set(IMEX_ENABLE_SYCL_RUNTIME 0)
endif()

if (IMEX_ENABLE_OPENCL_RUNTIME)
set(IMEX_ENABLE_OPENCL_RUNTIME 1)
else ()
set(IMEX_ENABLE_OPENCL_RUNTIME 0)
endif()

if (IMEX_ENABLE_L0_RUNTIME)
set(IMEX_ENABLE_L0_RUNTIME 1)
else ()
Expand Down
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Intel® Extension for MLIR (IMEX) is a collection of MLIR dialects and passes from Intel for supporting MLIR lowering to Intel silicon (CPU, GPU, …). Goal of this project is to support development of MLIR enhancements for upstream contribution, and to provide a sandbox for validation independent of front end frameworks. Current project scope includes:

* Dialects and passes needed to lower and execute MLIR entry dialect (linalg, CFG, and etc) on Intel GPU.
* Wrapper libraries to inteface with level zero runtime and sycl runtime supporting Intel GPU.
* Wrapper libraries to inteface with level zero runtime, sycl runtime and OpenCL runtime supporting Intel GPU.
* Other experimental dialects: NDArray, Dist

## Requirements for building and development
Expand Down Expand Up @@ -44,6 +44,13 @@ cmake --build build --target install
```
* Binary package for system-wide install: https://github.com/oneapi-src/level-zero/releases

#### Getting OpenCL headers and libraries (For OpenCL runtime)
* Install using OS-provided package (Ubuntu 22.04)
```sh
sudo apt install -y intel-opencl-icd opencl-c-headers
```
* Or, download and install package from: https://github.com/intel/compute-runtime/releases

### Example: Setting up requirements using Conda
```sh
conda create -n imex-dev -c intel -c defaults -c conda-forge pip">=21.2.4" pre-commit cmake clang-format lit doxygen
Expand Down Expand Up @@ -79,6 +86,9 @@ cmake -G Ninja -B build -S llvm \
# For GPU support pass thes cmake variables to enable the required runtime libraries
# -DIMEX_ENABLE_L0_RUNTIME=1
# -DIMEX_ENABLE_SYCL_RUNTIME=1
# -DIMEX_ENABLE_OPENCL_RUNTIME=1
# Additional if OpenCL library is not found by CMake
# -DOpenCL_LIBRARY=/PATH_TO/libOpenCL.so.1 ## usually at /usr/lib/x86_64-linux-gnu/libOpenCL.so.1
# Additional if using a non system wide Level Zero Loader built from source
# -DLEVEL_ZERO_DIR=/PATH_TO/level-zero-install

Expand Down Expand Up @@ -107,6 +117,9 @@ cmake -G Ninja -B build -S . \
# For GPU support pass thes cmake variables to enable the required runtime libraries
# -DIMEX_ENABLE_L0_RUNTIME=1
# -DIMEX_ENABLE_SYCL_RUNTIME=1
# -DIMEX_ENABLE_OPENCL_RUNTIME=1
# Additional if OpenCL library is not found by CMake
# -DOpenCL_LIBRARY=/PATH_TO/libOpenCL.so.1 ## usually at /usr/lib/x86_64-linux-gnu/libOpenCL.so.1
# Additional if using a non system wide Level Zero Loader built from source
# -DLEVEL_ZERO_DIR=/PATH_TO/level-zero-install

Expand All @@ -127,6 +140,9 @@ cmake -G Ninja -B build -S . \
# For GPU support pass thes cmake variables to enable the required runtime libraries
# -DIMEX_ENABLE_L0_RUNTIME=1
# -DIMEX_ENABLE_SYCL_RUNTIME=1
# -DIMEX_ENABLE_OPENCL_RUNTIME=1
# Additional if OpenCL library is not found by CMake
# -DOpenCL_LIBRARY=/PATH_TO/libOpenCL.so.1 ## usually at /usr/lib/x86_64-linux-gnu/libOpenCL.so.1
# Additional if using a non system wide Level Zero Loader built from source
# -DLEVEL_ZERO_DIR=/PATH_TO/level-zero-install

Expand Down
4 changes: 4 additions & 0 deletions lib/ExecutionEngine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ if(IMEX_ENABLE_SYCL_RUNTIME)
add_subdirectory(SYCLRUNTIME)
endif()

if(IMEX_ENABLE_OPENCL_RUNTIME)
add_subdirectory(OPENCLRUNTIME)
endif()

add_mlir_library(imex_runner_utils
SHARED
ImexRunnerUtils.cpp
Expand Down
40 changes: 40 additions & 0 deletions lib/ExecutionEngine/OPENCLRUNTIME/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright 2024 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

find_package(OpenCL REQUIRED)

if(NOT OpenCL_FOUND)
message(FATAL_ERROR "OpenCL not found.")
endif()

add_mlir_library(opencl-runtime
SHARED
OpenCLRuntimeWrappers.cpp

EXCLUDE_FROM_LIBMLIR
)

check_cxx_compiler_flag("-frtti" CXX_HAS_FRTTI_FLAG)
if(NOT CXX_HAS_FRTTI_FLAG)
message(FATAL_ERROR "CXX compiler does not accept flag -frtti")
endif()
target_compile_options (opencl-runtime PUBLIC -fexceptions -frtti)

target_include_directories(opencl-runtime PRIVATE
${MLIR_INCLUDE_DIRS}
${OpenCL_INCLUDE_DIRS}
)

message(STATUS "OpenCL Libraries: ${OpenCL_LIBRARIES}")
target_link_libraries(opencl-runtime PRIVATE ${OpenCL_LIBRARIES})
Loading
Loading