Automated GPU Kernel Generation Using LLMs and Inference-Time Scaling

nvidia · Tech · 2025 · source Agentic: no · promotional bias: med · source-backed · extracted with prompt 0.5.4 (schema v2)

Generated from extraction.json — do not edit by hand. Every claim cites verbatim source evidence; stated means the quote directly asserts the claim, implied means it supports it indirectly.

Problem

Domain: GPU systems

NVIDIA wanted to automate optimized attention-kernel generation, a specialized low-level programming task that normally requires expert GPU engineering and iterative performance tuning.

Constraints:

Architecture

NVIDIA built a closed-loop inference-time-scaling workflow for GPU kernel generation. A manually crafted prompt describes the target attention kernel, DeepSeek-R1 generates the initial GPU code, and a verifier running on H100 hardware tests or analyzes the generated kernel. If the kernel fails or can improve, Hopper GPUs refine and format feedback into a new prompt for DeepSeek-R1. The loop runs for a predetermined budget, about 15 minutes in the article, so the model can explore multiple candidate kernels and converge on numerically correct optimized implementations rather than relying on a one-shot answer.

Diagram confidence: explicit (topology described by the source).

flowchart LR
  manual-kernel-prompt[Manual kernel prompt] --> deepseek-r1-generator[DeepSeek-R1 generator]
  deepseek-r1-generator --> h100-verifier[H100 verifier]
  h100-verifier --> feedback-prompt-formatter[Feedback prompt formatter]
  feedback-prompt-formatter --> deepseek-r1-generator
  h100-verifier --> kernelbench-benchmark[KernelBench benchmark]
  deepseek-r1-nim-microservice[DeepSeek-R1 NIM microservice] --> deepseek-r1-generator
Drag to pan · scroll or use +/− to zoom · reconstructed from the source's described component topology

Components

Component Role Interacts with
Manual kernel prompt Domain-expert prompt describing the target attention kernel and implementation constraints. DeepSeek-R1 generator
DeepSeek-R1 generator Open-source reasoning model that generates GPU kernel code and revises it from verifier feedback. Manual kernel prompt, H100 verifier, Feedback prompt formatter
H100 verifier Verifier running on NVIDIA H100 hardware that analyzes generated kernels for numerical correctness and performance. DeepSeek-R1 generator, Feedback prompt formatter, KernelBench benchmark
Feedback prompt formatter Turns verifier analysis into new prompts for additional DeepSeek-R1 generation attempts. H100 verifier, DeepSeek-R1 generator
KernelBench benchmark Standardized benchmark used to measure numerical correctness for generated GPU kernels. H100 verifier
DeepSeek-R1 NIM microservice Containerized model-serving path NVIDIA points to for practical use of DeepSeek-R1. DeepSeek-R1 generator

Data flow

An engineer supplies a technical prompt describing an attention variant and implementation constraints. DeepSeek-R1 generates GPU kernel code. A verifier on an NVIDIA H100 checks the generated kernel and creates feedback prompts from the result. Those prompts are fed back into DeepSeek-R1 for additional attempts until the time budget ends, after which the workflow selects the improved generated kernel and evaluates it against KernelBench correctness and speedup measurements.

3 supporting quotes
“The workflow is first initialized by a manual prompt and the DeepSeek-R1 model generates the GPU code (that is, the kernel) in the first pass.”article, stated
“The verifier runs on an NVIDIA H100 GPU. It analyzes the generated kernel and creates new prompts that are provided as ‌input to the DeepSeek-R1 model.”article, stated
“This closed-loop approach makes the code generation process better by guiding it in a different way each time.”article, stated

Why this architecture

NVIDIA uses inference-time scaling because one-shot code generation is not reliable enough for GPU kernels. Attention implementations require precise math, memory behavior, and thread mapping, while LLMs can hallucinate or mix syntax. The verifier loop adds a concrete execution-based signal and turns failures into fresh prompts, spending more inference compute when the alternative is expert human kernel engineering. KernelBench provides a domain-specific correctness target, and NIM is the path toward operationalizing the model serving piece.

4 supporting quotes
“Recent LLMs like DeepSeek-R1 have shown a lot of promise in code generation tasks, but they still face challenges creating optimized code on the first try.”article, stated
“LLMs can occasionally produce hallucinated code or mix syntax from different languages or frameworks, causing immediate code errors or inefficiencies.”article, stated
“Computing the optimal GPU thread mapping is also non-trivial and a challenging task, often requiring iterative refinement to achieve a correct and efficient kernel.”article, stated
“This makes it necessary to use other strategies at inference time to generate optimized code. The following prompt is sample user input for a relative positional embeddings attention kernel.”article, stated

Models used: DeepSeek-R1 · DeepSeek-R1 NIM microservice

Scale

Alternatives considered (roads not taken)

One-shot LLM kernel generation

Rejected because: DeepSeek-R1 and similar models can generate useful code but still struggle to produce optimized, correct kernels on the first try.

“Recent LLMs like DeepSeek-R1 have shown a lot of promise in code generation tasks, but they still face challenges creating optimized code on the first try.”article, stated

Manual expert kernel development only

Rejected because: Creating optimized attention kernels takes significant skill and time, even for experienced engineers, so automated generation can reduce the human kernel-writing burden.

“Creating an optimized GPU kernel for attention takes a lot of skill and time, even for experienced software engineers.”article, stated

Accept simple attention implementations

Rejected because: Naive implementations can cause out-of-memory errors or poor computational efficiency as sequence length grows.

“developing an optimized lower-level implementation (that is, a GPU kernel) to prevent runtime errors arising from simple implementations (for example, out-of-memory errors)”article, stated

Patterns

eval-driven-development (verification)

Generated kernels are checked by a verifier and benchmarked for numerical correctness rather than accepted from the model directly.

“It analyzes the generated kernel and creates new prompts”article, stated
“This workflow produced numerically correct kernels for 100% of Level-1 problems and 96% of Level-2 problems”article, stated

prompt-chaining (generation-workflow)

Verifier feedback becomes fresh prompts that guide subsequent DeepSeek-R1 attempts in a loop.

“It analyzes the generated kernel and creates new prompts”article, stated
“This closed-loop approach makes the code generation process better by guiding it in a different way each time.”article, stated

latency-optimization (performance)

The generated kernels target attention speedups and computational efficiency on GPU workloads.

“The results turned out to be better than the optimized kernels developed by skilled engineers in some cases.”article, stated
“the NVIDIA Workflow with DeepSeek-R1 achieves speedups of 1.1x for Causal Mask and Document Mask, 1.5x for Relative Positional, 1.6x for Alibi Bias and Full Mask, and 2.1x for Softcap.”article, stated

Tradeoffs

Inference-time scaling for code generation

Chose spending additional inference compute and verifier iterations over single-pass model generation.

Rationale: The extra compute lets the workflow explore multiple outcomes and improve correctness for a complex technical task.

“this technique improves model performance by allocating additional computational resources during inference to evaluate multiple possible outcomes and then selecting the best one”article, stated
“Recent LLMs like DeepSeek-R1 have shown a lot of promise in code generation tasks, but they still face challenges creating optimized code on the first try.”article, stated

Execution-backed verification

Chose H100 verifier and KernelBench correctness checks over static review or human inspection alone.

Rationale: GPU kernels can fail through subtle numerical or performance issues, so hardware-backed verification supplies concrete feedback.

“The verifier runs on an NVIDIA H100 GPU. It analyzes the generated kernel and creates new prompts”article, stated
“The Level-1 solving rate in KernelBench refers to the numerical correct metric used to evaluate the ability of LLMs to generate efficient GPU kernels”article, stated

Domain-expert prompting remains in the loop

Chose manual prompts with detailed formulas and implementation constraints over fully autonomous natural-language task discovery.

Rationale: The sample prompt shows that useful kernel generation still depends on specific mathematical and implementation guidance.

“The workflow is first initialized by a manual prompt and the DeepSeek-R1 model generates the GPU code”article, stated
“Please write a GPU attention kernel to support relative position encodings. Implement the relative positional encoding on the fly within the kernel.”article, stated

Gotchas (what bit them)

LLM-generated GPU code can be syntactically or semantically wrong.

Root cause: Models may hallucinate code or mix syntax from different languages and frameworks.

Resolution: NVIDIA runs generated kernels through an H100 verifier and feeds failures back into further prompts.

“LLMs can occasionally produce hallucinated code or mix syntax from different languages or frameworks, causing immediate code errors or inefficiencies.”article, stated
“The verifier runs on an NVIDIA H100 GPU. It analyzes the generated kernel and creates new prompts”article, stated

Correct GPU thread mapping is hard for a model to infer directly.

Root cause: Optimal thread mapping is non-trivial and often requires refinement based on hardware execution behavior.

Resolution: The closed-loop verifier supplies iterative guidance rather than trusting the first generated mapping.

“Computing the optimal GPU thread mapping is also non-trivial and a challenging task, often requiring iterative refinement to achieve a correct and efficient kernel.”article, stated

The approach is promising but not universally consistent yet.

Root cause: Success rates still leave unsolved cases, especially outside the easier benchmark categories and problem variants.

Resolution: NVIDIA frames the work as active research and says more work is needed for wider problem consistency.

“While we are off to a good start, more work is needed to generate better results consistently for a wider variety of problems.”article, stated

Evaluation

NVIDIA evaluates generated kernels with an H100 verifier and Stanford KernelBench, using numerical correctness and speedup comparisons against PyTorch/Flex Attention baselines.

Metrics: 100% numerical correctness on Level-1 KernelBench problems · 96% numerical correctness on Level-2 KernelBench problems · 1.1x-2.1x speedup over PyTorch API baseline depending on kernel type · time budget over 10 minutes and about 15 minutes in the closed loop

3 supporting quotes
“This workflow produced numerically correct kernels for 100% of Level-1 problems and 96% of Level-2 problems, as tested by [Stanford’s KernelBench]”article, stated
“Figure 4 shows how the inference-time budget affects the agent’s solving rate.”article, stated
“the NVIDIA Workflow with DeepSeek-R1 achieves speedups of 1.1x for Causal Mask and Document Mask, 1.5x for Relative Positional, 1.6x for Alibi Bias and Full Mask, and 2.1x for Softcap.”article, stated

Outcomes

The reported evaluation spans KernelBench Level-1 and Level-2 problems, including 100 Level-1 problems and multiple attention-kernel variants.

3 supporting quotes
“This workflow produced numerically correct kernels for 100% of Level-1 problems and 96% of Level-2 problems”article, stated
“The results turned out to be better than the optimized kernels developed by skilled engineers in some cases.”article, stated
“While we are off to a good start, more work is needed to generate better results consistently for a wider variety of problems.”article, stated