Skip to content

Commit bac1992

Browse files
authored
readme : alternative way to build for Android with CLBlast. (ggml-org#1828)
1 parent b4c6f46 commit bac1992

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

README.md

+41
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,7 @@ And after 4.45 hours, you will have the final perplexity.
616616
617617
### Android
618618
619+
#### Building the Project using Android NDK
619620
You can easily run `llama.cpp` on Android device with [termux](https://termux.dev/).
620621
First, obtain the [Android NDK](https://developer.android.com/ndk) and then build with CMake:
621622
```
@@ -630,6 +631,46 @@ Finally, copy the `llama` binary and the model files to your device storage. Her
630631
631632
https://user-images.githubusercontent.com/271616/225014776-1d567049-ad71-4ef2-b050-55b0b3b9274c.mp4
632633
634+
#### Building the Project using Termux (F-Droid)
635+
Termux from F-Droid offers an alternative route to execute the project on an Android device. This method empowers you to construct the project right from within the terminal, negating the requirement for a rooted device or SD Card.
636+
637+
Outlined below are the directives for installing the project using OpenBLAS and CLBlast. This combination is specifically designed to deliver peak performance on recent devices that feature a GPU.
638+
639+
If you opt to utilize OpenBLAS, you'll need to install the corresponding package.
640+
```
641+
apt install libopenblas
642+
```
643+
644+
Subsequently, if you decide to incorporate CLBlast, you'll first need to install the requisite OpenCL packages:
645+
```
646+
apt install ocl-icd opencl-headers opencl-clhpp clinfo
647+
```
648+
649+
In order to compile CLBlast, you'll need to first clone the respective Git repository, which can be found at this URL: https://github.com/CNugteren/CLBlast. Alongside this, clone this repository into your home directory. Once this is done, navigate to the CLBlast folder and execute the commands detailed below:
650+
```
651+
cmake .
652+
make
653+
cp libclblast.so* $PREFIX/lib
654+
cp ./include/clblast.h ../llama.cpp
655+
```
656+
657+
Following the previous steps, navigate to the LlamaCpp directory. To compile it with OpenBLAS and CLBlast, execute the command provided below:
658+
```
659+
cp /data/data/com.termux/files/usr/include/openblas/cblas.h .
660+
cp /data/data/com.termux/files/usr/include/openblas/openblas_config.h .
661+
make LLAMA_CLBLAST=1 //(sometimes you need to run this command twice)
662+
```
663+
664+
Upon completion of the aforementioned steps, you will have successfully compiled the project. To run it using CLBlast, a slight adjustment is required: a command must be issued to direct the operations towards your device's physical GPU, rather than the virtual one. The necessary command is detailed below:
665+
```
666+
GGML_OPENCL_PLATFORM=0
667+
GGML_OPENCL_DEVICE=0
668+
export LD_LIBRARY_PATH=/system/vendor/lib64:$LD_LIBRARY_PATH
669+
./main (...)
670+
```
671+
672+
For easy and swift re-execution, consider documenting this final part in a .sh script file. This will enable you to rerun the process with minimal hassle.
673+
633674
### Docker
634675
635676
#### Prerequisites

0 commit comments

Comments
 (0)