Next step - compile straight to verilog so I can buy some LLMs on aliexpress
I mean.... LLM-in-a-box would actually be pretty neat! I'm looking at some air-gapped work coming up and having something like that would be quite handy
Compiling LLMs into a MegaKernel: A path to low-latency inference
41–50 of 79 posts
Re: Compiling LLMs into a MegaKernel: A path to low-latency inference
#42Earlier quoted context omitted.
I mean.... LLM-in-a-box would actually be pretty neat! I'm looking at some air-gapped work coming up and having something like that would be quite handy
Isn't that easily accomplished by setting up a local deployment and then yanking the network cable? Anything that can quickly run a capable LLM is going to be a pretty beefy box though. More like LLM in an expensive space heater.
Re: Compiling LLMs into a MegaKernel: A path to low-latency inference
#43https://news.ycombinator.com/item?id=44111673
I find it curious that fundamentals of the CUDA programming model (eg kernel launches) are being subverted in favor of fine grained task based parallelism that ends up using the hardware more effectively. Makes me wonder if CUDA has been holding us back in some ways.
What are the chances we see your work land in PyTorch as an experimental backend?
Awesome stuff thanks for sharing.
P.S. minor typo, your first two paragraphs under part 1 are nearly identical.
Re: Compiling LLMs into a MegaKernel: A path to low-latency inference
#44Re: Compiling LLMs into a MegaKernel: A path to low-latency inference
#45Does anyone have an intuition on why this offers significant gains over CUDA Graphs?. The CPU launch cost of a graph is tiny which implies most of the work has been offloaded to the GPU's own scheduler. I'd expect that some I/O marshalling at kernel boundaries could be avoided with megakernels. Maybe some loop fusion? Are there any more interesting optimizations they enable?
> The CPU launch cost of a graph is tiny Absolutely not; it’s comparable to the launch overhead of a kernel.
What I was getting at was that a “megakernel” and a captured graph should have similar launch costs.
Re: Compiling LLMs into a MegaKernel: A path to low-latency inference
#46Does anyone have an intuition on why this offers significant gains over CUDA Graphs?. The CPU launch cost of a graph is tiny which implies most of the work has been offloaded to the GPU's own scheduler. I'd expect that some I/O marshalling at kernel boundaries could be avoided with megakernels. Maybe some loop fusion? Are there any more interesting optimizations they enable?
You've hit the nail on the head. The CPU launch cost of a pre-compiled CUDA graph is tiny. CUDA Graphs are a huge step up from manually launching kernels, but they still treat kernels as monolithic, black-box operations. A megakernel erases the boundaries between those operations. With CUDA Graphs, as in the example in the article, if you have Matmul -> AllReduce, the AllReduce kernel cannot start until the entire Ma…
I suppose I could look through the code of this project, but I’d hate to have detangle that from the compiler infrastructure.
Re: Compiling LLMs into a MegaKernel: A path to low-latency inference
#47Next step - compile straight to verilog so I can buy some LLMs on aliexpress
Because training costs weren't high enough already so lets add mask costs on top. More seriously, isn't that pretty much what all those AI hardware startups have already been doing for a while now?
Re: Compiling LLMs into a MegaKernel: A path to low-latency inference
#48Hi author(s), the on-GPU interpreter approach looks like a promising path forward, have you seen this strikingly similar concurrent work? https://news.ycombinator.com/item?id=44111673 I find it curious that fundamentals of the CUDA programming model (eg kernel launches) are being subverted in favor of fine grained task based parallelism that ends up using the hardware more effectively. Makes me wonder if CUDA has bee…
I completely agree that CUDA can be a limiting factor, especially for latency-sensitive workloads. As GPUs are becoming larger and faster, it's increasingly difficult to write standalone kernels that fully utilize hardware resources—particularly when optimizing for low latency with small batch sizes.
> What are the chances we see your work land in PyTorch as an experimental backend?
We're definitely excited about that direction. We believe MPK can help PyTorch support megakernel generation, and we’re actively exploring how to make that happen. Stay tuned!
> P.S. minor typo, your first two paragraphs under part 1 are nearly identical.
Thanks for pointing it out--I meant to remove the duplicate paragraph when finalizing the post.
Re: Compiling LLMs into a MegaKernel: A path to low-latency inference
#49This project is from CMU. Hazy Research at Stanford talked about the megakernel too: https://hazyresearch.stanford.edu/blog/2025-05-27-no-bubbles Good to see the competition in this area. (Edited): Related paper covering the larger "mirage" project, but this doesn't cover the "megakernel" approach: https://arxiv.org/abs/2405.05751
This is the writer of the blog post. You are right that Stanford's work is a parallel effort. The main difference is that our focus is on compilation: making it easier to generate megakernels automatically.
Re: Compiling LLMs into a MegaKernel: A path to low-latency inference
#50Earlier quoted context omitted.
Because training costs weren't high enough already so lets add mask costs on top. More seriously, isn't that pretty much what all those AI hardware startups have already been doing for a while now?
most of them are much more general purpose. they might be specializing somewhat on the architecture, but not on the weights