Kernel fusion combines multiple GPU operations into a single device kernel to reduce global memory traffic and eliminate intermediate buffers. Using sum(abs(x)) as a running example, three fusion approaches are compared: manual CUDA C++ kernel fusion (full control, highest maintenance), implicit fusion via torch.compile (automatic but non-deterministic), and explicit fusion via cuda.compute using TransformIterator with reduce_into (Python ergonomics with deterministic, CUB-backed results). All three fused approaches achieve ~3x speedup over the naive two-kernel baseline by reducing memory traffic from 3 GiB to 1 GiB on an RTX 4090. The cuda.compute approach is highlighted as offering the best balance of productivity and predictability for Python developers.

10m read timeFrom developer.nvidia.com
Post cover image
Table of contents
Kernel fusion in practiceManual kernel fusionImplicit kernel fusionExplicit kernel fusion: Callbacks, iterators, and epilogs
50 Impressions