where does a llama.cpp backend live?
One interesting use case is running part of a model on the NPU, part on the iGPU. Where this really gets interesting is prefill, where we can cut latency. We have most of the pieces: this question is about project organization.
I see 3 separate efforts:
- OpenFlowLM-Next
- The open kernels -- often useful outside of OpenFlowLM, and if we're updating them all the time, we may want to make it something that can be updated outside of the CLI
- a llama.cpp backend to run prefill on the npu, decode on the next backend.
It turns out to enable the 3rd you don't need to fork llama.cpp or anything. You can just load it as a backend and say 'yes, let me run this piece on the npu' and handle it. I have this working outside of this repo.
The question -- does it belong in this repo, or is it a separate effort? If in this repo, how should we organize those 3 efforts?
llama.cpp - Could you explain this a little closer? Do you mean that by just adding a llama.cpp backend, we don't need to think about decoding on the gpu in this repo? What would be the scope increase in this case?
correct. Instead of being the frontend, we, or a companion project, just load as a backend within llama.cpp. The backend framework has the opportunity to 'take over' at a number of points. We can just take over prefill, and allow the gpu backend to handle decode.
i think it's going to have to be a separate, but related, project. a lot of folks are working on this. I'm not sure if anyone has cracked the code. I'm making some progress. If you or @Atomic-Germ see a way that this fits into this project, let me know. Since it doesn't need or have the frontend, and can only work with llama.cpp, it just seems like a weird fit.
I'll wait for opinions and if you all agree I'll close this issue.
@Cyronius I'm actually not so sure it should be a fully separate project. I think we can effectively expose the engine as a backend itself, like how you can pip install the llama.cpp repo to get some ggml tools installed. I'm not certain how we would keep it in sync otherwise. Seems like a sub-project should be a thing really. And currently with Guanaco, I can run all my prefill on my gpu and the tokens get generated on the cpu, which in an integrated system is fast because there's zero copying between the two chips. Being able to do the same with the NPU probably has benefits worth exploiting.
@Cyronius I'm actually not so sure it should be a fully separate project. I think we can effectively expose the engine as a backend itself, like how you can pip install the llama.cpp repo to get some ggml tools installed. I'm not certain how we would keep it in sync otherwise. Seems like a sub-project should be a thing really. And currently with Guanaco, I can run all my prefill on my gpu and the tokens get generated on the cpu, which in an integrated system is fast because there's zero copying between the two chips. Being able to do the same with the NPU probably has benefits worth exploiting.
what about a monorepo? I see flm. open kernels, and llama.cpp backend as being distinct, but we could keep them in the same tree since they lilkely reuse components.
I think this is something we could target for either the 0.2.0 or 0.3.0 milestones rather than trying to squeeze into this release; it is a large effort.
Thanks — this is very close to what I am seeing on Windows/XDNA2.
My current conclusion is that the main problem is no longer just kernel generation. The important part seems to be preserving execution state and changing only the runtime-dependent pieces when possible.
On my side I now have:
- adaptive kernel generation + hardware validation;
- persistent hw_context / BO experiments;
- an aiebu-generated config ELF whose relocation contract has been audited down to the BD addresses;
- the ELF-native XRT path built up to submission;
- a reproducible large cost when rotating hw_contexts;
- evidence that changing execution sequence can change measured compute throughput dramatically without changing the kernel itself.
The current blocker on Windows is now very specific: the config ELF and relocations look correct, but the ELF-native submission is rejected before real execution (state 6 / invalid CU mask). I reproduced the same behavior from native C++, so it is not a Python-only issue.
That is why the dynamic runtime_sequence / TXN work is particularly interesting to me.
If the topology/core program can stay resident and only BD addresses, offsets, strides, extents and sequencing are regenerated at runtime, that may be much better than switching complete executable configurations for every shape.
The architecture I am currently testing is roughly:
static kernel/topology + persistent context + dynamic TXN/BD + measured transition cost
with full ELF / multi-config only when the actual core program or topology has to change.
One thing I would be very interested to understand is the intended low-overhead path for this on Windows:
- Is the dynamic TXN path expected to work with the current XRT/MCDM Windows stack?
- Can multiple runtime-generated transactions reuse the same configured hw_context without rebinding the CU/kernel?
- Is there an intended way to keep the core/config resident and only submit new BD/runtime-sequence state?
- For full-ELF, where is the CU identity / mask expected to come from when using
xrt::ext::kernel?
I can provide minimal Windows reproducers for the ELF submission failure and the relocation/BD audit if that is useful.
I have a few XDNA2/Windows findings that may be useful for the llama.cpp backend work.
On my setup, the main bottleneck is not always AIE compute itself. Execution boundaries, transport, dispatch overhead, and context lifecycle can dominate end-to-end performance.
Some concrete observations from my tests:
- On the Windows path I am testing, I see roughly 0.7–0.9 ms of fixed overhead per dispatch.
- Different execution paths can behave very differently. For the same kind of operations, direct
xrt::runhas been much faster than some runlist-based paths in my measurements. - Batching changes the economics of the NPU significantly.
- For one FFN test over 4 tokens, I reduced total FFN time from about 90.9 ms to 44.0 ms, around a 2.07x speedup.
- Gate/up works well with B4 in that setup.
- For the down projection, B4 currently exceeds the L1 constraint in my configuration, so 2xB2 is used instead.
- Some optimized GEMV paths have reached roughly 2.4x improvement over earlier implementations.
- The important point is that good micro-kernel performance does not automatically translate into good LLM performance. The graph boundaries and data movement matter a lot.
For the llama.cpp backend specifically, I would be careful with purely op-by-op NPU offload.
I think the real cost function should be closer to:
copy-in + submit + kernel + copy-out + context/reconfiguration cost
rather than simply comparing NPU kernel time against GPU kernel time.
supports_op() or the offload decision could ideally be shape-aware and batch-aware, rather than only answering whether a kernel exists.
I would also avoid hard-coding a rule like:
prefill = NPU
decode = GPU
It is a good initial heuristic, but my results suggest that the optimal placement can depend strongly on the shape, batch size, residency, and transfer path.
The most interesting cases for XDNA2 seem to be M=2/4/8 and larger blocks where dispatch and transfer costs can be amortized.
For M=1 decode, some operations can still be interesting, but it is much more sensitive to dispatch cost, weight residency, and transport.
Architecturally, I think it would be useful to keep the llama.cpp backend thin and put the intelligence in a separate runtime layer:
shape -> candidate plans -> measurement/prediction -> plan selection -> cache
That runtime can then manage persistent contexts, ELF/kernel residency, buffers, and fallbacks independently from llama.cpp.
A few tests that may be worth doing early:
- Start with only one accelerated
MUL_MATpath. - Compare M=1, 2, 4, and 8.
- Measure kernel time and true end-to-end time separately.
- Try offloading a whole FFN region rather than every primitive independently.
- Compare CPU -> NPU -> CPU, GPU -> NPU -> GPU, and resident-NPU cases.
- Check whether the GGML scheduler inserts transfers between gate/up/activation/down.
- Track dispatch count and transferred bytes per token.
- Check whether weights, buffers, ELF/program state, and hardware contexts can remain persistent across calls.
One thing I would strongly recommend measuring is the performance of a complete graph region rather than judging the NPU from isolated kernel benchmarks.
On my tests, fast kernels can still lead to poor end-to-end inference if too many boundaries are introduced.
I also have a shape-aware measured routing/planning system in development, so I am very interested in comparing results if you start experimenting with dynamic NPU/GPU placement.
Just a note: my GitHub repos are not fully up to date with my current work.
I have quite a lot of Windows/XDNA2 material that is not published yet — experiments around XRT/MCDM, hw_context behavior, ELF/config handling, BO/sub-buffer quirks, submission paths, runtime sequencing, and a few reproducible failure modes.
Some of it may be useful for this discussion, and I’m happy to share specific reproducers, measurements or notes if they help.
This is not my professional field, so I may sometimes use the wrong terminology or approach things from an unusual angle. Most of what I have comes from direct experimentation, reverse engineering, and testing on real hardware rather than from working professionally on compilers or NPU runtimes.
GaTmaNnes : https://github.com/GaTmaNnes gatman45 : https://github.com/gatman45 Tagman45 : https://github.com/Tagman45 Repos importants xdna2- (runtime E2E XDNA2) : https://github.com/GaTmaNnes/xdna2- Npu-amd (findings stabilité, avril 2026) : https://github.com/gatman45/Npu-amd RAPPORT-TECHNIQUE (optimisation LLM XDNA2) : https://github.com/GaTmaNnes/RAPPORT-TECHNIQUE-Optimisation-de-l-inf-rence-LLM-sur-NPU-XDNA2 oga-xdna (daemon OGA) : https://github.com/Tagman45/oga-xdna d2-quant-planner : https://github.com/GaTmaNnes/d2-quant-planner d2-xdnaopti (profiler) : https://github.com/gatman45/d2-xdnaopti Autres liés
@Cyronius monorepo makes sense
I was recently made aware of a cool PR on FastFlowLM: https://github.com/ROCm/FastFlowLM/pull/743
with this we could basically attack things from the opposite end -- run everything on the npu by default, but selectively kick things over to the gpu or cpu by operation. This is a very cool idea that can probably get us a lot of mileage, and makes more sense for our project than running as a llama.cpp backend.
@Cyronius that's not a bad idea