Commit fd24ee26a for llama.cpp
commit fd24ee26ade8e39a1722aac1b08976fec29f5e17
Author: Hongqiang Wang <wangh@qti.qualcomm.com>
Date: Mon Nov 23 12:39:04 2026 -0800
opencl: fetch the Adreno binary kernel library at configure time for Windows on Snapdragon (#31759)
* opencl: fetch the Adreno binary kernel library at configure time
Make GGML_OPENCL_USE_ADRENO_BIN_KERNELS an option, default ON, and add
GGML_OPENCL_ADRENO_BIN_KERNELS_FETCH, default ON. On Windows, CMake
downloads the pinned adreno-opencl-kernels release from the Qualcomm
Software Center, verifies its SHA256, and copies the DLL and its license
next to the executables. A failed download is only a warning; the
backend then uses its builtin kernels.
The opencl-adreno release job turns the fetch off, since it ships only
ggml-opencl.dll.
* opencl: fetch the Adreno binary kernel library only on ARM64
The library is built for Windows on ARM64 only.
* opencl: add download timeout and better handle output dir
Assisted-by: Codex
* opencl: add .txt to license file
Assisted-by: Codex
---------
Co-authored-by: Li He <lih@qti.qualcomm.com>
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index c918feb06..11c97ea2c 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -1129,7 +1129,7 @@ jobs:
target: 'ggml-vulkan'
- backend: 'opencl-adreno'
arch: 'arm64'
- defines: '-G "Ninja Multi-Config" -D CMAKE_TOOLCHAIN_FILE=cmake/arm64-windows-llvm.cmake -DCMAKE_PREFIX_PATH="$env:RUNNER_TEMP/opencl-arm64-release" -DGGML_OPENCL=ON -DGGML_OPENCL_USE_ADRENO_KERNELS=ON'
+ defines: '-G "Ninja Multi-Config" -D CMAKE_TOOLCHAIN_FILE=cmake/arm64-windows-llvm.cmake -DCMAKE_PREFIX_PATH="$env:RUNNER_TEMP/opencl-arm64-release" -DGGML_OPENCL=ON -DGGML_OPENCL_USE_ADRENO_KERNELS=ON -DGGML_OPENCL_ADRENO_BIN_KERNELS_FETCH=OFF'
target: 'ggml-opencl'
steps:
diff --git a/docs/backend/OPENCL.md b/docs/backend/OPENCL.md
index 0a9a324fd..c912d331c 100644
--- a/docs/backend/OPENCL.md
+++ b/docs/backend/OPENCL.md
@@ -83,22 +83,29 @@ Since common quantizations are supported now, it is recommanded to download GGUF
A prebuilt binary kernel library has been introduced for Adreno GPUs.
It currently targets X2 GPUs (X2-90, X2-85 and X2-45) found in Snapdragon X2 SoC.
The library currently contains kernels for MUL_MAT_ID with Q4_0, Q4_1, Q4_K, MXFP4.
-The library must be manually downloaded from https://softwarecenter.qualcomm.com/catalog/item/Adreno_Kernel_Library_GGML.
-
-To allow using the kernel library, add `-DGGML_OPENCL_USE_ADRENO_BIN_KERNELS=ON` when configuring with CMake.
-Then, extract `adreno-opencl-kernels.dll` from the zip file downloaded from the above URL and put it alongside the executables.
+The library is published at https://softwarecenter.qualcomm.com/catalog/item/Adreno_Kernel_Library_GGML.
+Its use is subject to the license in the `license.txt` file shipped with it.
+
+The library is enabled by default (`GGML_OPENCL_USE_ADRENO_BIN_KERNELS=ON`).
+On Windows on ARM64, CMake downloads the library version pinned in `ggml/src/ggml-opencl/CMakeLists.txt` during configuration (`GGML_OPENCL_ADRENO_BIN_KERNELS_FETCH=ON`).
+The download is verified against a SHA256 hash, and the build copies `adreno-opencl-kernels.dll` and `LICENSE-adreno-opencl-kernels.txt` alongside the executables.
+If the download fails, configuration continues with a warning.
+To skip the download, add `-DGGML_OPENCL_ADRENO_BIN_KERNELS_FETCH=OFF`, then extract `adreno-opencl-kernels.dll` from the zip file downloaded from the above URL and put it alongside the executables yourself.
If kernels compatible with the current GPU are found in the library, they will be loaded and used.
+If the library is missing, the builtin kernels are used.
+Add `-DGGML_OPENCL_USE_ADRENO_BIN_KERNELS=OFF` to disable the library entirely.
## CMake Options
The OpenCL backend has the following CMake options that control the behavior of the backend.
-| CMake options | Default value | Description |
-|:------------------------------------:|:--------------:|:------------------------------------------|
-| `GGML_OPENCL_EMBED_KERNELS` | `ON` | Embed OpenCL kernels into the executable. |
-| `GGML_OPENCL_USE_ADRENO_KERNELS` | `ON` | Use kernels optimized for Adreno. |
-| `GGML_OPENCL_USE_ADRENO_BIN_KERNELS` | `OFF` | Allow using binary kernel lib for Adreno. |
+| CMake options | Default value | Description |
+|:--------------------------------------:|:--------------:|:--------------------------------------------------------|
+| `GGML_OPENCL_EMBED_KERNELS` | `ON` | Embed OpenCL kernels into the executable. |
+| `GGML_OPENCL_USE_ADRENO_KERNELS` | `ON` | Use kernels optimized for Adreno. |
+| `GGML_OPENCL_USE_ADRENO_BIN_KERNELS` | `ON` | Allow using binary kernel lib for Adreno. |
+| `GGML_OPENCL_ADRENO_BIN_KERNELS_FETCH` | `ON` | Download the binary kernel lib for Adreno (Windows ARM64). |
## Decomposed Flash Attention
diff --git a/ggml/CMakeLists.txt b/ggml/CMakeLists.txt
index 03bdb03ed..06278c2d3 100644
--- a/ggml/CMakeLists.txt
+++ b/ggml/CMakeLists.txt
@@ -269,6 +269,8 @@ option(GGML_OPENCL "ggml: use OpenCL"
option(GGML_OPENCL_PROFILING "ggml: use OpenCL profiling (increases overhead)" OFF)
option(GGML_OPENCL_EMBED_KERNELS "ggml: embed kernels" ON)
option(GGML_OPENCL_USE_ADRENO_KERNELS "ggml: use optimized kernels for Adreno" ON)
+option(GGML_OPENCL_USE_ADRENO_BIN_KERNELS "ggml: load the Adreno binary kernel library" ON)
+option(GGML_OPENCL_ADRENO_BIN_KERNELS_FETCH "ggml: fetch the Adreno binary kernel library" ON)
set (GGML_OPENCL_TARGET_VERSION "300" CACHE STRING
"ggml: OpenCL API version to target")
diff --git a/ggml/src/ggml-opencl/CMakeLists.txt b/ggml/src/ggml-opencl/CMakeLists.txt
index d71802c03..1520f8d40 100644
--- a/ggml/src/ggml-opencl/CMakeLists.txt
+++ b/ggml/src/ggml-opencl/CMakeLists.txt
@@ -36,6 +36,78 @@ endif ()
if (GGML_OPENCL_USE_ADRENO_BIN_KERNELS)
message(STATUS "OpenCL will use precompiled binary kernels for Adreno (improved performance on some platforms)")
add_compile_definitions(GGML_OPENCL_USE_ADRENO_BIN_KERNELS)
+ target_link_libraries(${TARGET_NAME} PRIVATE ${CMAKE_DL_LIBS})
+endif ()
+
+# The library is only published for Windows on ARM64. A failed download is not
+# fatal: without the library the backend uses its builtin kernels.
+string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" ADRENO_BIN_KERNELS_SYSTEM_PROCESSOR)
+if (GGML_OPENCL_USE_ADRENO_BIN_KERNELS AND GGML_OPENCL_ADRENO_BIN_KERNELS_FETCH AND
+ WIN32 AND ADRENO_BIN_KERNELS_SYSTEM_PROCESSOR MATCHES "^(aarch64|arm64)$")
+ # Bump the version and hash together when a new library release is published.
+ set(ADRENO_BIN_KERNELS_VERSION "0.0.15")
+ set(ADRENO_BIN_KERNELS_ZIP_SHA256 "325c89a3bce51abe95f40c6bacece005d5ca9cf6166eb5f17d33592cd13ab795")
+ set(ADRENO_BIN_KERNELS_URL "https://softwarecenter.qualcomm.com/api/download/software/tools/Adreno_Kernel_Library_GGML/Windows/${ADRENO_BIN_KERNELS_VERSION}/adreno-opencl-kernels-${ADRENO_BIN_KERNELS_VERSION}.zip")
+
+ set(ADRENO_BIN_KERNELS_ROOT "${CMAKE_BINARY_DIR}/_deps/adreno-opencl-kernels-${ADRENO_BIN_KERNELS_VERSION}")
+ set(ADRENO_BIN_KERNELS_ZIP "${ADRENO_BIN_KERNELS_ROOT}.zip")
+ set(ADRENO_BIN_KERNELS_DLL "${ADRENO_BIN_KERNELS_ROOT}/adreno-opencl-kernels.dll")
+ set(ADRENO_BIN_KERNELS_LICENSE "${ADRENO_BIN_KERNELS_ROOT}/license.txt")
+
+ if (NOT EXISTS "${ADRENO_BIN_KERNELS_DLL}" OR NOT EXISTS "${ADRENO_BIN_KERNELS_LICENSE}")
+ message(STATUS "OpenCL: fetching Adreno binary kernel library ${ADRENO_BIN_KERNELS_VERSION} from Qualcomm; its use is subject to the license in license.txt")
+ file(DOWNLOAD "${ADRENO_BIN_KERNELS_URL}" "${ADRENO_BIN_KERNELS_ZIP}"
+ TLS_VERIFY ON
+ TIMEOUT 120
+ INACTIVITY_TIMEOUT 30
+ STATUS ADRENO_BIN_KERNELS_DOWNLOAD_STATUS)
+ list(GET ADRENO_BIN_KERNELS_DOWNLOAD_STATUS 0 ADRENO_BIN_KERNELS_DOWNLOAD_RESULT)
+ if (ADRENO_BIN_KERNELS_DOWNLOAD_RESULT EQUAL 0)
+ file(SHA256 "${ADRENO_BIN_KERNELS_ZIP}" ADRENO_BIN_KERNELS_ZIP_ACTUAL_SHA256)
+ if (NOT ADRENO_BIN_KERNELS_ZIP_ACTUAL_SHA256 STREQUAL ADRENO_BIN_KERNELS_ZIP_SHA256)
+ file(REMOVE "${ADRENO_BIN_KERNELS_ZIP}")
+ message(FATAL_ERROR "Adreno binary kernel library hash mismatch: expected ${ADRENO_BIN_KERNELS_ZIP_SHA256}, got ${ADRENO_BIN_KERNELS_ZIP_ACTUAL_SHA256}")
+ endif ()
+
+ file(MAKE_DIRECTORY "${ADRENO_BIN_KERNELS_ROOT}")
+ execute_process(
+ COMMAND ${CMAKE_COMMAND} -E tar xf "${ADRENO_BIN_KERNELS_ZIP}"
+ WORKING_DIRECTORY "${ADRENO_BIN_KERNELS_ROOT}"
+ RESULT_VARIABLE ADRENO_BIN_KERNELS_EXTRACT_RESULT)
+ if (NOT ADRENO_BIN_KERNELS_EXTRACT_RESULT EQUAL 0)
+ message(WARNING "Failed to extract the Adreno binary kernel library from ${ADRENO_BIN_KERNELS_ZIP}")
+ endif ()
+ else ()
+ list(GET ADRENO_BIN_KERNELS_DOWNLOAD_STATUS 1 ADRENO_BIN_KERNELS_DOWNLOAD_ERROR)
+ message(WARNING "Failed to download the Adreno binary kernel library (${ADRENO_BIN_KERNELS_DOWNLOAD_ERROR}); "
+ "the builtin kernels will be used. Set GGML_OPENCL_ADRENO_BIN_KERNELS_FETCH=OFF to skip the download.")
+ endif ()
+ file(REMOVE "${ADRENO_BIN_KERNELS_ZIP}")
+ endif ()
+
+ if (EXISTS "${ADRENO_BIN_KERNELS_DLL}" AND EXISTS "${ADRENO_BIN_KERNELS_LICENSE}")
+ if (COMMAND license_add_file)
+ license_add_file("Adreno OpenCL kernels" "${ADRENO_BIN_KERNELS_LICENSE}")
+ endif ()
+
+ set(ADRENO_BIN_KERNELS_OUTPUT_DIR "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
+ if (CMAKE_CONFIGURATION_TYPES AND NOT ADRENO_BIN_KERNELS_OUTPUT_DIR MATCHES "\\$<")
+ string(APPEND ADRENO_BIN_KERNELS_OUTPUT_DIR "/$<CONFIG>")
+ endif ()
+ foreach (CONFIG IN LISTS CMAKE_CONFIGURATION_TYPES CMAKE_BUILD_TYPE)
+ string(TOUPPER "${CONFIG}" CONFIG_UPPER)
+ if (DEFINED CMAKE_RUNTIME_OUTPUT_DIRECTORY_${CONFIG_UPPER})
+ set(ADRENO_BIN_KERNELS_OUTPUT_DIR "$<$<CONFIG:${CONFIG}>:${CMAKE_RUNTIME_OUTPUT_DIRECTORY_${CONFIG_UPPER}}>$<$<NOT:$<CONFIG:${CONFIG}>>:${ADRENO_BIN_KERNELS_OUTPUT_DIR}>")
+ endif ()
+ endforeach ()
+ add_custom_target(ggml-opencl-adreno-bin-kernels ALL
+ COMMAND ${CMAKE_COMMAND} -E make_directory "${ADRENO_BIN_KERNELS_OUTPUT_DIR}"
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different "${ADRENO_BIN_KERNELS_DLL}" "${ADRENO_BIN_KERNELS_OUTPUT_DIR}/adreno-opencl-kernels.dll"
+ COMMAND ${CMAKE_COMMAND} -E copy_if_different "${ADRENO_BIN_KERNELS_LICENSE}" "${ADRENO_BIN_KERNELS_OUTPUT_DIR}/LICENSE-adreno-opencl-kernels.txt")
+ add_dependencies(${TARGET_NAME} ggml-opencl-adreno-bin-kernels)
+ install(FILES "${ADRENO_BIN_KERNELS_DLL}" DESTINATION ${CMAKE_INSTALL_BINDIR})
+ install(FILES "${ADRENO_BIN_KERNELS_LICENSE}" DESTINATION ${CMAKE_INSTALL_BINDIR} RENAME LICENSE-adreno-opencl-kernels.txt)
+ endif ()
endif ()
function(ggml_opencl_add_kernel KNAME)