High-Performance Code Generation Using LLMs: Tensor Reduction
Investigation of LLM capabilities in automating high-performance CUDA kernel generation for tensor reduction on NVIDIA A100 GPUs.
- The problem
- Can LLMs write GPU code as fast as hand-tuned code?
- What we did
- Compared hand-tuned and LLM-written CUDA code for summing an array on an A100 GPU.
- What we found
- On 1 and 2 billion numbers, the best LLM code took 2.1× as long as hand-tuned.
- The limit
- We tested one task on one GPU, not other workloads or hardware.
On sums of 1 and 2 billion numbers, the best LLM-written CUDA kernel took 2.1× as long as the hand-tuned one.
Table 4 (p. 18), NCU Duration. Tree values from Fig. 9a. Ratios computed.
Six hand-optimization steps cut the time for one billion numbers from 34.12 to 4.41 ms, 7.7× faster.
Table 2 (p. 16). Speedup computed.
Serial addressing keeps the busy threads side by side, and warp efficiency rises from 84.85% to 98.62%.
The 8-number serial example is worked out here to show the idea.
Redrawn from Fig. 9 (p. 24), after [13]; Table 2.
The LLM kernels came from a loop: generate, compile, time on the GPU, and feed the result back.
§4.2, Figs. 5–6; models as in Table 3.
The gap grows with input size: about equal at 1,024 numbers, 1.51× at a million, 2.12× at 1 and 2 billion.
The value at 1,024 numbers is approximate: its time is printed as a rounded 4 µs.
Table 4 (p. 18). Ratios computed.
The best LLM kernel matched the hand-tuned one on the basics but lacked three techniques: two numbers per thread on load, warp shuffle, and full unrolling.
Table 5 (p. 19), shortened.



































































































