mirror of
https://github.com/ggml-org/whisper.cpp.git
synced 2026-10-22 03:48:19 +02:00
ggml-zendnn: update code for latest ZenDNN API (llama/19923)
- adapt ggml-zendnn.cpp to the new lowoha::matmul interface - update the ZenDNN git tag in CMake to the latest release (ZenDNN‑2026‑WW08) - add static lib support in CMake
This commit is contained in:
committed by
Georgi Gerganov
parent
316d921c1a
commit
9c1fd5cc6e
@@ -1,12 +1,19 @@
|
|||||||
ggml_add_backend_library(ggml-zendnn
|
ggml_add_backend_library(ggml-zendnn
|
||||||
ggml-zendnn.cpp)
|
ggml-zendnn.cpp)
|
||||||
|
|
||||||
# Get ZenDNN path
|
|
||||||
if (NOT DEFINED ZENDNN_ROOT OR ZENDNN_ROOT STREQUAL "")
|
if (NOT DEFINED ZENDNN_ROOT OR ZENDNN_ROOT STREQUAL "")
|
||||||
set(ZENDNN_ROOT "$ENV{ZENDNN_ROOT}")
|
set(ZENDNN_ROOT "$ENV{ZENDNN_ROOT}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Check if path is still empty or OFF
|
if (BUILD_SHARED_LIBS)
|
||||||
|
set(ZENDNN_SHARED_LIB ON)
|
||||||
|
set(ZENDNN_ARCHIVE_LIB OFF)
|
||||||
|
else()
|
||||||
|
set(ZENDNN_SHARED_LIB OFF)
|
||||||
|
set(ZENDNN_ARCHIVE_LIB ON)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Download and build ZenDNN if not provided
|
||||||
if (NOT ZENDNN_ROOT OR ZENDNN_ROOT STREQUAL "" OR ZENDNN_ROOT STREQUAL "OFF")
|
if (NOT ZENDNN_ROOT OR ZENDNN_ROOT STREQUAL "" OR ZENDNN_ROOT STREQUAL "OFF")
|
||||||
message(STATUS "ZENDNN_ROOT not set. Automatically downloading and building ZenDNN...")
|
message(STATUS "ZENDNN_ROOT not set. Automatically downloading and building ZenDNN...")
|
||||||
message(STATUS "This will take several minutes on first build...")
|
message(STATUS "This will take several minutes on first build...")
|
||||||
@@ -21,7 +28,7 @@ if (NOT ZENDNN_ROOT OR ZENDNN_ROOT STREQUAL "" OR ZENDNN_ROOT STREQUAL "OFF")
|
|||||||
ExternalProject_Add(
|
ExternalProject_Add(
|
||||||
zendnn
|
zendnn
|
||||||
GIT_REPOSITORY https://github.com/amd/ZenDNN.git
|
GIT_REPOSITORY https://github.com/amd/ZenDNN.git
|
||||||
GIT_TAG 21ce8f7879c86bf3637f707fae6f29e0951db5fe
|
GIT_TAG a18adf8c605fb5f5e52cefd7eda08a7b18febbaf # ZenDNN-2026-WW08
|
||||||
PREFIX ${ZENDNN_PREFIX}
|
PREFIX ${ZENDNN_PREFIX}
|
||||||
SOURCE_DIR ${ZENDNN_SOURCE_DIR}
|
SOURCE_DIR ${ZENDNN_SOURCE_DIR}
|
||||||
BINARY_DIR ${ZENDNN_BUILD_DIR}
|
BINARY_DIR ${ZENDNN_BUILD_DIR}
|
||||||
@@ -32,7 +39,9 @@ if (NOT ZENDNN_ROOT OR ZENDNN_ROOT STREQUAL "" OR ZENDNN_ROOT STREQUAL "OFF")
|
|||||||
-DZENDNNL_BUILD_DOXYGEN=OFF
|
-DZENDNNL_BUILD_DOXYGEN=OFF
|
||||||
-DZENDNNL_BUILD_GTEST=OFF
|
-DZENDNNL_BUILD_GTEST=OFF
|
||||||
-DZENDNNL_BUILD_BENCHDNN=OFF
|
-DZENDNNL_BUILD_BENCHDNN=OFF
|
||||||
# Enable ALL matmul algorithm backends
|
-DZENDNNL_DEPENDS_FBGEMM=OFF
|
||||||
|
-DZENDNNL_LIB_BUILD_ARCHIVE=${ZENDNN_ARCHIVE_LIB}
|
||||||
|
-DZENDNNL_LIB_BUILD_SHARED=${ZENDNN_SHARED_LIB}
|
||||||
-DZENDNNL_DEPENDS_AOCLDLP=ON
|
-DZENDNNL_DEPENDS_AOCLDLP=ON
|
||||||
-DZENDNNL_DEPENDS_ONEDNN=ON
|
-DZENDNNL_DEPENDS_ONEDNN=ON
|
||||||
-DZENDNNL_DEPENDS_LIBXSMM=ON
|
-DZENDNNL_DEPENDS_LIBXSMM=ON
|
||||||
@@ -45,47 +54,37 @@ if (NOT ZENDNN_ROOT OR ZENDNN_ROOT STREQUAL "" OR ZENDNN_ROOT STREQUAL "OFF")
|
|||||||
LOG_INSTALL ON
|
LOG_INSTALL ON
|
||||||
)
|
)
|
||||||
|
|
||||||
# Add dependency so ZenDNN builds before our library
|
|
||||||
add_dependencies(ggml-zendnn zendnn)
|
add_dependencies(ggml-zendnn zendnn)
|
||||||
|
|
||||||
# Set ZENDNN_ROOT to the installation directory
|
|
||||||
set(ZENDNN_ROOT ${ZENDNN_INSTALL_DIR})
|
set(ZENDNN_ROOT ${ZENDNN_INSTALL_DIR})
|
||||||
|
|
||||||
message(STATUS "ZenDNN will be built to: ${ZENDNN_ROOT}")
|
message(STATUS "ZenDNN will be built to: ${ZENDNN_ROOT}")
|
||||||
else()
|
else()
|
||||||
message(STATUS "Using custom ZenDNN installation at: ${ZENDNN_ROOT}")
|
message(STATUS "Using custom ZenDNN installation at: ${ZENDNN_ROOT}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# ZenDNN headers + libs
|
|
||||||
target_include_directories(ggml-zendnn PRIVATE
|
target_include_directories(ggml-zendnn PRIVATE
|
||||||
${ZENDNN_ROOT}/zendnnl/include
|
${ZENDNN_ROOT}/zendnnl/include
|
||||||
${ZENDNN_ROOT}/deps/aocldlp/include
|
|
||||||
${ZENDNN_ROOT}/deps/aoclutils/include
|
|
||||||
${ZENDNN_ROOT}/deps/json/include
|
${ZENDNN_ROOT}/deps/json/include
|
||||||
${ZENDNN_ROOT}/deps/libxsmm/include
|
${ZENDNN_ROOT}/deps/aoclutils/include
|
||||||
|
${ZENDNN_ROOT}/deps/aocldlp/include
|
||||||
${ZENDNN_ROOT}/deps/onednn/include
|
${ZENDNN_ROOT}/deps/onednn/include
|
||||||
)
|
${ZENDNN_ROOT}/deps/libxsmm/include)
|
||||||
|
|
||||||
target_link_directories(ggml-zendnn PRIVATE
|
if (ZENDNN_SHARED_LIB)
|
||||||
${ZENDNN_ROOT}/zendnnl/lib
|
target_link_directories(ggml-zendnn PRIVATE ${ZENDNN_ROOT}/zendnnl/lib)
|
||||||
${ZENDNN_ROOT}/deps/aocldlp/lib
|
target_link_libraries(ggml-zendnn PRIVATE zendnnl)
|
||||||
${ZENDNN_ROOT}/deps/aoclutils/lib
|
elseif (ZENDNN_ARCHIVE_LIB)
|
||||||
${ZENDNN_ROOT}/deps/libxsmm/lib
|
target_link_libraries(ggml-zendnn PRIVATE
|
||||||
${ZENDNN_ROOT}/deps/onednn/lib
|
${ZENDNN_ROOT}/zendnnl/lib/libzendnnl_archive.a
|
||||||
)
|
${ZENDNN_ROOT}/deps/aoclutils/${CMAKE_INSTALL_LIBDIR}/libaoclutils.a
|
||||||
|
${ZENDNN_ROOT}/deps/aoclutils/${CMAKE_INSTALL_LIBDIR}/libau_cpuid.a
|
||||||
|
${ZENDNN_ROOT}/deps/aocldlp/lib/libaocl-dlp.a
|
||||||
|
${ZENDNN_ROOT}/deps/onednn/${CMAKE_INSTALL_LIBDIR}/libdnnl.a
|
||||||
|
${ZENDNN_ROOT}/deps/libxsmm/lib/libxsmm.a
|
||||||
|
${ZENDNN_ROOT}/deps/libxsmm/lib/libxsmmext.a
|
||||||
|
${ZENDNN_ROOT}/deps/libxsmm/lib/libxsmmnoblas.a)
|
||||||
|
endif()
|
||||||
|
|
||||||
target_link_libraries(ggml-zendnn PRIVATE
|
target_link_libraries(ggml-zendnn PRIVATE m pthread)
|
||||||
zendnnl_archive # ZenDNN main
|
|
||||||
aocl-dlp # AOCL libraries
|
|
||||||
aoclutils
|
|
||||||
au_cpuid
|
|
||||||
dnnl # OneDNN
|
|
||||||
xsmm # libxsmm small matrix math
|
|
||||||
xsmmext
|
|
||||||
xsmmnoblas
|
|
||||||
m
|
|
||||||
pthread
|
|
||||||
)
|
|
||||||
|
|
||||||
if (GGML_OPENMP)
|
if (GGML_OPENMP)
|
||||||
target_link_libraries(ggml-zendnn PRIVATE OpenMP::OpenMP_CXX)
|
target_link_libraries(ggml-zendnn PRIVATE OpenMP::OpenMP_CXX)
|
||||||
|
|||||||
@@ -41,13 +41,13 @@ static bool ggml_zendnn_matmul(ggml_backend_zendnn_context * ctx, int64_t m, int
|
|||||||
const TA * A, int64_t lda, const TB * B, int64_t ldb, TC * C,
|
const TA * A, int64_t lda, const TB * B, int64_t ldb, TC * C,
|
||||||
int64_t ldc) {
|
int64_t ldc) {
|
||||||
|
|
||||||
zendnnl::lowoha::lowoha_params params;
|
zendnnl::lowoha::matmul::matmul_params params;
|
||||||
params.dtypes.src = ggml_to_zendnn_type<TB>();
|
params.dtypes.src = ggml_to_zendnn_type<TB>();
|
||||||
params.dtypes.wei = ggml_to_zendnn_type<TA>();
|
params.dtypes.wei = ggml_to_zendnn_type<TA>();
|
||||||
params.dtypes.dst = ggml_to_zendnn_type<TC>();
|
params.dtypes.dst = ggml_to_zendnn_type<TC>();
|
||||||
params.num_threads = ctx->n_threads;
|
params.num_threads = ctx->n_threads;
|
||||||
|
|
||||||
zendnnl::lowoha::status_t status = zendnnl::lowoha::matmul_direct(
|
zendnnl::error_handling::status_t status = zendnnl::lowoha::matmul::matmul_direct(
|
||||||
'r', false, true, // row-major, don't transpose B, transpose A (because it's column-major)
|
'r', false, true, // row-major, don't transpose B, transpose A (because it's column-major)
|
||||||
n, // M: rows of B and C
|
n, // M: rows of B and C
|
||||||
m, // N: cols of A^T and C
|
m, // N: cols of A^T and C
|
||||||
@@ -63,7 +63,7 @@ static bool ggml_zendnn_matmul(ggml_backend_zendnn_context * ctx, int64_t m, int
|
|||||||
params // params
|
params // params
|
||||||
);
|
);
|
||||||
|
|
||||||
if (status != zendnnl::lowoha::status_t::success) {
|
if (status != zendnnl::error_handling::status_t::success) {
|
||||||
GGML_LOG_ERROR("%s, ZenDNN matmul failed: status=%d\n", __func__, static_cast<int>(status));
|
GGML_LOG_ERROR("%s, ZenDNN matmul failed: status=%d\n", __func__, static_cast<int>(status));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user