Skip to content

Adding Experimental llama.cpp Hexagon Build#15

Merged
infil00p merged 4 commits into
mainfrom
hexagon-build
Feb 26, 2026
Merged

Adding Experimental llama.cpp Hexagon Build#15
infil00p merged 4 commits into
mainfrom
hexagon-build

Conversation

@infil00p

Copy link
Copy Markdown
Contributor
  • Added Hexagon support to Baseweight Snap using the llama.cpp shared libraries generated by the Hexagon Docker
  • Fixed a bug with stale context when loading new images

infil00p and others added 4 commits February 25, 2026 00:08
Add multi-backend build system (vulkan/hexagon product flavors) that
supports both building Vulkan from source and linking against prebuilt
Snapdragon Docker libraries for Hexagon NPU + OpenCL GPU acceleration.

Key changes:
- CMakeLists.txt: dual backend support with IMPORTED prebuilt libraries
  for hexagon flavor, building common/cpp-httplib from source
- build.gradle.kts: product flavors (vulkan/hexagon) with per-flavor
  ABI filters and jniLibs packaging
- AndroidManifest.xml: uses-native-library for libOpenCL.so and
  libcdsprpc.so (vendor library namespace access), extractNativeLibs
- MTMD_Android.kt: pre-load vendor OpenCL before native library init
- mtmd-android.cpp: set ADSP_LIBRARY_PATH for Hexagon DSP skel lookup
- Update llama.cpp submodule to 35715657c (matches prebuilt binaries)
- Add OpenCL-Headers as submodule for Adreno GPU backend
- Add hexagon build documentation and build script

Tested on OnePlus 13 (Snapdragon 8 Elite, Hexagon v81):
- OpenCL GPU: Adreno 840, all layers offloaded, working
- Hexagon NPU: session opens, model loads, but crashes in
  ggml_hexagon_session::flush() during inference (experimental backend)

Co-Authored-By: Claude Opus 4.6 <[email protected]>
The Hexagon backend crashed with SIGABRT in ggml_hexagon_session::flush()
during the first real llama_decode call. Two differences from the working
llama-mtmd-cli were identified:

1. Missing warmup: the CLI runs a warmup decode (llama_set_warmup + dummy
   tokens) to let backends compile and validate compute graphs before real
   data. Without this, Hexagon hit uninitialized state on first decode.

2. swa_full defaulted to true (llama_context_default_params), while the
   CLI uses false via common_params. This changes KV cache sizing and
   graph structure in ways the experimental Hexagon backend doesn't handle.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Clear n_past, KV cache, and sampler state at the start of each
generation so that taking a new photo starts with a fresh context
instead of accumulating stale embeddings from previous images.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
The addition of product flavors (vulkan/hexagon) renamed the test task.
Hexagon flavor can't build in CI (needs prebuilt Snapdragon libraries).

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@infil00p
infil00p merged commit 8727318 into main Feb 26, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant