OpenFlowLM-Next icon indicating copy to clipboard operation
OpenFlowLM-Next copied to clipboard

open_kernels has no batched prefill GEMM

Open Cyronius opened this issue 2 months ago • 1 comments

open_kernels/ covers a Qwen3.6-MoE decode step end to end, but every matmul design in it is a GEMV: one weight pass produces one token. That is the right shape for decode, which is DRAM-bandwidth-bound, and the wrong shape for prefill.

Prefill is the compute-bound phase, and it is the only place XDNA2's matrix units can beat an iGPU — but only if one weight pass feeds many tokens. With a GEMV the weights are re-read per token, so prefill runs at decode speed and the NPU's arithmetic throughput is never used.

designs/gemm_q4_prefill/ is not this. It dequantises to bf16 first, which gives up the integer matrix unit and moves more bytes, and it predates the blocked dataflow work.

What is missing is a design where:

  • the weights stream once per pass and M tokens ride along;
  • the quantised weights enter the matrix unit as stored — no dequantisation step and no offline requantisation. For GGUF that means Q4_K, whose 6-bit sub-scales have to be folded into the integer accumulation instead of being applied in a float epilogue eight times per chunk;
  • the activation-side preparation does not eat the gain, which in practice means the host hands the core a table it has already quantised.

There is a further constraint that shapes the design: L1 is the ceiling on M, because the resident accumulator grows with it. Holding one output tile's bands instead of all of them is what buys the larger M.

Filing this so the gap is recorded. A design that closes it is measured and ready to port.

Cyronius avatar Sep 15 '26 19:09 Cyronius

i'm not sure if this one is quite ready yet. The work was done as part of a separate project where we run prefill on the npu and llama.cpp for everything else. But I'm posting it here now to gather opinions.

prelim work at https://github.com/Cyronius/ggml-xdna

Cyronius avatar Sep 15 '26 20:09 Cyronius