char-fork/llama.cpp

git clone https://git.t4t.associates/char-fork/llama.cpp

Hongqiang Wangopencl: cache compiled cl_program binaries on disk (#26050)ed7adbfef

char/aliceai-t5-moe
11.6 KiB313 linesraw

llama.cpp for OpenCL

Background

OpenCL (Open Computing Language) is an open, royalty-free standard for cross-platform, parallel programming of diverse accelerators found in supercomputers, cloud servers, personal computers, mobile devices and embedded platforms. OpenCL specifies a programming language (based on C99) for programming these devices and application programming interfaces (APIs) to control the platform and execute programs on the compute devices. Similar to CUDA, OpenCL has been widely used to program GPUs and is supported by most GPU vendors.

Llama.cpp + OpenCL

The llama.cpp OpenCL backend is designed to enable llama.cpp on Qualcomm Adreno GPU firstly via OpenCL. Thanks to the portabilty of OpenCL, the OpenCL backend can also run on certain Intel GPUs such as those that do not have SYCL support although the performance is not optimal.

OS

OSStatusVerified
AndroidSupportSnapdragon 8 Gen 3, Snapdragon 8 Elite
WindowsSupportWindows 11 Arm64 with Snapdragon X Elite
LinuxSupportUbuntu 22.04 WSL2 with Intel 12700H

Hardware

Adreno GPU

Verified devices

Adreno GPUStatus
Adreno 750 (Snapdragon 8 Gen 3)Support
Adreno 810 (Snapdragon 7s Gen 3)Support
Adreno 830 (Snapdragon 8 Elite)Support
Adreno 840 (Snapdragon 8 Elite Gen 5)Support
Adreno X1-85 (Snapdragon X Elite)Support
Adreno X2-90 (Snapdragon X2 Elite)Support

A6x GPUs with a recent driver and compiler are supported; they are usually found in IoT platforms. However, A6x GPUs in phones are likely not supported due to the outdated driver and compiler.

DataType Supports

DataTypeStatus
Q1_0Support
Q4_0Support
Q4_1Support
Q5_0Support
Q5_1Support
Q8_0Support
Q4_KSupport
Q5_KSupport
Q6_KSupport
MXFP4Support
IQ4_NLSupport

Model Preparation

Since common quantizations are supported now, it is recommanded to download GGUF models directly from Huggingface.

Binary Kernel Library

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. If kernels compatible with the current GPU are found in the library, they will be loaded and used.

CMake Options

The OpenCL backend has the following CMake options that control the behavior of the backend.

CMake optionsDefault valueDescription
GGML_OPENCL_EMBED_KERNELSONEmbed OpenCL kernels into the executable.
GGML_OPENCL_USE_ADRENO_KERNELSONUse kernels optimized for Adreno.
GGML_OPENCL_USE_ADRENO_BIN_KERNELSOFFAllow using binary kernel lib for Adreno.

Program Binary Cache

Compiled cl_program binaries are cached on disk, so subsequent runs skip the expensive compile-from-source step when nothing relevant has changed (kernel source, compile options, device, driver, or platform version).

The cache is controlled with the GGML_OPENCL_KERNEL_CACHE_DIR environment variable:

ValueBehavior
unset / empty / 1 / defaultEnabled in the platform default cache directory: %LOCALAPPDATA%\llama.cpp\cl-cache (Windows), ~/Library/Caches/llama.cpp/cl-cache (macOS), <temp dir>/llama.cpp/cl-cache elsewhere.
0 / off / none / disable(d)Disabled.
any other valueUsed verbatim as the cache directory path.

If the chosen directory cannot be created or used, the cache disables itself for the process and kernels are compiled from source as usual. Set GGML_OPENCL_KERNEL_CACHE_DEBUG=1 to print a HIT/MISS/SAVE trace to stderr.

Android

Ubuntu 22.04 is used for targeting Android. Make sure the following tools are accessible from command line,

  • Git
  • CMake 3.29
  • Ninja
  • Python3

I. Setup Environment

  1. Install NDK
cd ~
wget https://dl.google.com/android/repository/commandlinetools-linux-8512546_latest.zip && \
unzip commandlinetools-linux-8512546_latest.zip && \
mkdir -p ~/android-sdk/cmdline-tools && \
mv cmdline-tools latest && \
mv latest ~/android-sdk/cmdline-tools/ && \
rm -rf commandlinetools-linux-8512546_latest.zip

yes | ~/android-sdk/cmdline-tools/latest/bin/sdkmanager "ndk;26.3.11579264"
  1. Install OpenCL Headers and Library
mkdir -p ~/dev/llm
cd ~/dev/llm

git clone https://github.com/KhronosGroup/OpenCL-Headers && \
cd OpenCL-Headers && \
cp -r CL ~/android-sdk/ndk/26.3.11579264/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include

cd ~/dev/llm

git clone https://github.com/KhronosGroup/OpenCL-ICD-Loader && \
cd OpenCL-ICD-Loader && \
mkdir build_ndk26 && cd build_ndk26 && \
cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_TOOLCHAIN_FILE=$HOME/android-sdk/ndk/26.3.11579264/build/cmake/android.toolchain.cmake \
  -DOPENCL_ICD_LOADER_HEADERS_DIR=$HOME/android-sdk/ndk/26.3.11579264/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include \
  -DANDROID_ABI=arm64-v8a \
  -DANDROID_PLATFORM=24 \
  -DANDROID_STL=c++_shared && \
ninja && \
cp libOpenCL.so ~/android-sdk/ndk/26.3.11579264/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android

II. Build llama.cpp

cd ~/dev/llm

git clone https://github.com/ggml-org/llama.cpp && \
cd llama.cpp && \
mkdir build-android && cd build-android

cmake .. -G Ninja \
  -DCMAKE_TOOLCHAIN_FILE=$HOME/android-sdk/ndk/26.3.11579264/build/cmake/android.toolchain.cmake \
  -DANDROID_ABI=arm64-v8a \
  -DANDROID_PLATFORM=android-28 \
  -DBUILD_SHARED_LIBS=OFF \
  -DGGML_OPENCL=ON

ninja

Windows 11 Arm64

A Snapdragon X Elite device with Windows 11 Arm64 is used. Make sure the following tools are accessible from command line,

  • Git
  • CMake 3.29
  • Clang 19
  • Ninja
  • Visual Studio 2022
  • Powershell 7
  • Python

Visual Studio provides necessary headers and libraries although it is not directly used for building. Alternatively, Visual Studio Build Tools can be installed instead of the full Visual Studio.

Note that building using Visual Studio's cl compiler is not supported. Clang must be used. Clang depends on libraries provided by Visual Studio to work. Therefore, Visual Studio must be installed. Alternatively, Visual Studio Build Tools can be installed instead of the full Visual Studio.

Powershell 7 is used for the following commands. If an older version of Powershell is used, these commands may not work as they are.

I. Setup Environment

  1. Install OpenCL Headers and Library
mkdir -p ~/dev/llm

cd ~/dev/llm
git clone https://github.com/KhronosGroup/OpenCL-Headers && cd OpenCL-Headers
mkdir build && cd build
cmake .. -G Ninja `
  -DBUILD_TESTING=OFF `
  -DOPENCL_HEADERS_BUILD_TESTING=OFF `
  -DOPENCL_HEADERS_BUILD_CXX_TESTS=OFF `
  -DCMAKE_INSTALL_PREFIX="$HOME/dev/llm/opencl"
cmake --build . --target install

cd ~/dev/llm
git clone https://github.com/KhronosGroup/OpenCL-ICD-Loader && cd OpenCL-ICD-Loader
mkdir build && cd build
cmake .. -G Ninja `
  -DCMAKE_BUILD_TYPE=Release `
  -DCMAKE_PREFIX_PATH="$HOME/dev/llm/opencl" `
  -DCMAKE_INSTALL_PREFIX="$HOME/dev/llm/opencl"
cmake --build . --target install

II. Build llama.cpp

mkdir -p ~/dev/llm
cd ~/dev/llm

git clone https://github.com/ggml-org/llama.cpp && cd llama.cpp
mkdir build && cd build

cmake .. -G Ninja `
  -DCMAKE_TOOLCHAIN_FILE="$HOME/dev/llm/llama.cpp/cmake/arm64-windows-llvm.cmake" `
  -DCMAKE_BUILD_TYPE=Release `
  -DCMAKE_PREFIX_PATH="$HOME/dev/llm/opencl" `
  -DBUILD_SHARED_LIBS=OFF `
  -DGGML_OPENCL=ON
ninja

Linux

The two steps just above also apply to Linux. When building for linux, the commands are mostly the same as those for PowerShell on Windows, but in the second step they do not have the -DCMAKE_TOOLCHAIN_FILE parameter, and then in both steps the backticks are replaced with back slashes.

If not installed already, install Git, CMake, Clang, Ninja and Python, then run in the terminal the following:

I. Setup Environment

  1. Install OpenCL Headers and Library
mkdir -p ~/dev/llm

cd ~/dev/llm
git clone https://github.com/KhronosGroup/OpenCL-Headers && cd OpenCL-Headers
mkdir build && cd build
cmake .. -G Ninja \
  -DBUILD_TESTING=OFF \
  -DOPENCL_HEADERS_BUILD_TESTING=OFF \
  -DOPENCL_HEADERS_BUILD_CXX_TESTS=OFF \
  -DCMAKE_INSTALL_PREFIX="$HOME/dev/llm/opencl"
cmake --build . --target install

cd ~/dev/llm
git clone https://github.com/KhronosGroup/OpenCL-ICD-Loader && cd OpenCL-ICD-Loader
mkdir build && cd build
cmake .. -G Ninja \
  -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_PREFIX_PATH="$HOME/dev/llm/opencl" \
  -DCMAKE_INSTALL_PREFIX="$HOME/dev/llm/opencl"
cmake --build . --target install

II. Build llama.cpp

mkdir -p ~/dev/llm
cd ~/dev/llm

git clone https://github.com/ggml-org/llama.cpp && cd llama.cpp
mkdir build && cd build

cmake .. -G Ninja \
  -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_PREFIX_PATH="$HOME/dev/llm/opencl" \
  -DBUILD_SHARED_LIBS=OFF \
  -DGGML_OPENCL=ON
ninja

Known Issues

  • Flash attention does not always improve performance.
  • Currently OpenCL backend works on A6xx GPUs with recent drivers and compilers (usually found in IoT platforms). However, it does not work on A6xx GPUs found in phones with old drivers and compilers.

TODO

  • Improve flash attention
  • Improve OpenCL C kernels performance
1# llama.cpp for OpenCL
2
3- [llama.cpp for OpenCL](#llamacpp-for-opencl)
4  - [Background](#background)
5    - [Llama.cpp + OpenCL](#llamacpp--opencl)
6  - [OS](#os)
7  - [Hardware](#hardware)
8    - [Adreno GPU](#adreno-gpu)
9  - [DataType Supports](#datatype-supports)
10  - [Model Preparation](#model-preparation)
11  - [Binary Kernel Library](#binary-kernel-library)
12  - [CMake Options](#cmake-options)
13  - [Android](#android)
14    - [I. Setup Environment](#i-setup-environment)
15    - [II. Build llama.cpp](#ii-build-llamacpp)
16  - [Windows 11 Arm64](#windows-11-arm64)
17    - [I. Setup Environment](#i-setup-environment-1)
18    - [II. Build llama.cpp](#ii-build-llamacpp-1)
19  - [Linux](#linux)
20    - [I. Setup Environment](#i-setup-environment-2)
21    - [II. Build llama.cpp](#ii-build-llamacpp-2)
22  - [Known Issues](#known-issues)
23  - [TODO](#todo)
24
25## Background
26
27OpenCL (Open Computing Language) is an open, royalty-free standard for cross-platform, parallel programming of diverse accelerators found in supercomputers, cloud servers, personal computers, mobile devices and embedded platforms. OpenCL specifies a programming language (based on C99) for programming these devices and application programming interfaces (APIs) to control the platform and execute programs on the compute devices. Similar to CUDA, OpenCL has been widely used to program GPUs and is supported by most GPU vendors.
28
29### Llama.cpp + OpenCL
30
31The llama.cpp OpenCL backend is designed to enable llama.cpp on **Qualcomm Adreno GPU** firstly via OpenCL. Thanks to the portabilty of OpenCL, the OpenCL backend can also run on certain Intel GPUs such as those that do not have [SYCL](/docs/backend/SYCL.md) support although the performance is not optimal.
32
33## OS
34
35| OS      | Status  | Verified                                       |
36|---------|---------|------------------------------------------------|
37| Android | Support | Snapdragon 8 Gen 3, Snapdragon 8 Elite         |
38| Windows | Support | Windows 11 Arm64 with Snapdragon X Elite       |
39| Linux   | Support | Ubuntu 22.04 WSL2 with Intel 12700H            |
40
41## Hardware
42
43### Adreno GPU
44
45**Verified devices**
46
47| Adreno GPU                            | Status  |
48|:-------------------------------------:|:-------:|
49| Adreno 750 (Snapdragon 8 Gen 3)       | Support |
50| Adreno 810 (Snapdragon 7s Gen 3)      | Support |
51| Adreno 830 (Snapdragon 8 Elite)       | Support |
52| Adreno 840 (Snapdragon 8 Elite Gen 5) | Support |
53| Adreno X1-85 (Snapdragon X Elite)     | Support |
54| Adreno X2-90 (Snapdragon X2 Elite)    | Support |
55
56> A6x GPUs with a recent driver and compiler are supported; they are usually found in IoT platforms.
57However, A6x GPUs in phones are likely not supported due to the outdated driver and compiler.
58
59## DataType Supports
60
61| DataType               | Status                     |
62|:----------------------:|:--------------------------:|
63| Q1_0                   | Support                    |
64| Q4_0                   | Support                    |
65| Q4_1                   | Support                    |
66| Q5_0                   | Support                    |
67| Q5_1                   | Support                    |
68| Q8_0                   | Support                    |
69| Q4_K                   | Support                    |
70| Q5_K                   | Support                    |
71| Q6_K                   | Support                    |
72| MXFP4                  | Support                    |
73| IQ4_NL                 | Support                    |
74
75## Model Preparation
76
77Since common quantizations are supported now, it is recommanded to download GGUF models directly from Huggingface.
78
79## Binary Kernel Library
80
81A prebuilt binary kernel library has been introduced for Adreno GPUs.
82It currently targets X2 GPUs (X2-90, X2-85 and X2-45) found in Snapdragon X2 SoC.
83The library currently contains kernels for MUL_MAT_ID with Q4_0, Q4_1, Q4_K, MXFP4.
84The library must be manually downloaded from https://softwarecenter.qualcomm.com/catalog/item/Adreno_Kernel_Library_GGML.
85
86To allow using the kernel library, add `-DGGML_OPENCL_USE_ADRENO_BIN_KERNELS=ON` when configuring with CMake.
87Then, extract `adreno-opencl-kernels.dll` from the zip file downloaded from the above URL and put it alongside the executables.
88If kernels compatible with the current GPU are found in the library, they will be loaded and used.
89
90
91## CMake Options
92
93The OpenCL backend has the following CMake options that control the behavior of the backend.
94
95| CMake options                        | Default value  | Description                               |
96|:------------------------------------:|:--------------:|:------------------------------------------|
97| `GGML_OPENCL_EMBED_KERNELS`          | `ON`           | Embed OpenCL kernels into the executable. |
98| `GGML_OPENCL_USE_ADRENO_KERNELS`     | `ON`           | Use kernels optimized for Adreno.         |
99| `GGML_OPENCL_USE_ADRENO_BIN_KERNELS` | `OFF`          | Allow using binary kernel lib for Adreno. |
100
101## Program Binary Cache
102
103Compiled `cl_program` binaries are cached on disk, so subsequent runs skip the expensive
104compile-from-source step when nothing relevant has changed (kernel source, compile options,
105device, driver, or platform version).
106
107The cache is controlled with the `GGML_OPENCL_KERNEL_CACHE_DIR` environment variable:
108
109| Value                                  | Behavior                                       |
110|:---------------------------------------|:-----------------------------------------------|
111| unset / empty / `1` / `default`        | Enabled in the platform default cache directory: `%LOCALAPPDATA%\llama.cpp\cl-cache` (Windows), `~/Library/Caches/llama.cpp/cl-cache` (macOS), `<temp dir>/llama.cpp/cl-cache` elsewhere. |
112| `0` / `off` / `none` / `disable(d)`    | Disabled.                                      |
113| any other value                        | Used verbatim as the cache directory path.     |
114
115If the chosen directory cannot be created or used, the cache disables itself for the process
116and kernels are compiled from source as usual. Set `GGML_OPENCL_KERNEL_CACHE_DEBUG=1` to
117print a HIT/MISS/SAVE trace to stderr.
118
119## Android
120
121Ubuntu 22.04 is used for targeting Android. Make sure the following tools are accessible from command line,
122
123* Git
124* CMake 3.29
125* Ninja
126* Python3
127
128### I. Setup Environment
129
1301. **Install NDK**
131
132```sh
133cd ~
134wget https://dl.google.com/android/repository/commandlinetools-linux-8512546_latest.zip && \
135unzip commandlinetools-linux-8512546_latest.zip && \
136mkdir -p ~/android-sdk/cmdline-tools && \
137mv cmdline-tools latest && \
138mv latest ~/android-sdk/cmdline-tools/ && \
139rm -rf commandlinetools-linux-8512546_latest.zip
140
141yes | ~/android-sdk/cmdline-tools/latest/bin/sdkmanager "ndk;26.3.11579264"
142```
143
1442. **Install OpenCL Headers and Library**
145
146```sh
147mkdir -p ~/dev/llm
148cd ~/dev/llm
149
150git clone https://github.com/KhronosGroup/OpenCL-Headers && \
151cd OpenCL-Headers && \
152cp -r CL ~/android-sdk/ndk/26.3.11579264/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include
153
154cd ~/dev/llm
155
156git clone https://github.com/KhronosGroup/OpenCL-ICD-Loader && \
157cd OpenCL-ICD-Loader && \
158mkdir build_ndk26 && cd build_ndk26 && \
159cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release \
160  -DCMAKE_TOOLCHAIN_FILE=$HOME/android-sdk/ndk/26.3.11579264/build/cmake/android.toolchain.cmake \
161  -DOPENCL_ICD_LOADER_HEADERS_DIR=$HOME/android-sdk/ndk/26.3.11579264/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include \
162  -DANDROID_ABI=arm64-v8a \
163  -DANDROID_PLATFORM=24 \
164  -DANDROID_STL=c++_shared && \
165ninja && \
166cp libOpenCL.so ~/android-sdk/ndk/26.3.11579264/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android
167```
168
169### II. Build llama.cpp
170
171```sh
172cd ~/dev/llm
173
174git clone https://github.com/ggml-org/llama.cpp && \
175cd llama.cpp && \
176mkdir build-android && cd build-android
177
178cmake .. -G Ninja \
179  -DCMAKE_TOOLCHAIN_FILE=$HOME/android-sdk/ndk/26.3.11579264/build/cmake/android.toolchain.cmake \
180  -DANDROID_ABI=arm64-v8a \
181  -DANDROID_PLATFORM=android-28 \
182  -DBUILD_SHARED_LIBS=OFF \
183  -DGGML_OPENCL=ON
184
185ninja
186```
187
188## Windows 11 Arm64
189
190A Snapdragon X Elite device with Windows 11 Arm64 is used. Make sure the following tools are accessible from command line,
191
192* Git
193* CMake 3.29
194* Clang 19
195* Ninja
196* Visual Studio 2022
197* Powershell 7
198* Python
199
200Visual Studio provides necessary headers and libraries although it is not directly used for building.
201Alternatively, Visual Studio Build Tools can be installed instead of the full Visual Studio.
202
203> Note that building using Visual Studio's cl compiler is not supported. Clang must be used. Clang depends on libraries provided by Visual Studio to work. Therefore, Visual Studio must be installed. Alternatively, Visual Studio Build Tools can be installed instead of the full Visual Studio.
204
205Powershell 7 is used for the following commands.
206If an older version of Powershell is used, these commands may not work as they are.
207
208### I. Setup Environment
209
2101. **Install OpenCL Headers and Library**
211
212```powershell
213mkdir -p ~/dev/llm
214
215cd ~/dev/llm
216git clone https://github.com/KhronosGroup/OpenCL-Headers && cd OpenCL-Headers
217mkdir build && cd build
218cmake .. -G Ninja `
219  -DBUILD_TESTING=OFF `
220  -DOPENCL_HEADERS_BUILD_TESTING=OFF `
221  -DOPENCL_HEADERS_BUILD_CXX_TESTS=OFF `
222  -DCMAKE_INSTALL_PREFIX="$HOME/dev/llm/opencl"
223cmake --build . --target install
224
225cd ~/dev/llm
226git clone https://github.com/KhronosGroup/OpenCL-ICD-Loader && cd OpenCL-ICD-Loader
227mkdir build && cd build
228cmake .. -G Ninja `
229  -DCMAKE_BUILD_TYPE=Release `
230  -DCMAKE_PREFIX_PATH="$HOME/dev/llm/opencl" `
231  -DCMAKE_INSTALL_PREFIX="$HOME/dev/llm/opencl"
232cmake --build . --target install
233```
234
235### II. Build llama.cpp
236
237```powershell
238
239mkdir -p ~/dev/llm
240cd ~/dev/llm
241
242git clone https://github.com/ggml-org/llama.cpp && cd llama.cpp
243mkdir build && cd build
244
245cmake .. -G Ninja `
246  -DCMAKE_TOOLCHAIN_FILE="$HOME/dev/llm/llama.cpp/cmake/arm64-windows-llvm.cmake" `
247  -DCMAKE_BUILD_TYPE=Release `
248  -DCMAKE_PREFIX_PATH="$HOME/dev/llm/opencl" `
249  -DBUILD_SHARED_LIBS=OFF `
250  -DGGML_OPENCL=ON
251ninja
252```
253
254## Linux
255
256The two steps just above also apply to Linux. When building for linux, the commands are mostly the same as those for PowerShell on Windows, but in the second step they do not have the `-DCMAKE_TOOLCHAIN_FILE` parameter, and then in both steps the backticks are replaced with back slashes.
257
258If not installed already, install Git, CMake, Clang, Ninja and Python, then run in the terminal the following:
259
260### I. Setup Environment
261
2621. **Install OpenCL Headers and Library**
263
264```bash
265mkdir -p ~/dev/llm
266
267cd ~/dev/llm
268git clone https://github.com/KhronosGroup/OpenCL-Headers && cd OpenCL-Headers
269mkdir build && cd build
270cmake .. -G Ninja \
271  -DBUILD_TESTING=OFF \
272  -DOPENCL_HEADERS_BUILD_TESTING=OFF \
273  -DOPENCL_HEADERS_BUILD_CXX_TESTS=OFF \
274  -DCMAKE_INSTALL_PREFIX="$HOME/dev/llm/opencl"
275cmake --build . --target install
276
277cd ~/dev/llm
278git clone https://github.com/KhronosGroup/OpenCL-ICD-Loader && cd OpenCL-ICD-Loader
279mkdir build && cd build
280cmake .. -G Ninja \
281  -DCMAKE_BUILD_TYPE=Release \
282  -DCMAKE_PREFIX_PATH="$HOME/dev/llm/opencl" \
283  -DCMAKE_INSTALL_PREFIX="$HOME/dev/llm/opencl"
284cmake --build . --target install
285```
286
287### II. Build llama.cpp
288
289```bash
290mkdir -p ~/dev/llm
291cd ~/dev/llm
292
293git clone https://github.com/ggml-org/llama.cpp && cd llama.cpp
294mkdir build && cd build
295
296cmake .. -G Ninja \
297  -DCMAKE_BUILD_TYPE=Release \
298  -DCMAKE_PREFIX_PATH="$HOME/dev/llm/opencl" \
299  -DBUILD_SHARED_LIBS=OFF \
300  -DGGML_OPENCL=ON
301ninja
302```
303
304## Known Issues
305
306- Flash attention does not always improve performance.
307- Currently OpenCL backend works on A6xx GPUs with recent drivers and compilers (usually found in IoT platforms).
308  However, it does not work on A6xx GPUs found in phones with old drivers and compilers.
309
310## TODO
311
312- Improve flash attention
313- Improve OpenCL C kernels performance