KatInterview

Designing an Agent That Writes and Tunes GPU Kernels

Machine LearningModel answer
MediumModel answerMachine Learningml-systemscompilersgpu

Last updated

Design an agent that generates and optimizes GPU kernels and compiler passes, covering validation strategy, correctness checks, numerical tolerances, and performance evaluation.

Scenario

Your team is exploring whether an AI agent could automate the writing and tuning of low-level GPU kernels and compiler transformation passes — work that today requires specialist engineers and many manual iterations.

Before committing to the idea, your tech lead wants a clear-eyed design review. They are not asking you to build the system yet; they want to know whether the concept is sound and, if so, what it would take to trust its outputs.

Your Task

Walk through the following:

  1. What the agent needs to do — what inputs it works from, what it produces, and what transformation space it operates in.
  2. How you would validate its outputs — distinguishing three separate bars: does it compile, is it numerically correct, and is it actually faster?
  3. How you would run generated code safely — isolation, resource limits, and why "it compiles" is not enough.
  4. What benchmarks and reference data you would use — representative shapes, data types, and hardware targets.
  5. Where the approach breaks down — fundamental limitations that would constrain how far you could deploy this in practice.

What Is Expected

A structured discussion with concrete mechanisms, not a high-level wish list. Call out trade-offs, failure modes, and where human review is still necessary. Numbers and examples strengthen the answer.

Hints

Hint 1

Start by bounding the problem: an agent with an unbounded transformation space is unverifiable, so name specific constraints (tile sizes, loop orders, data layouts) before discussing validation.

Hint 2

Separate correctness from performance — a kernel can be numerically wrong and still be faster, or numerically acceptable under a relaxed tolerance but only for certain data types. Treat these as independent checks, not a single pass/fail.

Hint 3

Think about what 'isolated execution' actually requires: a kernel that allocates too much memory, spins forever, or silently corrupts a shared buffer is a real risk. Describe the sandbox, not just the concept of one.