Skip to content

Commit 40e522e

Browse files
committed
sycl: cleanup oneDNN related code
1 parent 9f7add1 commit 40e522e

File tree

6 files changed

+301
-365
lines changed

6 files changed

+301
-365
lines changed

docs/backend/SYCL.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,15 @@ cmake -B buildWithCublas -DCMAKE_CXX_COMPILER=icpx -DCMAKE_C_COMPILER=icx -DENAB
227227
cmake --build buildWithCublas --config Release
228228
```
229229

230+
**oneDNN**: The current oneDNN releases *(shipped with the oneAPI base-toolkit)* do not include the NVIDIA backend. Therefore, oneDNN must be compiled from source to enable the NVIDIA target:
231+
232+
```sh
233+
git clone https://github.com/oneapi-src/oneDNN.git
234+
cd oneDNN
235+
cmake -GNinja -Bbuild-nvidia -DDNNL_CPU_RUNTIME=DPCPP -DDNNL_GPU_RUNTIME=DPCPP -DDNNL_GPU_VENDOR=NVIDIA -DONEDNN_BUILD_GRAPH=OFF -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx
236+
cmake --build build-nvidia --config Release
237+
```
238+
230239
- **Adding support to AMD GPUs**
231240

232241
**oneAPI Plugin**: In order to enable SYCL support on AMD GPUs, please install the [Codeplay oneAPI Plugin for AMD GPUs](https://developer.codeplay.com/products/oneapi/amd/download). As with Nvidia GPUs, the user should also make sure the plugin version matches the installed base toolkit.
@@ -317,10 +326,10 @@ export CPLUS_INCLUDE_DIR=/path/to/oneMKL/include:$CPLUS_INCLUDE_DIR
317326
GGML_SYCL_DEVICE_ARCH=sm_80 # Example architecture
318327

319328
# Option 1: Use FP32 (recommended for better performance in most cases)
320-
cmake -B build -DGGML_SYCL=ON -DGGML_SYCL_TARGET=NVIDIA -DGGML_SYCL_DEVICE_ARCH=${GGML_SYCL_DEVICE_ARCH} -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx
329+
cmake -B build -DGGML_SYCL=ON -DGGML_SYCL_TARGET=NVIDIA -DGGML_SYCL_DEVICE_ARCH=${GGML_SYCL_DEVICE_ARCH} -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx -DDNNL_DIR=/path/to/oneDNN/build-nvidia/install/lib/cmake/dnnl
321330

322331
# Option 2: Use FP16
323-
cmake -B build -DGGML_SYCL=ON -DGGML_SYCL_TARGET=NVIDIA -DGGML_SYCL_DEVICE_ARCH=${GGML_SYCL_DEVICE_ARCH} -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx -DGGML_SYCL_F16=ON
332+
cmake -B build -DGGML_SYCL=ON -DGGML_SYCL_TARGET=NVIDIA -DGGML_SYCL_DEVICE_ARCH=${GGML_SYCL_DEVICE_ARCH} -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx -DGGML_SYCL_F16=ON -DDNNL_DIR=/path/to/oneDNN/build-nvidia/install/lib/cmake/dnnl
324333

325334
# build all binary
326335
cmake --build build --config Release -j -v

ggml/src/ggml-sycl/CMakeLists.txt

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,26 @@ ggml_add_backend_library(ggml-sycl
2121
../../include/ggml-sycl.h
2222
)
2323

24+
find_package(DNNL)
25+
set(GGML_SYCL_DNNL 0)
26+
if(DNNL_FOUND)
27+
get_target_property(CONFIG DNNL::dnnl IMPORTED_CONFIGURATIONS)
28+
get_target_property(DNNL_LIB DNNL::dnnl IMPORTED_LOCATION_${CONFIG})
29+
message(STATUS "Found oneDNN: ${DNNL_LIB}")
30+
if("${GGML_SYCL_TARGET}" STREQUAL "${DNNL_GPU_VENDOR}")
31+
target_link_libraries(ggml-sycl PRIVATE DNNL::dnnl)
32+
set(GGML_SYCL_DNNL 1)
33+
else()
34+
message(WARNING
35+
"oneDNN must be compiled for the same target as llama.cpp.
36+
llama.cpp: ${GGML_SYCL_TARGET}, oneDNN: ${DNNL_GPU_VENDOR}.
37+
Disabling oneDNN support.")
38+
endif()
39+
else()
40+
message(STATUS "oneDNN not found, disabling oneDNN support")
41+
endif()
42+
target_compile_definitions(ggml-sycl PRIVATE GGML_SYCL_DNNL=${GGML_SYCL_DNNL})
43+
2444
if (GGML_SYCL_F16)
2545
if (GGML_SYCL_TARGET STREQUAL "AMD")
2646
message(WARNING "AMD target does not entirely support FP16 in the SYCL backend.")
@@ -46,18 +66,6 @@ file(GLOB GGML_HEADERS_SYCL "*.hpp")
4666
file(GLOB GGML_SOURCES_SYCL "*.cpp")
4767
target_sources(ggml-sycl PRIVATE ${GGML_HEADERS_SYCL} ${GGML_SOURCES_SYCL})
4868

49-
find_package(DNNL)
50-
message("-- DNNL found:" ${DNNL_FOUND})
51-
52-
if (GGML_SYCL_TARGET STREQUAL "INTEL")
53-
add_compile_definitions(GGML_SYCL_DNNL=${DNNL_FOUND})
54-
else()
55-
add_compile_definitions(GGML_SYCL_DNNL=0)
56-
endif()
57-
58-
if (${DNNL_FOUND} AND GGML_SYCL_TARGET STREQUAL "INTEL")
59-
target_link_libraries(ggml-sycl PRIVATE DNNL::dnnl)
60-
endif()
6169

6270
if (WIN32)
6371
find_package(IntelSYCL REQUIRED)

0 commit comments

Comments
 (0)