Skip to content

Commit 0d1d9c6

Browse files
author
Menooker
authored
Add OpenCL runtime (#191)
This introduces a OCL stream wrapper, and the implementation of gpux dialect's and upstream runtime with OCL. IMEX runtime wrapper If context and device is passed with nullptr, we will return a global stream object. The stream object is responsible for releasing the context. If both are given, we "borrow" the context and we don't release the context at the destructor of the stream object. Upstream runtime wrapper We use the same stream object class as used in IMEX wrapper. In upstream ROCM/Cuda/Sycl wrapper, they use raw queue pointer as the type of queue parameter in mgpu* APIS (like sycl::queue*).
1 parent bee0ddb commit 0d1d9c6

File tree

16 files changed

+540
-24
lines changed

16 files changed

+540
-24
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,15 @@ cmake --build . --target gc-check
5858
Notes:
5959
* `/PATH/TO/llvm-project/llvm-install` should be the install path of LLVM. If you installed LLVM elsewhere by `-DCMAKE_INSTALL_PREFIX` option when building LLVM, you need to change the path in `-DMLIR_DIR` accordingly.
6060
* The cmake option `-DLLVM_EXTERNAL_LIT` is for the tests of this project. It requires the `lit` tool to be installed in the system. You can install it via `pip install lit`. If you don't need to run the tests of this repo, you can omit this option in the command line.
61-
* If GPU components are on (`-DGC_USE_GPU=ON`), make sure the Level-zero runtime is installed in your system. Either install Level-zero runtime via system package managers (e.g. `apt`), or follow the instructions of [IMEX](https://github.com/intel/mlir-extensions).
61+
62+
More notes if GPU components are on (`-DGC_USE_GPU=ON`):
63+
* make sure the OpenCL runtime is installed in your system. You can either
64+
install using OS-provided package (Ubuntu 22.04)
65+
```sh
66+
sudo apt install -y intel-opencl-icd opencl-c-headers
67+
```
68+
Or, download and install package from: https://github.com/intel/compute-runtime/releases
69+
* the LLVM codebase needs to be patched to support XeGPU lowering (from IMEX). Please follow instructions of [IMEX](https://github.com/intel/mlir-extensions) on patching LLVM.
6270

6371
Graph Compiler supports the following build-time options.
6472

cmake/imex.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ get_property(IMEX_INCLUDES GLOBAL PROPERTY IMEX_INCLUDES)
44
if (NOT DEFINED IMEX_INCLUDES)
55
include(functions)
66
set(IMEX_CHECK_LLVM_VERSION ON)
7-
set(IMEX_ENABLE_L0_RUNTIME 1)
7+
set(IMEX_ENABLE_L0_RUNTIME 0)
88
# TODO: Change to main https://github.com/oneapi-src/oneDNN.git when all the
99
# required functionality is merged.
1010
gc_fetch_content(imex 496b240093b5e132b60c5ee69878300fe69be300 https://github.com/Menooker/mlir-extensions
11-
CMAKE_ARGS "-DMLIR_DIR=${MLIR_DIR};-DIMEX_CHECK_LLVM_VERSION=ON;-DIMEX_ENABLE_L0_RUNTIME=1"
11+
CMAKE_ARGS "-DMLIR_DIR=${MLIR_DIR};-DIMEX_CHECK_LLVM_VERSION=ON;-DIMEX_ENABLE_L0_RUNTIME=0"
1212
)
1313

1414
set(IMEX_INCLUDES

include/gc/Transforms/Passes.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def ConvertOneDNNGraphToLinalg : Pass<"convert-onednn-graph-to-linalg"> {
3232
];
3333
}
3434

35-
35+
#ifdef GC_USE_GPU
3636
def LinalgToXeGPU : Pass<"linalg-to-xegpu", "func::FuncOp"> {
3737
let summary = "Convert linalg dialect to XeGPU dialect.";
3838
let description = [{
@@ -57,5 +57,6 @@ def LinalgToXeGPU : Pass<"linalg-to-xegpu", "func::FuncOp"> {
5757
"DPAS register block sizes MxNxK">,
5858
];
5959
}
60+
#endif
6061

6162
#endif // GC_DIALECT_GC_PASSES

lib/gc/CAPI/CMakeLists.txt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1+
set(GC_ALL_LIBS
2+
MLIROneDNNGraph
3+
MLIRCPURuntimeDialect
4+
GCPasses
5+
MLIRCPURuntimeTransforms)
6+
7+
if(GC_USE_GPU)
8+
list(APPEND GC_ALL_LIBS GCGPUPasses)
9+
endif()
10+
111
add_mlir_public_c_api_library(GcCAPI
212
Dialects.cpp
313
Passes.cpp
414
LINK_LIBS PUBLIC
5-
MLIROneDNNGraph
6-
MLIRCPURuntimeDialect
7-
GCPasses
8-
GCGPUPasses
9-
MLIRCPURuntimeTransforms
15+
${GC_ALL_LIBS}
1016
)

lib/gc/ExecutionEngine/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
add_subdirectory(CPURuntime)
2-
add_subdirectory(Driver)
2+
add_subdirectory(Driver)
3+
if(GC_USE_GPU)
4+
add_subdirectory(OpenCLRuntime)
5+
endif()

lib/gc/ExecutionEngine/Driver/CMakeLists.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ else()
2626
)
2727
endif()
2828

29+
set(GC_PASSES GCPasses)
30+
if(GC_USE_GPU)
31+
list(APPEND GC_PASSES GCGPUPasses)
32+
endif()
33+
2934
add_mlir_library(GCJitWrapper
3035
Driver.cpp
3136

@@ -35,8 +40,7 @@ add_mlir_library(GCJitWrapper
3540
LINK_LIBS PUBLIC
3641
${MLIR_LINK_COMPONENTS}
3742
${dialect_libs}
38-
${conversion_libs}
39-
GCPasses
40-
GCGPUPasses
43+
${conversion_libs}
44+
${GC_PASSES}
4145
)
4246

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
find_package(OpenCL REQUIRED)
2+
3+
add_mlir_library(mlir_opencl_runtime
4+
SHARED
5+
OpenCLRuntimeWrappers.cpp
6+
7+
EXCLUDE_FROM_LIBMLIR
8+
)
9+
10+
check_cxx_compiler_flag("-frtti" CXX_HAS_FRTTI_FLAG)
11+
if(NOT CXX_HAS_FRTTI_FLAG)
12+
message(FATAL_ERROR "CXX compiler does not accept flag -frtti")
13+
endif()
14+
target_compile_options (mlir_opencl_runtime PUBLIC -fexceptions -frtti)
15+
16+
target_include_directories(mlir_opencl_runtime PRIVATE
17+
${MLIR_INCLUDE_DIRS}
18+
${OpenCL_INCLUDE_DIRS}
19+
)
20+
21+
message(STATUS "OpenCL Libraries: ${OpenCL_LIBRARIES}")
22+
target_link_libraries(mlir_opencl_runtime PUBLIC ${OpenCL_LIBRARIES})

0 commit comments

Comments
 (0)