Skip to content

QVAC-21901 perf(mtmd/gemma4v): Mali Vulkan encoder profiling and measured sweep#182

Closed
Alok-Ranjan23 wants to merge 3 commits into
temp-9341from
feat/QVAC-21901-close-mali-vulkan-encoder-gpu-cpu-gap
Closed

QVAC-21901 perf(mtmd/gemma4v): Mali Vulkan encoder profiling and measured sweep#182
Alok-Ranjan23 wants to merge 3 commits into
temp-9341from
feat/QVAC-21901-close-mali-vulkan-encoder-gpu-cpu-gap

Conversation

@Alok-Ranjan23

@Alok-Ranjan23 Alok-Ranjan23 commented Jul 8, 2026

Copy link
Copy Markdown

Status — Draft / DO NOT MERGE

QVAC-21901 tracks the measured effort to close the Gemma-4V Mali Vulkan projector GPU↔CPU gap. Base: temp-9341.

Candidate #1 — rejected and removed

The original sqrt(n_embd) std-norm affine fold was benchmarked on Pixel 9 / Mali with the cognitive preset:

Configuration CPU mmproj encode GPU mmproj encode GPU/CPU
Fold ON 8,770 ms 12,829 ms 1.46×
Fold OFF 9,409 ms 12,498 ms 1.33×

Device Farm units vary, so this is not an exact regression claim; however it showed no win and an unfavorable direction. The candidate and its QVAC_G4V_STDFOLD knob have been reverted. The branch intentionally has no net source diff while profiling determines the next candidate.

Next: measured op profile

A Pixel 9 GPU-only Vulkan profiling run completed. The first environment-only profiler attempt did not emit per-op timings to Device Farm logcat, so the next bench-only step enables the port's force-profiler feature and verifies Vulkan Profiling Results appear before selecting a kernel candidate.

Potential targets (only after profile): patch-embedding CONV_2D, repeated Gemma-4V 2D-RoPE / V RMS-norm dispatches, or explicit-attention / matmul shapes.

Validation method

QVAC-21361-style Device Farm measurement: Gemma-4 E2B Q4 + Q8 projector, Pixel 9 Mali-G715, CPU-vs-GPU projector cells, cognitive preset, quality identity gate. Keep only measured winners and remove all sweep/profile knobs before review.

Dependencies / related work

…to std-norm

Mali Vulkan encoder optimization for the Gemma-4V projector tail. Instead of
scaling the full pooled activation tensor [n_embd, n_tokens] by sqrt(n_embd),
fold that magnitude into the per-channel std-norm params (tiny [n_embd] vectors):
    (k*p - b)*s == (p - b/k)*(s*k)
Trades one full-tensor elementwise op for two vector-sized ones. Algebraically
exact (quality unchanged).

Gated by QVAC_G4V_STDFOLD (default on) as a QVAC-21361-style sweep knob so the
on-device Pixel 9 / Mali encode A/B measures fold-on vs fold-off; the winning
config is baked in and the knob removed before the PR ships.

Candidate #1 of the QVAC-21901 Mali fusion sweep. Remaining candidates
(per-layer 2D-RoPE collapse, conv2d patch-embed, coop-matrix/KleidiAI) are
added + measured after the on-device profile identifies the post-#174 hotspot.

Co-authored-by: Cursor <cursoragent@cursor.com>
@Alok-Ranjan23 Alok-Ranjan23 changed the title QVAC-21901 perf(mtmd/gemma4v): Mali Vulkan encoder fusion sweep (candidate #1: std-norm fold) QVAC-21901 perf(mtmd/gemma4v): Mali Vulkan encoder profiling and measured sweep Jul 13, 2026
…snapshots

The existing Vulkan perf logger only prints debug output, which is not retained
by the Android Device Farm benchmark path. Capture its aggregated per-op timing
map as compact JSON after each completed graph and expose it through a dynamic
Vulkan registry extension. mtmd retrieves the latest vision-graph snapshot
immediately after image encode, without adding generic-backend dependencies.

The API is a no-op for non-Vulkan/unprofiled backends. The addon benchmark will
forward the JSON through runtime stats in a follow-up bench-only change, letting
Pixel 9 runs rank CONV_2D, MUL_MAT, RMS_NORM, and attention operations before
selecting the next production optimization.

Co-authored-by: Cursor <cursoragent@cursor.com>
@Alok-Ranjan23

Copy link
Copy Markdown
Author

Closing without merge. QVAC-21901 measured the Pixel 9 Mali-G715 Gemma-4V path:

Conclusion: retain #172/#174, keep the projector CPU-default on Mali (GPU remains ~1.33x CPU), and do not ship profiling/sweep code. Evidence is recorded on QVAC-21901.

@gianni-cor gianni-cor deleted the feat/QVAC-21901-close-mali-vulkan-encoder-gpu-cpu-gap branch July 15, 2026 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant