Commit 8d1d73a
[BCI] Enable dynamic backend loading for Android (QVAC-19235) (#2326)
* bci-whispercpp: thread backendsDir + Android dynamic-backend loader (QVAC-19235)
PR 1 of 3 for the BCI GPU rollout. Behaviour on every platform is
unchanged today because `bci-whispercpp` still pins
`whisper-cpp@1.8.4.2`, whose port builds ggml with the static-backend
registry (`GGML_BACKEND_DL=OFF`). This PR is the safety net that lets
the follow-up `whisper-cpp@1.8.5` bump (QVAC-19009) flip
`GGML_BACKEND_DL=ON` on Android without reproducing the `SIGABRT` on
model load that hit `transcription-whispercpp` on its PR #2124 -- see
`aiDocs/15-android-mobile-test-crash-fix.md` for the post-mortem.
What changes:
- BCIConfig gains a `backendsDir` string field. JSAdapter reads
the top-level `configurationParams.backendsDir` directly (not
via `loadMap`) to avoid polluting any of the BCI handler
namespaces.
- index.js threads `BCIWhispercppConfig.backendsDir` into
`configurationParams`, defaulting to `<addon>/prebuilds`
resolved via `bare-path`. Surfaced in `index.d.ts`.
- BCIModel::load() now calls `ensureBackendsLoadedAndroid()` (gated
on `__ANDROID__`, idempotent via `std::call_once`) BEFORE
`whisper_init_from_file_with_params()`. Joins `backendsDir` with
the compile-time `BACKENDS_SUBDIR` and dispatches to
`ggml_backend_load_all_from_path()`. Inactive today (no MODULE
backends produced at 1.8.4.2); the call still runs because it's
cheap and we want symmetry with transcription/parakeet.
- BCIModel::captureActiveBackendInfo() snapshots the active backend
identity + device-memory after backend registration. New
`RuntimeStats` keys: `backendDevice`, `backendId`, `gpuMemTotalMb`,
`gpuMemFreeMb`. Numeric mapping (CPU=0 / Metal=1 / CUDA=2 /
Vulkan=3 / OpenCL=4 / other=99) lock-stepped with
transcription-whispercpp 0.9.0 + transcription-parakeet for
cross-addon Device Farm comparability.
- CMakeLists.txt: `bare_target` + `bare_module_target` discovery,
`BACKENDS_SUBDIR` compile define, `BACKEND_DL_LIBS` (IMPORTED
`ggml::*` targets) + `BACKEND_DL_LOOSE_SOS` (loose
`libqvac-speech-ggml-*.so` staging) plumbing. Parity with
transcription-whispercpp / transcription-parakeet.
Test-then-implementation: GoogleTest additions guard the new
config field round-trip and the new RuntimeStats key contract +
default-CPU values (mirrors `WhisperModel`'s `BackendInfo` unit-
test contract). All 22 GTests, 21 brittle unit tests, 6 integration
tests pass locally on Linux.
Version bump: 0.1.0 -> 0.1.1 (additive plumbing only, no behaviour
change; the minor bump is reserved for PR 3 / GPU enablement).
Co-authored-by: Cursor <cursoragent@cursor.com>
* bci-whispercpp: derive backend stats from actual whisper_context_params (review)
Addresses jpgaribotti's review on #2326: captureActiveBackendInfo()
treated a missing contextParams.use_gpu as false, but
toWhisperContextParams() leaves whisper_context_default_params() intact
(use_gpu=true). So with no explicit use_gpu, whisper could initialise a
GPU while runtimeStats reported backendDevice=0/backendId=0.
Fix: pass the exact whisper_context_params used by
whisper_init_from_file_with_params() into captureActiveBackendInfo() and
read use_gpu / gpu_device from it, instead of re-deriving from the
BCIConfig map with a (wrong) false default. Reported backend identity is
now in lock-step with the context whisper actually built.
Also corrects the GPU device selection to mirror whisper's
whisper_backend_init_gpu(): gpu_device is an index AMONG GPU devices
(default 0), not an index into all devices (device 0 is normally the
CPU). Removed the now-unused configUseGpu()/configGpuDeviceIndex()
helpers.
Validated: host build + test:cpp (22/22) + test:integration (6/6) green;
clang-tidy + clang-format clean on the changed file; android-arm64
cross-build compiles.
Co-authored-by: Cursor <cursoragent@cursor.com>
* bci-whispercpp: report IGPU backends + Adreno OpenCL guard (port transcription #2343)
Ports the transcription-whispercpp fix merged in #2343
("report IGPU backends (fix Mali silent CPU mislabel)") into the BCI
addon so the two stay faithful mirrors and the BCI Android GPU path
(QVAC-19234) behaves correctly on real devices:
- captureActiveBackendInfo() now walks BOTH GGML_BACKEND_DEVICE_TYPE_GPU
and _IGPU. ggml-vulkan reports integrated GPUs (Mali, Adreno-via-
Vulkan, Intel iGPU) as IGPU; skipping IGPU made every Vulkan-on-mobile
device look like a silent CPU fallback even while whisper ran on the
GPU. gpu_device is treated as an index into the filtered GPU/IGPU list,
matching whisper_backend_init_gpu()'s `cnt`.
- New adrenoOpenclGpuDeviceIndex() + an Adreno guard in load(): when an
Adreno OpenCL device is registered (Android registers both Vulkan and
OpenCL for the same GPU, Vulkan first), steer whisper to OpenCL. The
Adreno Vulkan driver SIGSEGVs in ggml compute (vkCmdBindPipeline);
OpenCL is the supported Adreno backend. No-op on Mali/desktop.
- captureActiveBackendInfo() signature is now (bool useGpu, int
gpuDeviceIndex), fed the exact post-guard whisper_context_params, and
the fallback WARNING text matches #2343.
All behaviour-neutral on this PR's whisper-cpp@1.8.4.2 (no GPU/IGPU
devices register, adrenoOpenclGpuDeviceIndex()=-1). Validated: host
build + test:cpp (22/22) + test:integration (6/6) + lint + test:dts;
clang-format-20 + clang-tidy-19 clean on the changed files;
android-arm64 NDK cross-build compiles.
Co-authored-by: Cursor <cursoragent@cursor.com>
---------
Co-authored-by: Cursor <cursoragent@cursor.com>1 parent 4bc3e10 commit 8d1d73a
10 files changed
Lines changed: 553 additions & 5 deletions
File tree
- packages/bci-whispercpp
- addon
- src
- js-interface
- model-interface/bci
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
8 | 59 | | |
9 | 60 | | |
10 | 61 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
49 | 105 | | |
50 | 106 | | |
51 | 107 | | |
| |||
77 | 133 | | |
78 | 134 | | |
79 | 135 | | |
| 136 | + | |
80 | 137 | | |
81 | 138 | | |
82 | 139 | | |
| |||
Lines changed: 10 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
108 | 118 | | |
109 | 119 | | |
110 | 120 | | |
| |||
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
30 | 37 | | |
31 | 38 | | |
32 | 39 | | |
| |||
0 commit comments