TL;DR
As Large Language Models (LLMs) shift toward "agentic" workloads with massive context windows, inference is increasingly bottlenecked by memory bandwidth rather than raw compute. This paper introduces DeepFusionKernel, an aggressively fused CUDA operator that combines the separate matrix multiplications (GEMMs) and pointwise operations of SwiGLU MLP blocks into a single kernel. By eliminating intermediate memory read/writes, it delivers up to a 13.2% speedup on NVIDIA H100 and 9.7% on A100 GPUs over state-of-the-art inference frameworks like SGLang.
What Problem Does This Paper Address?
When LLMs are deployed in real-world agentic workflows (like analyzing large codebases or maintaining long-running chat histories), they process up to 100× more tokens per inference than standard chatbots. In this regime, the primary bottleneck shifts from compute capacity to memory bandwidth.
While recent optimization efforts have heavily targeted the attention mechanism, the SwiGLU MLP (Multi-Layer Perceptron) blocks actually dominate the model's parameter count and drive massive memory-bandwidth pressure. Standard deep learning frameworks implement SwiGLU using either four separate kernels (naive PyTorch) or two kernels (SGLang, vLLM). As shown in the layout comparison below, these approaches force the GPU to repeatedly write intermediate activations back to High Bandwidth Memory (HBM) and read them back, leaving powerful Tensor Cores severely underutilized.
Methods
The authors propose DeepFusionKernel, which deeply fuses the first stage of the SwiGLU MLP block:
$$A_2 = (XW_{\text{Up}}) \otimes \text{SiLU}(XW_{\text{Gate}})$$
Instead of materializing the intermediate outputs of the gate and up-projections in HBM, DeepFusionKernel streams these values directly through the GPU's registers and shared memory.
To maximize on-chip data reuse across different hardware and workload configurations, the authors designed two distinct tiling strategies:
- Row-major tiling: Enhances locality for the input activation $X$, making it ideal for larger batch sizes where activations dominate memory traffic.
- Column-major tiling: Prioritizes the reuse of weight tiles, which is highly beneficial for agentic decoding where batch sizes are small and large model weights dominate the memory footprint.
Because the optimal configuration depends heavily on batch size, model shape, and GPU architecture, DeepFusionKernel includes a lightweight, profiler-driven scheduler. At deployment time, this scheduler quickly benchmarks candidate tiling sizes and loop orderings to select the highest-throughput option before capturing the execution path using CUDA Graphs.
Datasets
The paper does not introduce new datasets or focus on model training. Instead, it evaluates inference and decoding performance using the popular LLaMA 3.1 70B model architecture executing in FP16 precision.
Key Insights and Ideas
- The "Fat" GEMM Problem: In long-context autoregressive decoding, batch sizes are constrained by KV-cache limits, causing GEMM inputs to become structurally "fat." This drops Tensor Core utilization, making memory traffic reduction the highest-leverage optimization strategy.
- Tiling Layout Matters: There is no single "best" kernel layout for all inference jobs. The choice between row-major and column-major tiling creates a fundamental trade-off between optimizing for input activation locality versus weight matrix reuse.
- Co-designing Fusion with Tensor Parallelism: The authors carefully align their fusion strategy with standard Tensor Parallelism (TP). By partitioning the up and gate weights column-wise and the down weights row-wise, intermediate computations stay entirely local to each GPU, requiring only a single all-reduce operation at the very end of the MLP block.
Key Results
The authors integrated DeepFusionKernel into SGLang (utilizing the FlashInfer attention backend) and benchmarked it against stock SGLang, vLLM, and naive distributed PyTorch using four NVIDIA A100 or H100 GPUs (TP=4).
- Throughput Gains: DeepFusionKernel consistently outperformed SGLang across typical decoding workloads, achieving up to a 13.2% speedup on H100 (at batch size 2) and up to a 9.7% speedup on A100 (at batch size 16).
- Abundant Compute Scaling: The speedups were particularly pronounced on the H100. Because the H100 possesses massive compute throughput relative to its memory bandwidth, reducing HBM traffic via fusion unlocked significant latent performance.
- Long-Context Stability: In agentic long-generation tests scaling up to 16,384 tokens, DeepFusionKernel maintained stable throughput advantages, proving that even as attention costs grow with context length, MLP memory optimization remains highly impactful.
Limitations and Future Work
- Interconnect Evaluation: Due to limited hardware resources, the authors did not exhaustively test different GPU cluster interconnect topologies, though they note that inter-GPU communication jitter accounts for most of their high-batch-size variance.
- Scope of Fusion: The kernel currently focuses on fusing the first stage of the SwiGLU block ($W_{\text{Gate}}$ and $W_{\text{Up}}$), leaving the final $W_{\text{Down}}$ projection as a separate step due to the intervening tensor-parallel all-reduce requirement.
- Integration Model: DeepFusionKernel relies on manual integration into an inference framework (SGLang) paired with a runtime profiler, rather than being automatically generated by a general-purpose compiler.
Summary updated