Skip to content

Commit 7d7b1ba

Browse files
authored
opencl: update doc for OpenCL (ggml-org#12702)
* opencl: add OpenCL to build.md * opencl: remove fixed issue/TODO * opencl: add link to OPENCL.md * opencl: update doc - refine tools requirement for Windows 11 arm64
1 parent c262bed commit 7d7b1ba

File tree

2 files changed

+97
-3
lines changed

2 files changed

+97
-3
lines changed

docs/backend/OPENCL.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,13 @@ A Snapdragon X Elite device with Windows 11 Arm64 is used. Make sure the followi
145145
* Clang 19
146146
* Ninja
147147
* Visual Studio 2022
148+
* Powershell 7
148149

149-
Powershell is used for the following instructions.
150+
Visual Studio provides necessary headers and libraries although it is not directly used for building.
151+
Alternatively, Visual Studio Build Tools can be installed instead of the full Visual Studio.
152+
153+
Powershell 7 is used for the following commands.
154+
If an older version of Powershell is used, these commands may not work as they are.
150155

151156
### I. Setup Environment
152157

@@ -196,10 +201,9 @@ ninja
196201

197202
## Known Issues
198203

199-
- Qwen2.5 0.5B model produces gibberish output with Adreno kernels.
204+
- Currently OpenCL backend does not work on Adreno 6xx GPUs.
200205

201206
## TODO
202207

203-
- Fix Qwen2.5 0.5B
204208
- Optimization for Q6_K
205209
- Support and optimization for Q4_K

docs/build.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,96 @@ KleidiAI's microkernels implement optimized tensor operations using Arm CPU feat
456456

457457
Depending on your build target, other higher priority backends may be enabled by default. To ensure the CPU backend is used, you must disable the higher priority backends either at compile time, e.g. -DGGML_METAL=OFF, or during run-time using the command line option `--device none`.
458458

459+
## OpenCL
460+
461+
This provides GPU acceleration through OpenCL on recent Adreno GPU.
462+
More information about OpenCL backend can be found in [OPENCL.md](./backend/OPENCL.md) for more information.
463+
464+
### Android
465+
466+
Assume NDK is available in `$ANDROID_NDK`. First, install OpenCL headers and ICD loader library if not available,
467+
468+
```sh
469+
mkdir -p ~/dev/llm
470+
cd ~/dev/llm
471+
472+
git clone https://github.com/KhronosGroup/OpenCL-Headers && \
473+
cd OpenCL-Headers && \
474+
cp -r CL $ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include
475+
476+
cd ~/dev/llm
477+
478+
git clone https://github.com/KhronosGroup/OpenCL-ICD-Loader && \
479+
cd OpenCL-ICD-Loader && \
480+
mkdir build_ndk && cd build_ndk && \
481+
cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release \
482+
-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake \
483+
-DOPENCL_ICD_LOADER_HEADERS_DIR=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include \
484+
-DANDROID_ABI=arm64-v8a \
485+
-DANDROID_PLATFORM=24 \
486+
-DANDROID_STL=c++_shared && \
487+
ninja && \
488+
cp libOpenCL.so $ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android
489+
```
490+
491+
Then build llama.cpp with OpenCL enabled,
492+
493+
```sh
494+
cd ~/dev/llm
495+
496+
git clone https://github.com/ggml-org/llama.cpp && \
497+
cd llama.cpp && \
498+
mkdir build-android && cd build-android
499+
500+
cmake .. -G Ninja \
501+
-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake \
502+
-DANDROID_ABI=arm64-v8a \
503+
-DANDROID_PLATFORM=android-28 \
504+
-DBUILD_SHARED_LIBS=OFF \
505+
-DGGML_OPENCL=ON
506+
507+
ninja
508+
```
509+
510+
### Windows Arm64
511+
512+
First, install OpenCL headers and ICD loader library if not available,
513+
514+
```powershell
515+
mkdir -p ~/dev/llm
516+
517+
cd ~/dev/llm
518+
git clone https://github.com/KhronosGroup/OpenCL-Headers && cd OpenCL-Headers
519+
mkdir build && cd build
520+
cmake .. -G Ninja `
521+
-DBUILD_TESTING=OFF `
522+
-DOPENCL_HEADERS_BUILD_TESTING=OFF `
523+
-DOPENCL_HEADERS_BUILD_CXX_TESTS=OFF `
524+
-DCMAKE_INSTALL_PREFIX="$HOME/dev/llm/opencl"
525+
cmake --build . --target install
526+
527+
cd ~/dev/llm
528+
git clone https://github.com/KhronosGroup/OpenCL-ICD-Loader && cd OpenCL-ICD-Loader
529+
mkdir build && cd build
530+
cmake .. -G Ninja `
531+
-DCMAKE_BUILD_TYPE=Release `
532+
-DCMAKE_PREFIX_PATH="$HOME/dev/llm/opencl" `
533+
-DCMAKE_INSTALL_PREFIX="$HOME/dev/llm/opencl"
534+
cmake --build . --target install
535+
```
536+
537+
Then build llama.cpp with OpenCL enabled,
538+
539+
```powershell
540+
cmake .. -G Ninja `
541+
-DCMAKE_TOOLCHAIN_FILE="$HOME/dev/llm/llama.cpp/cmake/arm64-windows-llvm.cmake" `
542+
-DCMAKE_BUILD_TYPE=Release `
543+
-DCMAKE_PREFIX_PATH="$HOME/dev/llm/opencl" `
544+
-DBUILD_SHARED_LIBS=OFF `
545+
-DGGML_OPENCL=ON
546+
ninja
547+
```
548+
459549
## Android
460550

461551
To read documentation for how to build on Android, [click here](./android.md)

0 commit comments

Comments
 (0)