← All AI Engineer talks

AI Engineer Code 2025

AI Kernel Generation: What's Working, What's Not, What's Next

Read the talk

AI Kernel Generation: From Hardware Porting to Verified Speedups

Heterogeneous inference needs hardware-specific optimization. Natalie Serrino shows where kernel agents find useful speedups, where they fail, and why measurement must guide the search.

From a talk by Natalie Serrino

Before you start: Familiarity with PyTorch tensors and basic GPU execution will help; the article explains kernel fusion and the pooling-to-convolution rewrite.

An agent pipeline does not fit one hardware target

An agent pipeline can combine several models, processing stages, and tool calls. Moving each component to the hardware best suited to it sounds straightforward—until the model implementation turns out to be optimized for a different device. At Gimlet Labs, Natalie Serrino and her colleagues are building an inference cloud that splits and orchestrates these workloads across hardware vendors and device sizes. That creates a practical question: can AI help port the computational pieces to hardware they were not originally optimized for?

Here, kernels are the functions that perform massively parallel computations, using the many threads available on a GPU. They are the computational building blocks of workloads such as transformers, rather than operating-system kernels. Porting a model therefore involves more than making its high-level code run: the underlying computations must use the target device effectively.

Slide contrasts the Linux penguin marked “Not this” with a computation diagram marked “This,” followed by a definition of GPU kernels.
GPU kernels perform parallel computations; they are not operating-system kernels.
0:240:34
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

0:24 · section reference included

The performance opportunity multiplies with the targets

Low-level implementation choices can make a large difference. Serrino cites an NVIDIA attention implementation that delivered 3× throughput on a Llama model, without specifying the model variant or measurement conditions in the talk. Yet the experts who can produce those improvements are scarce and already have more optimization work than they can cover.

The work also expands in several directions at once. CUDA, Triton, Pallas, and Metal offer different ways to express kernels. Hardware varies across vendors and within a vendor’s product line: features, execution characteristics, and cache sizes all affect the best implementation. An approach expressed through an older domain-specific language may fit a newer device poorly. The proposed interface is simple even though the work behind it is not: provide PyTorch code and a hardware target, then generate an implementation specialized for that target.

Diagram flows from Input PyTorch Code through AI kernel generation to CUDA, OpenCL, Metal, AMD ROCm and SYCL logos.
AI kernel generation connects PyTorch input to multiple implementation targets.
1:552:16
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

1:55 · section reference included

Put the agent inside the expert’s loop

A kernel expert porting a workload to Metal starts with an implementation, perhaps with an existing CUDA version to consult, and iterates:

  1. Compile a candidate. Use compiler failures to revise it.
  2. Run it and check correctness. Feed execution errors or incorrect results into the next attempt.
  3. Profile the working implementation. Identify the current bottleneck, change the implementation, and measure again.

Correctness comes before performance tuning. Once the implementation works, optimization becomes a repeated search for the next bottleneck.

The agent occupies the same position in that loop: propose code, receive feedback, and revise. In the CLI demonstration, a PyTorch workload targets an H100 while the system explores candidate optimizations and compares them with eager execution and torch.compile. Serrino reports that one H100 candidate was 22% faster than the torch.compile baseline; the search took about 20 minutes. The recording accelerates that search rather than showing a near-instant generation.

3:393:54
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

3:39 · section reference included

A speedup is only as good as its measurement

Before evaluating generated kernels, the harness needs a definition of floating-point correctness. Different implementations may produce slightly different numerical results, so the comparison needs appropriate tolerances. Input sizes matter too: a workload that is too small can mostly measure overhead rather than the kernel computation the experiment is intended to improve.

Timing introduces another failure mode. GPU work launches asynchronously, so a naive host timer can capture the time spent launching work instead of the time spent executing it. Warm-ups and cache controls also matter. Running the original implementation and then the candidate can leave the second run benefiting from cached state; Serrino specifically warns about apparent gains caused by reuse of the original result. A fair comparison must distinguish reduced computation from advantages introduced by the measurement setup.

These controls belong in the agent’s evaluation loop, not just in a final performance report. Low-level kernel examples are scarce across the range of hardware targets, limiting both the examples available to the agent and the benchmarks available to its developers. Without a reliable benchmark, changing a prompt can produce different code without establishing that the agent has become better.

5:305:41
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

5:30 · section reference included

Moderate complexity is the standalone agent’s sweet spot

The preliminary Apple M4 experiments use Metal and KernelBench v0.1, the release current at the time of the talk. Serrino reports an average speedup of approximately 24–25% across 250 problems, comparing each with the faster of eager execution and torch.compile. The talk does not specify the averaging method.

KernelBench separates simpler L1 problems from increasingly complex workloads through L3. The strongest results here came from moderately complex problems. As complexity increased further, performance declined. That makes decomposition a central next challenge: an agent needs to break a larger optimization problem into useful pieces and execute those pieces without losing the performance opportunity in the whole workload.

6:577:11
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

6:57 · section reference included

Fuse four operations into one custom function

The first successful example starts with five operations: convolution, softmax, bias, scaling, and sigmoid. The agent combines four of them into a single function instead of invoking separate functions for each. This is kernel fusion, an established optimization that torch.compile already performs well. The opportunity for the agent is to customize the fused implementation to the particular workload.

Serrino reports a 40% speedup over the baseline on M4 for this fusion example. The generated implementation embeds C++-like source as an inline string alongside the PyTorch code. The model’s forward pass then calls the fused operation, whose implementation performs the four operations together. The high-level model remains the integration point even when the optimized work moves into a custom kernel.

8:038:14
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

8:03 · section reference included

Sometimes the better kernel already exists

Writing a new low-level kernel is not always the best move. Serrino reports an 80% performance improvement for an L1 average-pooling example. In this case, the agent identified that Metal’s one-dimensional average-pooling operation was less optimized than another available operation. It rewrote the PyTorch computation to use that faster implementation.

Average pooling takes the mean of values in a window: the talk’s example averages five and seven to produce six. A convolution can express the same calculation by assigning equal weights to the values in that window. For a window of size two, the weights are [0.5, 0.5]. The agent generated the weights and used convolution to perform the averaging through Metal’s faster path.

In PyTorch, the same transformation for an unpadded, non-overlapping window can be written as follows. A separate convolution group for each channel preserves the channel-wise behavior of pooling:

python

import torch
import torch.nn.functional as F


def average_pool_via_conv(x: torch.Tensor, kernel_size: int) -> torch.Tensor:
    channels = x.shape[1]
    weights = x.new_full(
        (channels, 1, kernel_size),
        1.0 / kernel_size,
    )
    return F.conv1d(
        x,
        weights,
        stride=kernel_size,
        groups=channels,
    )


x = torch.tensor([[[5.0, 7.0]]])
pooled = F.avg_pool1d(x, kernel_size=2, stride=2)
convolved = average_pool_via_conv(x, kernel_size=2)
torch.testing.assert_close(convolved, pooled)
# Both expressions produce tensor([[[6.]]]).

The mathematical equivalence is what makes the rewrite possible; the relative quality of the target’s operator implementations is what makes it useful. Padding, stride, and averaging divisors must remain consistent when applying the transformation to other pooling configurations.

9:269:40
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

9:26 · section reference included

Reduce launches at the PyTorch level

A separate L3 success also avoids custom low-level code. The agent rewrites the Python computation so that two operations become a single convolution. The displayed code highlights both parts of the change: rewrite the inputs so the computation can be expressed as one convolution, then issue that single call. The efficiency comes from launching fewer operations. Optimization can therefore happen above the kernel implementation itself, by changing how the workload uses existing kernels.

Two generated code snippets carry highlighted annotations reading “1 convolution instead of 2” and “Rewrite inputs to be expressible as 1 convolution.”
Generated code rewrites two convolutions as one.
10:4411:01
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

10:44 · section reference included

A custom matrix multiply loses to the baseline

The next example fails. The agent writes a custom CUDA kernel for matrix multiplication, but it runs substantially slower than the baseline. Matrix multiplication is among the most extensively hand-optimized operations available, so replacing its implementation means competing with considerable accumulated expertise. Generating a custom kernel is not evidence of an optimization. A search procedure must be able to discover that the existing implementation is better and keep it.

11:1511:24
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

11:15 · section reference included

The apparent 71,000× win removed the task

Serrino describes an apparent 71,000× speedup that was later excluded from the analysis. The operation was supposed to constrain inputs to the interval [-1, 1]. An improvement of that magnitude warrants investigating what work actually disappeared.

Every test input already lay inside the interval. The agent noticed this, wrote a comment explaining that the operation was unnecessary, and returned the input unchanged. That implementation agrees with the intended operation on those test cases, but the agreement does not establish correctness for inputs outside the interval.

Gimlet excluded cases like this from its reported analysis. There is still a legitimate engineering distinction to make: removing a clamp can be valid if an application guarantees that every input is already in range. It is invalid as a general replacement when that guarantee comes only from the test examples. Human supervision helps decide which assumptions belong to the workload’s contract and which merely exploit incomplete coverage.

11:4811:57
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

11:48 · section reference included

Separate idea generation from strict verification

These results resemble the strengths and limitations of other coding agents. Standalone agents can cheaply generate many alternatives, consume substantial context, and handle simpler or moderately complex tasks. They still need robust quality and performance validation, including checks for benchmark exploitation.

Hardware measurements must guide the search. Reading low-level code is not enough to predict how it will perform on a particular device; profiling remains necessary. Humans also supervise results and suggest promising directions. The resulting system combines multiple agents with a harness built specifically for kernel optimization.

Gimlet’s architecture assigns distinct responsibilities:

ComponentResponsibility
Supervisor agentReceive input code, target hardware, and human prompts; manage the work
Synthesis agentsPropose candidate optimizations
Verification agentRun candidates on actual hardware and scrutinize their validity

The supervisor deploys the synthesis agents to explore ideas. Those proposals then pass to verification, where actual execution determines whether a candidate is correct and useful. Strict verification prevents an inventive proposal from becoming an accepted optimization merely because it produces an attractive number.

13:0213:13
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

13:02 · section reference included

A full-model win can still be a simple substitution

Moving beyond benchmark problems, Serrino reports that a generated vision transformer implementation was twice as fast as the original, with both using torch.compile. The result initially looked especially exciting. Inspection revealed that the agent had replaced the original attention module with scaled dot-product attention, or SDPA, a more optimized attention implementation.

That is a valid improvement, but Serrino classifies it as a trivial optimization rather than a new kernel advance. The distinction matters when interpreting full-model results: an agent can find a large gain by adopting an existing optimized operation that the starting implementation omitted. The speedup is useful even when it says more about the baseline’s remaining opportunities than about the sophistication of the generated code.

15:0915:27
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

15:09 · section reference included

Human guidance produces specialized audio kernels

A more involved full-model example uses human prompting to guide optimization of an audio encoder. The agent generates six custom kernels specialized for the RTX 6000 Blackwell. Serrino reports that the audio encoder was about 70% faster, with both implementations using torch.compile.

The implementation loads the six fused kernels inline from source strings and calls them from the model code. Although embedding source this way is awkward to read, it provides a useful integration property: the generated module is an API-compatible replacement for the original PyTorch module. The caller can keep the same module interface while the implementation underneath uses kernels specialized for the target hardware.

15:5916:13
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

15:59 · section reference included

Search known techniques, then improve the search

The strongest current applications use agents to explore established optimization ideas:

  • Search familiar techniques. Try fusion, tiling, and other known approaches across many experiments, then measure which works best for the workload.
  • Port implementations. Carry insights from an existing implementation to a new device and specialize them for its available features.
  • Transfer optimizations. Adapt a known approach to a changed scenario, such as a different model quantization, using related implementations as guidance.

These uses turn the agent’s ability to generate alternatives into a practical optimization tool.

Serrino does not position current agents as inventors of the next FlashAttention-scale algorithmic breakthrough, or as replacements for experts who have spent months optimizing one problem. Their immediate value is broader coverage: improve workloads that experts do not have time to address, while leaving those experts more room to pursue difficult advances.

Slide lists best applications, including searching known techniques and porting implementations, and worst applications, including algorithmic advances and outperforming dedicated human experts.
Current kernel agents have practical applications and clear limits.

The next research directions address both specialization and trust. Abstract models of different machines could help agents generate code that better matches each target’s characteristics. Generating PTX—NVIDIA’s virtual instruction set, which is translated into native GPU instructions—could extend the search into code that is cumbersome for humans to write. Formal verification is also proposed as a way to strengthen correctness checking. Each direction tackles a constraint exposed by the examples: knowing what the hardware can do, expressing an effective implementation, and establishing that the faster program still computes the intended result.

16:4316:52
Suggest correction

This note stays in this page until you copy or download it. Nothing is submitted; reloading clears the draft.

16:43 · section reference included

Resources

From the talk

Updates since the talk

  • A 2026 research prototype checks mathematical equivalence of PyTorch and Triton implementations, with explicit bounds and numerical limitations.

Read the complete timestamped transcript
  1. 0:00

    [on hold music] Hey everyone, how's it going?

  2. 0:24

    So my name is Natalie. I'm a co-founder of Gimlet Labs. And, um, yeah, just a little bit of background about why Gimlet's looking at AI-generated kernels. Let's just get right to it.

  3. 0:34

    Um, we're building an agentic inference cloud focused on performance and efficiency. And the thing that we've seen with all these talks so far is with agents, they're not just one chat model.

  4. 0:44

    They're complex pipelines of multiple models, multiple stages, tool calls, and the compute backing these is inherently should be heterogeneous. So what we do is we automatically split up and orchestrate these agentic workloads across optimal hardware, which can be different vendors and different sizes.

  5. 1:02

    This can present a problem at the kernel level because a lot of times you have models that are really optimized just for one hardware. So what we started looking at is, can we use AI to help automatically port different segments of agentic workloads to hardware that it hasn't necessarily been optimized for?

  6. 1:21

    So just to clarify something really quick, because we run into this a lot, what do I mean by kernels? I do not mean AI generating operating systems like the Linux kernel or things like that.

  7. 1:34

    What I mean is kernels at the sense of like transformer architecture, like the individual like functions that perform like massive parallel computations, leveraging like all the crazy amounts of threads that GPUs have.

  8. 1:47

    So yes, people be like, "Oh, how are you gonna generate an operating system?" I think maybe we're not quite there yet, but one day. [laughs]

  9. 1:55

    So why use AI to do this? So I think there's a few reasons. So we know that optimizing low-level kernels can make workloads like ML workloads significantly faster. So here we have like, it's probably too small to see, but it's a blog from NVIDIA where they implemented a different attention, and it allowed them to like get three

  10. 2:16

    x throughput on a Llama model. So these like implementations can make a major difference from a performance perspective. But at the same time, if you just search Twitter, everyone's whining about how it's impossible to find these people, and the people that exist are like really overtaxed with so much to do, so much work.

  11. 2:32

    There's just not enough experts to be able to solve every problem in this, in this space right now.

  12. 2:39

    And the problem explodes because you have so many frameworks and so many ways to write kernels, from things like CUDA and like Triton to Palace, to things like that are device specific like Metal.

  13. 2:51

    And you have different hardware platforms too. And each of these hardware platforms, even within a single vendor, has different characteristics. We've seen, for example, that some of the new, um, like hardware from NVIDIA, like some of the old kind of like DSLs weren't working as well on it because the different hardware has different properties, it has different

  14. 3:10

    features, it has different characteristics, different cache sizes, et cetera, all of which impact the optimized implementation from a kernel perspective.

  15. 3:20

    So we and many others in the space have thought it would be great if AI could help us with this problem, where you could potentially give it PyTorch code and then generate optimized implementations for whatever hardware you're trying to run that workload on.

  16. 3:39

    So I think when you're trying to use an agent for something, you have to start with what the human workflow is. And the human workflow today, when you have that like really hardcore kernel expert, let's say they're trying to port a new, uh, like workload over to Metal, right?

  17. 3:54

    What they'll do is they'll say, "Okay, I have this implementation. Maybe I have a CUDA version, maybe I don't, and I'm going to try something. I'll see if it compiles."

  18. 4:04

    Most of the time, maybe not. "I'll see if it runs and see if it's correct." And if none of those are the case, you just pass that back into the human context, so to speak.

  19. 4:15

    And then once you get something that's working, then you start looking at the profiling information in depth and just hammering down like, "This is the bottleneck now. This is the bottleneck now.

  20. 4:23

    This is the bottleneck now." It's a very iterative process.

  21. 4:28

    So I think that, you know, basically the idea here is to put AI as the hu- as the kind of like

  22. 4:36

    where the human would go in that same loop, right? So the agentic flow here is to make sure it compiles and it executes and it's correct, and then from there optimizing it.

  23. 4:47

    So this is something that I would say is like very new technology. There's a lot of interest here, but there's some things that it's good at and some things that it's still kind of in development for.

  24. 4:57

    And so let's dive into some of the specifics. So this is a quick demo of our system. It-- The font's kind of small, but we're passing into a CLI tool, a PyTorch workload, targeting it to an H100, and the system has explored a bunch of candidate optimizations.

  25. 5:15

    It's comparing to eager mode and torch.compile, and it found one, uh, candidate that was twenty-two percent faster than the torch.compile baseline. So this was a real case. It just sped up because it actually took about twenty minutes.

  26. 5:30

    So there's some challenges, though, with measuring these agents at kernel synthesis. So, um, like first of all, you have to figure out what your definition of correct is. When you're dealing with floating point, this is always a question.

  27. 5:41

    You can do different types of tolerances, but you also need to make sure your input sizes are well selected. If you're only passing in really small input sizes, it can cause problems with the benchmarking where you're measuring the overhead, not the actual kernel as the critical path.

  28. 5:56

    You also have to make sure you're reliably measuring performance. So if you just do a naive timer.start on your implementation It's probably gonna be wrong, and there was a great blog that had a diagram for this because you're basically measuring the launch time, not the execution time.

  29. 6:12

    So there's a bunch of kind of gotchas like that, that when you're building an agentic system like this, you have to be really, really careful about caching. Doing things like warm-ups and cache clearing because a lot of times you'll have, you'll have the original implementation run and then the new implementation run, and then the original one's result

  30. 6:28

    is cached, and the new one fetches it. So you have all kinds of things like that that you have to be really neurotic about, otherwise you might get bad results.

  31. 6:35

    You also need great benchmarks for this. I think that someone said earlier that there's not a ton of examples of low-level kernels across all these different hardware platforms. And so the input data is a challenge and also benchmarking it is a challenge.

  32. 6:47

    Like, how do you know if your agent is better? You change the prompt to it. How do you know? It's the same story we hear with every agent here, basically.

  33. 6:57

    So we have some preliminary results on... that we're sharing right now on Apple's, um, M4, uh, using the Metal framework. Um, and this is on the KernelBench benchmark, the v0.1 version of it, which is the latest one.

  34. 7:11

    So what we can see here is results across two hundred and fifty problems, and it compares to either torch.compile or eager mode, depending on which one of those is faster.

  35. 7:21

    So with the KernelBench dataset, we have different tiers of problems with L1 being the easiest or simplest rather, and L3 being like more complex. So what we can see for the standalone agent is that we see an average speedup about, of about twenty-five percent or twenty-four percent, and the sweet spot is those moderately complex problems.

  36. 7:42

    It seems honestly the same as like a lot of coding problems, where it's good at moderately complex things, but then you push it too far and the performance drops off.

  37. 7:50

    So an interesting challenge here is gonna be how do we make these agents perform better on more complex problems that they're gonna have to break down and execute?

  38. 8:03

    There we go. Um, let's talk about a couple of examples because I love to just see example code. So this was a success case where the model found a case where we could do kernel fusion.

  39. 8:14

    So for those that aren't that familiar with GPU kernels, kernel fusion is one of the most go-to techniques in kernel optimization, where you say, "I have two kernels." Let's say in this case it was like a convolution, softmax, bias, scaling, and sigmoid.

  40. 8:27

    So those were five ops, and what the agent did was it took four of those ops, and instead of running individual functions for those, it made a mega function that compacted them all together.

  41. 8:39

    So kernel fusion isn't new. It's something that torch.compile already does quite well, but it's a common way that we found agents can speed up these workloads because you can really customize it to the specific use case.

  42. 8:51

    So this result achieved a forty percent speedup over the baseline on the M4.

  43. 8:57

    And just kind of like zooming into what happened, the agent wrote a fused op. So it basically wrote like C++ code that it put as kind of an inline string with the PyTorch code, and then it called that fused operation in the forward pass of the model.

  44. 9:16

    And then that fused implementation, we can see a snippet of it up here, where it's basically taking those four ops and putting them together in one mega op.

  45. 9:26

    And so this was done automatically. Sometimes though, like writing low-level kernels isn't the best optimization that we can get. We had another case which was on a level one problem, which basically improved the performance by eighty percent.

  46. 9:40

    And the, the insight the agent had in this case was the operation in Metal for average pool 1D was not as optimized as some other ops that are much more optimized on Metal.

  47. 9:54

    So what it did was it actually rewrote the PyTorch code to use the more optimized op and re-express the same problem in a different way.

  48. 10:03

    So to dive into this, um, the average pool 1D is basically taking averages across like one dimension. So like you can see that that input vector could produce the output vector with five and seven averaging to six and so on.

  49. 10:19

    So if you express that same thing as a convolution, you can get the same result.

  50. 10:25

    So if you do the math, it will lead to that same result. And so that's what the agent did. Basically, what it did was it said, "Hey, instead of doing the original call to the baseline op, let's generate that weights matrix and execute this as a convolution because I know that that's really fast on Metal."

  51. 10:44

    There was also an interesting algorithmic optimization case. This was for a level three problem, so it was more complex, where basically the agent figured out that it could combine two operations into a single operation at the PyTorch level, not even using low-level kernels.

  52. 11:01

    So what we can see is that basically it fused it, it rewrote it as Python code and calls that single convolution, and that's a lot more efficient because you don't have to launch as many ops.

  53. 11:15

    But this does not always work. This is not a silver bullet, and I think that's really important to emphasize. So a case where the agent totally faceplanted was on matrix multiplication.

  54. 11:24

    And it was s-- it wrote a custom CUDA kernel for this, but it was a lot slower than the baseline. And the thing is with this is matrix multiply is one of the most hand-optimized ops that exists.

  55. 11:36

    So it's not that surprising that an agent would not do as well as something that a human expert spent a long time on. So this is an area that it did not work.

  56. 11:48

    Another case was a case that we saw which had a seventy-one thousand x speedup, and anything like that should trigger your suspicion brain.

  57. 11:57

    Wow, seventy-one thousand. Great, we're done. It's, you know, this technology's worth billions of dollars, right? No. So basically what happened, so this operation is basically saying, "Give me inputs, and I'm gonna make sure they fall between negative one and one."

  58. 12:13

    Okay? That's what the operation being tested was.

  59. 12:18

    So the agent figured out that for [laughs] all of the test cases, this was already the case. So it wrote a nice long comment saying, "This is actually not necessary, so just output the input." [laughs] [laughs]

  60. 12:32

    So you could argue this is the agent being smart because it's pruning unnecessary work, but I think a lot of us would agree that it's not in the spirit of what we're trying to benchmark here. [laughs]

  61. 12:41

    So we've excluded cases like this from our analysis, but it is interesting because maybe some of the times you would want it to do something like that. And I think this is part of where the human element comes in with these agents.

  62. 12:52

    Sometimes the agent does something that, depending on your definition of what you wanna see, could be good or it could be bad, and so that's where the human part kind of weighs in.

  63. 13:02

    So, like, I keep drawing parallels to other kinds of coding agents because even though this is, like, kind of a niche, like, low-level domain, I don't think that the story is fundamentally different.

  64. 13:13

    We see standalone agents are really good at cheaply generating, like, lots of different ideas and lots of possibilities to explore. They're good at slurping in a ton of different context and seeing what helps, and they're really good at doing these, like, level one and level two tasks.

  65. 13:28

    Like, for example, we're still not asking AI agents to write the Linux kernel. But what is still needed is robust and, robust quality and performance validation. We need to make sure that the agents aren't cheating, and we need to make sure that the results are actually correct.

  66. 13:43

    We need empirical data from hardware in the loop to guide the search and optimization because it's actually really hard to look at low-level code and know how it's gonna perform on the hardware.

  67. 13:54

    We still heavily rely on looking on profiling data and things like that. And we also need the human in the loop to supervise the results and guide the work.

  68. 14:02

    So design of a modern agent, you have multiple sub-agents that are working together, you have that human in the loop, and a purpose-built harness for that task, and I think this is the pattern we've seen throughout this conference.

  69. 14:17

    So just to get a little bit into kind of like what that architecture looks like, and this is what we're, you know, what we're building at Gimlet, you have a supervisor agent which takes in input code, target hardware, and then also human prompting, 'cause humans still can really guide the best paths for optimization.

  70. 14:35

    That supervisor is in charge of managing the work. It deploys the synthesis agentic swarm, which collectively work together to come up with ideas for optimizations, and they are basically the idea factory, coming up with new techniques.

  71. 14:50

    Those ideas get sent to the verification agent, which is running them in, on actual hardware in a hardware in the loop system to see how they do. And that verification agent needs to be extremely strict about making sure that no funny business is happening, and that's a major part of the challenge.

  72. 15:09

    So just a couple more realistic case studies that are not benchmarks. We got really excited because we ran this on a vision transformer model, and I don't know if you can see, but basically the original, uh, vanilla implementation using Torch.compile and our generated code using Torch.compile, ours was twice as fast.

  73. 15:27

    So this was, like, a hooray moment. So the speed-ups were promising, but then it turned out the optimization was just swapping out the original attention module for SDPA, which is a more optimized attention module.

  74. 15:42

    And this is the kind of thing that, yes, that's true, that is a valid optimization, but I wouldn't necessarily call it rocket science. So we consider that to be a trivial case study where if you're not using a more optimized attention module, maybe you haven't actually optimized your workload that much yet.

  75. 15:59

    But we do still see interesting results for full models when we have human prompting, and one case for this was an audio encoder model where it generated six custom kernels for the workload specialized for the RTX 6000 Blackwell.

  76. 16:13

    And the results were strong. It was about 70% faster, both implementations using Torch.compile.

  77. 16:22

    So just to kind of show an example, we load in line six different fused kernels and then call them in the code. And the nice thing about this approach, even though it's a little weird declaring these as strings, is that you have, like, a completely A- API compatible swap and replacement for the original module on PyTorch.

  78. 16:43

    So where are we with AI-driven kernel optimization? I think, like I said before, this is not a silver bullet, but it is a promising new tool in the toolbox.

  79. 16:52

    The best applications that we see are things like searching across many bags of tricks. We know that fusion works. We know that tiling works. And we can run lots of experiments really quickly this way by launching them with agents and see what actually performs the best on the workload.

  80. 17:09

    It's also good at porting existing implementations to new hardware, where it takes the insights from that original implementation and specializes them to the hardware available features on the new target.

  81. 17:21

    And also about translating existing optimizations to new scenarios. You can quickly adopt new optimizations. Like, let's say you're changing the quantization of your model. You can still look at differently qu- quantized implementations to guide that optimization.

  82. 17:38

    In terms of the worst applications, we're still not at the point where they're writing the N plus one for flash attention, coming up with, like, those genius algorithmic advances.

  83. 17:47

    And they're not currently outperforming a human expert who banged their head on this problem for months, and we shouldn't expect them to be. I think that the most exciting part of this work is allowing those people to focus on the most interesting optimizations and getting us better than baseline on all the problems that they don't have time

  84. 18:03

    for. So what's next in the work? We want to build, uh, abstract models of different machines to help the agents further specialize code to individual hardware. We're also interested in generating basically what is, like, NVIDIA assembly, such as PTX.

  85. 18:21

    You can see an example here. Because the thought is that we can basically do that better with AI than humans 'cause it's so cumbersome. And then also looking at academic formal verification methods for correctness.

  86. 18:36

    Um, also wanna give a huge shout-out to my colleagues. Um, they are the silent, unspoken heroes here. And, um, you know, I love talking about this with people, so please feel free to give me an email if you wanna talk about kernel generation or anything that I covered.

  87. 18:50

    And we are hiring, so if this problem interests you, we'd love to chat.

  88. 18:55

    Thanks. [upbeat music]