Choose a backend
- CPU: no special drivers or extra build flags needed. Useful as a baseline to compare against GPU or NPU performance.
- GPU (OpenCL): build llama.cpp with the OpenCL backend to offload layers to the Adreno GPU. The same build also runs on CPU by skipping GPU offload.
- NPU (Hexagon HTP): build llama.cpp with the Snapdragon toolchain container to offload layers to the Hexagon HTP device (
HTP0) for the best performance on supported models.
- NPU (Hexagon HTP)
- GPU (OpenCL)
- CPU
Overview
Build llama.cpp for Dragonwing devices with the Hexagon HTP backend, then run GGUF large language models onHTP0.These instructions focus on the Snapdragon and Dragonwing llama.cpp build that exposes the Hexagon HTP device as
HTP0. This is different from the OpenCL GPU workflow in the GPU tab.Prerequisites
Before you begin, make sure you have:- Completed the first time setup for your Dragonwing device:
- Access to the device by SSH, or by a directly connected display, keyboard, and mouse.
- The setup guides linked above include instructions for networking, serial console access, display setup, and SSH access.
- Installed the required Dragonwing software packages on the device:
- Installed Docker on the build host.
- Enough free space for the build output and models. Plan for several GB per model.
libqnn-dev and qnn-tools, that llama.cpp needs for accelerated inference.Prepare the build host
On your build host, clone llama.cpp or update an existing checkout.Build llama.cpp with the Snapdragon toolchain container
The easiest way to build llama.cpp for Dragonwing is to use the Snapdragon ARM64 Linux toolchain container. The container includes the ARM64 cross compiler, CMake, OpenCL SDK, and Hexagon SDK pieces needed by the Snapdragon preset. The Docker command below explicitly requests thelinux/amd64 image.From the root of your llama.cpp checkout, start the container:Rebuild when upstream llama.cpp changes
llama.cpp changes frequently. To rebuild with the latest upstream code, repeat this update and build flow from your host checkout:If you are testing a branch, tag, or local llama.cpp changes, check out that source before running the Docker build command.
Copy the package to the Dragonwing device
Replaceubuntu@DEVICE_IP with your SSH user and target IP address.Make this the default llama.cpp install on the device
The packaged binaries needLD_LIBRARY_PATH and ADSP_LIBRARY_PATH so they can find the packaged llama.cpp and Hexagon backend libraries. The safest way to make this the default install is to move the package into /opt and create wrapper commands in /usr/local/bin.Run the following on the Dragonwing device:llama-cli and llama-server:Download a model
llama.cpp uses models in GGUF format. A small instruct model is a good first test.Create a model directory on the Dragonwing device:Model support and performance vary by architecture, quantization, context length, and llama.cpp commit. If you find a model or quantization that runs particularly well on Dragonwing devices, share it with the community.
Run your first prompt on HTP0
Runllama-cli and offload layers to the Hexagon HTP device:--device HTP0selects the Hexagon HTP backend.-ngl 99asks llama.cpp to offload model layers to the selected device.-mpoints to your GGUF model file.-ppasses a prompt for single prompt testing.
Start llama-server
llama-server exposes a local web UI and an OpenAI compatible API.Start a server on the Dragonwing device:curl:Update the default install after a rebuild
After you rebuild and copy a newpkg-snapdragon.zip to the device, update /opt/llama.cpp-snapdragon:/usr/local/bin do not need to be recreated unless you change the install path.Troubleshooting
error while loading shared librariesIf you run binaries directly from the package directory, set the library paths first:/usr/local/bin/llama-cli.HTP0 does not appearConfirm that the required Dragonwing software packages are installed, especially libqnn-dev and qnn-tools. Then check devices again:/usr/local/bin, update your PATH or call /usr/local/bin/llama-cli explicitly.


