Felipe97/llama-cpp-compiled
01.1k
1# Snapdragon-based Linux devices2 3The cross-compilation is performed using the Snapdragon Linux Docker toolchain image (see4[github.com/snapdragon-toolchain](https://github.com/snapdragon-toolchain)):5 6* **Linux toolchain**: `ghcr.io/snapdragon-toolchain/arm64-linux:v0.7`7 8The unified build utility (`scripts/snapdragon/build.py`) automatically pulls9and orchestrates this container to perform target compilation. You only need to10ensure that Docker is running on your host machine.11 12 13## How to Build14 15### Using build.py script (Recommended)16 17The easiest way to build llama.cpp is by using the `scripts/snapdragon/build.py` script. It automatically copies the CMake presets,18launches the correct compilation Docker container, builds the libraries and tools,19installs them, and optionally pushes them to your target device.20 21Build and deploy for a Linux target (using SSH deployment alias `lnx` or `linux`):22```23$ ./scripts/snapdragon/build.py --target lnx:user@host --push24```25 26### Manual CMake Build27 28Alternatively, you can build llama.cpp manually by entering the cross-compilation Docker container and running the CMake commands:29 30```bash31# Start the cross-compilation container manually:32~/src/llama.cpp$ docker run -it --rm -u $(id -u):$(id -g) --volume $(pwd):/workspace --platform linux/amd64 ghcr.io/snapdragon-toolchain/arm64-linux:v0.733 34# Inside the container, build the project using presets:35[d]/workspace> cp docs/backend/snapdragon/CMakeUserPresets.json .36 37[d]/workspace> cmake --preset arm64-linux-snapdragon-release -B build-snapdragon38 39[d]/workspace> cmake --build build-snapdragon -j $(nproc)40```41 42To generate an installable "package" simply use cmake --install, then zip it:43 44```45[d]/workspace> cmake --install build-snapdragon --prefix pkg-linux46[d]/workspace> zip -r pkg-linux.zip pkg-linux47```48 49## How to Install50 51For this step, you will deploy the built binaries and libraries to the target52Linux device. Transfer `pkg-linux.zip` to the target device, then unzip it53and set up the environment variables:54 55```56$ unzip pkg-linux.zip57$ cd pkg-linux58$ export LD_LIBRARY_PATH=./lib59$ export ADSP_LIBRARY_PATH=./lib60```61 62At this point, you should also download some models onto the device:63 64```65$ wget https://huggingface.co/bartowski/Llama-3.2-3B-Instruct-GGUF/resolve/main/Llama-3.2-3B-Instruct-Q4_0.gguf66```67 68## How to Run69You can run locally on the Snapdragon Linux device:70```71$ ./scripts/snapdragon/run.py --devices HTP0 -- llama-cli -m Llama-3.2-3B-Instruct-Q4_0.gguf -ngl 99 -p "what is the most popular cookie in the world?"72```73 74Or run remotely from your host development machine using the SSH target option:75```76$ ./scripts/snapdragon/run.py --target lnx:user@host --devices HTP0 -- llama-cli -m Llama-3.2-3B-Instruct-Q4_0.gguf -ngl 99 -p "what is the most popular cookie in the world?"77```78 79For multi-NPU systems, you can run a tensor split completion command targeting a remote Linux system:80```81$ ./scripts/snapdragon/run.py --target ubuntu:maxk@192.168.1.87 --device HTP0:0,HTP1:0 -- llama-completion -m models/gemma-2b-it-Q4_0.gguf -f prompts/sample_prompt_1024.txt --jinja -st --split-mode tensor --ctx-size 819282```83 84This translates to the following command being executed remotely via SSH:85```86+ ssh maxk@192.168.1.87 "cd ~/llama.cpp && ulimit -c unlimited && LD_LIBRARY_PATH=./lib ADSP_LIBRARY_PATH=./lib GGML_HEXAGON_DEVICES=HTP0:0,HTP1:0 GGML_HEXAGON_OPPOLL=1 ./bin/llama-completion -m models/gemma-2b-it-Q4_0.gguf -f prompts/sample_prompt_1024.txt --jinja -st --split-mode tensor --ctx-size 8192 -v -n 16 --device HTP0:0,HTP1:0 -ngl 99 --ubatch-size 1024 -fa on -t 6"87```88 89Alternatively, you can run the binary directly on the device:90```91$ ./bin/llama-cli -m Llama-3.2-3B-Instruct-Q4_0.gguf --device HTP0 -ngl 99 -p "what is the most popular cookie in the world?"92```93 94 