Skip to content

Commit 244979b

Browse files
committed
ggml-zendnn : address ZenDNN backend review fixes and suggestions
1 parent 7db9002 commit 244979b

File tree

6 files changed

+43
-33
lines changed

6 files changed

+43
-33
lines changed

docs/backend/ZenDNN.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# llama.cpp for AMD ZenDNN
22

3+
> **Note:** ZenDNN is **not** the same as zDNN.
4+
> - **ZenDNN** (this page): AMD's deep learning library for AMD EPYC CPUs
5+
> - **zDNN**: IBM's library for IBM Z mainframe processors ([see zDNN documentation](zDNN.md))
6+
37
- [Background](#background)
48
- [OS](#os)
59
- [Hardware](#hardware)
@@ -115,12 +119,12 @@ Default installation path: `ZenDNN/build/install`
115119

116120
```sh
117121
# Using environment variable
118-
export GGML_ZENDNN_PATH=/path/to/ZenDNN/build/install
122+
export ZENDNN_ROOT=/path/to/ZenDNN/build/install
119123
cmake -B build -DGGML_ZENDNN=ON -DCMAKE_BUILD_TYPE=Release
120124
cmake --build build --config Release -j $(nproc)
121125

122126
# OR specify path directly in CMake
123-
cmake -B build -DGGML_ZENDNN=ON -DGGML_ZENDNN_PATH=/path/to/ZenDNN/build/install -DCMAKE_BUILD_TYPE=Release
127+
cmake -B build -DGGML_ZENDNN=ON -DZENDNN_ROOT=/path/to/ZenDNN/build/install -DCMAKE_BUILD_TYPE=Release
124128
cmake --build build --config Release -j $(nproc)
125129
```
126130

@@ -166,7 +170,7 @@ Access the server at `http://localhost:8080`.
166170
| Name | Value | Function |
167171
|--------------------|---------------------------------------|---------------------------------------------|
168172
| GGML_ZENDNN | ON/OFF | Enable ZenDNN backend support |
169-
| GGML_ZENDNN_PATH | Path to ZenDNN installation | Set ZenDNN installation directory |
173+
| ZENDNN_ROOT | Path to ZenDNN installation | Set ZenDNN installation directory |
170174
| GGML_OPENMP | ON/OFF (recommended: ON) | Enable OpenMP for multi-threading |
171175

172176
### Runtime

docs/backend/zDNN.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# llama.cpp for IBM zDNN Accelerator
22

3+
> **Note:** zDNN is **not** the same as ZenDNN.
4+
> - **zDNN** (this page): IBM's library for IBM Z mainframe processors
5+
> - **ZenDNN**: AMD's deep learning library for AMD EPYC CPUs ([see ZenDNN documentation](ZenDNN.md))
6+
37
## Background
48

59
IBM zDNN (Z Deep Neural Network) is a hardware acceleration library designed specifically to leverage the IBM NNPA (Neural Network Processor Assist) accelerator located within IBM Telum I and II processors. It provides significant performance improvements for neural network inference operations.

docs/build.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ ZenDNN provides optimized deep learning primitives for AMD EPYC™ CPUs. It acce
502502
- Using `CMake` with custom ZenDNN installation:
503503

504504
```bash
505-
cmake -B build -DGGML_ZENDNN=ON -DGGML_ZENDNN_PATH=/path/to/zendnn/install
505+
cmake -B build -DGGML_ZENDNN=ON -DZENDNN_ROOT=/path/to/zendnn/install
506506
cmake --build build --config Release
507507
```
508508

ggml/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ option(GGML_HEXAGON "ggml: enable Hexagon backend"
259259
set (GGML_VULKAN_SHADERS_GEN_TOOLCHAIN "" CACHE FILEPATH "ggml: toolchain file for vulkan-shaders-gen")
260260

261261
option(GGML_ZENDNN "ggml: use ZenDNN" OFF)
262-
option(GGML_ZENDNN_PATH "ggml: path to ZenDNN installation" "")
262+
option(ZENDNN_ROOT "ggml: path to ZenDNN installation" "")
263263

264264
# extra artifacts
265265
option(GGML_BUILD_TESTS "ggml: build tests" ${GGML_STANDALONE})

ggml/src/ggml-zendnn/CMakeLists.txt

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
ggml_add_backend_library(ggml-zendnn
2-
ggml-zendnn.cpp
3-
)
2+
ggml-zendnn.cpp)
43

54
# Get ZenDNN path
6-
if (NOT DEFINED GGML_ZENDNN_PATH OR GGML_ZENDNN_PATH STREQUAL "")
7-
set(GGML_ZENDNN_PATH "$ENV{GGML_ZENDNN_PATH}")
5+
if (NOT DEFINED ZENDNN_ROOT OR ZENDNN_ROOT STREQUAL "")
6+
set(ZENDNN_ROOT "$ENV{ZENDNN_ROOT}")
87
endif()
98

109
# Check if path is still empty or OFF
11-
if (NOT GGML_ZENDNN_PATH OR GGML_ZENDNN_PATH STREQUAL "" OR GGML_ZENDNN_PATH STREQUAL "OFF")
12-
message(STATUS "GGML_ZENDNN_PATH not set. Automatically downloading and building ZenDNN...")
10+
if (NOT ZENDNN_ROOT OR ZENDNN_ROOT STREQUAL "" OR ZENDNN_ROOT STREQUAL "OFF")
11+
message(STATUS "ZENDNN_ROOT not set. Automatically downloading and building ZenDNN...")
1312
message(STATUS "This will take several minutes on first build...")
1413

1514
include(ExternalProject)
@@ -33,6 +32,10 @@ if (NOT GGML_ZENDNN_PATH OR GGML_ZENDNN_PATH STREQUAL "" OR GGML_ZENDNN_PATH STR
3332
-DZENDNNL_BUILD_DOXYGEN=OFF
3433
-DZENDNNL_BUILD_GTEST=OFF
3534
-DZENDNNL_BUILD_BENCHDNN=OFF
35+
# Enable ALL matmul algorithm backends
36+
-DZENDNNL_DEPENDS_AOCLDLP=ON
37+
-DZENDNNL_DEPENDS_ONEDNN=ON
38+
-DZENDNNL_DEPENDS_LIBXSMM=ON
3639
BUILD_COMMAND ${CMAKE_COMMAND} --build ${ZENDNN_BUILD_DIR} --target zendnnl
3740
INSTALL_COMMAND ${CMAKE_COMMAND} --build ${ZENDNN_BUILD_DIR} --target install
3841
BUILD_ALWAYS OFF
@@ -45,41 +48,43 @@ if (NOT GGML_ZENDNN_PATH OR GGML_ZENDNN_PATH STREQUAL "" OR GGML_ZENDNN_PATH STR
4548
# Add dependency so ZenDNN builds before our library
4649
add_dependencies(ggml-zendnn zendnn)
4750

48-
# Set GGML_ZENDNN_PATH to the installation directory
49-
set(GGML_ZENDNN_PATH ${ZENDNN_INSTALL_DIR})
51+
# Set ZENDNN_ROOT to the installation directory
52+
set(ZENDNN_ROOT ${ZENDNN_INSTALL_DIR})
5053

51-
message(STATUS "ZenDNN will be built to: ${GGML_ZENDNN_PATH}")
54+
message(STATUS "ZenDNN will be built to: ${ZENDNN_ROOT}")
5255
else()
53-
message(STATUS "Using custom ZenDNN installation at: ${GGML_ZENDNN_PATH}")
56+
message(STATUS "Using custom ZenDNN installation at: ${ZENDNN_ROOT}")
5457
endif()
5558

5659
# ZenDNN headers + libs
5760
target_include_directories(ggml-zendnn PRIVATE
58-
${GGML_ZENDNN_PATH}/zendnnl/include
59-
${GGML_ZENDNN_PATH}/deps/aocldlp/include
60-
${GGML_ZENDNN_PATH}/deps/aoclutils/include
61-
${GGML_ZENDNN_PATH}/deps/json/include
62-
${GGML_ZENDNN_PATH}/deps/libxsmm/include
61+
${ZENDNN_ROOT}/zendnnl/include
62+
${ZENDNN_ROOT}/deps/aocldlp/include
63+
${ZENDNN_ROOT}/deps/aoclutils/include
64+
${ZENDNN_ROOT}/deps/json/include
65+
${ZENDNN_ROOT}/deps/libxsmm/include
66+
${ZENDNN_ROOT}/deps/onednn/include
6367
)
6468

6569
target_link_directories(ggml-zendnn PRIVATE
66-
${GGML_ZENDNN_PATH}/zendnnl/lib
67-
${GGML_ZENDNN_PATH}/deps/aocldlp/lib
68-
${GGML_ZENDNN_PATH}/deps/aoclutils/lib
69-
${GGML_ZENDNN_PATH}/deps/libxsmm/lib
70+
${ZENDNN_ROOT}/zendnnl/lib
71+
${ZENDNN_ROOT}/deps/aocldlp/lib
72+
${ZENDNN_ROOT}/deps/aoclutils/lib
73+
${ZENDNN_ROOT}/deps/libxsmm/lib
74+
${ZENDNN_ROOT}/deps/onednn/lib
7075
)
7176

7277
target_link_libraries(ggml-zendnn PRIVATE
7378
zendnnl_archive # ZenDNN main
7479
aocl-dlp # AOCL libraries
7580
aoclutils
7681
au_cpuid
82+
dnnl # OneDNN
7783
xsmm # libxsmm small matrix math
7884
xsmmext
7985
xsmmnoblas
80-
xsmmf
81-
m # System math
82-
pthread # Threading support
86+
m
87+
pthread
8388
)
8489

8590
if (GGML_OPENMP)

ggml/src/ggml-zendnn/ggml-zendnn.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ static void ggml_zendnn_compute_forward_mul_mat(
122122

123123
GGML_TENSOR_BINARY_OP_LOCALS
124124

125-
enum ggml_type const vec_dot_type = ggml_get_type_traits_cpu(src0->type)->vec_dot_type;
125+
ggml_type const vec_dot_type = ggml_get_type_traits_cpu(src0->type)->vec_dot_type;
126126
ggml_from_float_t const from_float = ggml_get_type_traits_cpu(vec_dot_type)->from_float;
127127

128128
GGML_ASSERT(ne0 == ne01);
@@ -205,7 +205,7 @@ static void ggml_backend_zendnn_free(ggml_backend_t backend) {
205205
delete backend;
206206
}
207207

208-
static enum ggml_status ggml_backend_zendnn_graph_compute(ggml_backend_t backend, ggml_cgraph * cgraph) {
208+
static ggml_status ggml_backend_zendnn_graph_compute(ggml_backend_t backend, ggml_cgraph * cgraph) {
209209
ggml_backend_zendnn_context * ctx = (ggml_backend_zendnn_context *)backend->context;
210210

211211
for (int i = 0; i < cgraph->n_nodes; i++) {
@@ -250,7 +250,7 @@ static struct ggml_backend_i ggml_backend_zendnn_i = {
250250
};
251251

252252
static ggml_guid_t ggml_backend_zendnn_guid(void) {
253-
static const char * guid_str = "AMD-ZENDNN-ACCELER";
253+
static const char * guid_str = "AMD-ZENDNN-ACCEL";
254254
return reinterpret_cast<ggml_guid_t>(const_cast<char*>(guid_str));
255255
}
256256

@@ -434,9 +434,6 @@ static ggml_backend_dev_t ggml_backend_zendnn_reg_get_device(ggml_backend_reg_t
434434
};
435435

436436
return &ggml_backend_zendnn_device;
437-
438-
GGML_UNUSED(reg);
439-
GGML_UNUSED(index);
440437
}
441438

442439
static void * ggml_backend_zendnn_get_proc_address(ggml_backend_reg_t reg, const char * name) {

0 commit comments

Comments
 (0)