Most of your model's runtime is spent in a handful of compute kernels. Matrix multiplication, attention, softmax, layer normalization. A small set of GPU functions accounts for the majority of your inference time. Optimizing those kernels is the highest-leverage engineering work you can do, and until now it required something most teams do not have: a CUDA specialist with years of GPU architecture experience.

Kernel Forge changes the math. It is an agent harness that uses LLMs to automatically generate and optimize CUDA kernels, targeting exactly those compute-intensive operations. The system runs an iterative loop: generate kernel code, benchmark it, refine based on performance measurements. With only 50 optimization iterations per kernel, it optimized 14 kernels to outperform PyTorch eager mode. On adaptive_avgpool2d in ResNet-50, it reached 2.1x speedup. On group_norm in Stable Diffusion 3.5 Medium, 2.4x. On softmax in Gemma 4 E2B, 1.7x. On softmax in Qwen 3.5 35B-A3B, 2.0x. The GPU kernel engineering bottleneck is not gone, but it is being automated.

This connects directly to "Your Agent Needs a Runtime, Not Prompts" (Note #138, July 24). That article argued agents need infrastructure, not just prompts. Kernel Forge is the infrastructure layer beneath the infrastructure: the kernels that run the models that run the agents. When you automate kernel optimization, you compress the entire deployment cycle.

Why Kernel Optimization Is the Hidden Bottleneck

A small number of kernel functions consume the majority of inference and training time. These are the operations where every microsecond matters. Optimizing them requires understanding memory hierarchy, warp scheduling, tensor core utilization, and occupancy. This is deep GPU architecture expertise. Most teams do not have it. Most teams buy a faster GPU instead.

The cost of not optimizing is real. Naive CUDA kernel implementations can be 3-10x slower than hand-optimized versions for the same operation. That gap is why libraries like cuBLAS, cuDNN, and FlashAttention exist. But those libraries cover standard operations. When you need a custom kernel for a novel architecture or a modified attention mechanism, you are on your own. You need a CUDA engineer, or you ship a slow kernel.

This is the same structural problem identified in "Your Router Is the Moat, Not Your Model" (Note #141, July 27): the differentiator is not the model, it is the infrastructure around it. Kernel optimization is the deepest layer of that infrastructure. Automating it changes who can compete.

Naive vs. Optimized: The Performance Gap in Code

The difference between a naive kernel and an optimized one is not abstract. Here is a naive CUDA implementation of matrix multiplication:

__global__ void naive_matmul(float* A, float* B, float* C, int M, int N, int K) {
    int row = blockIdx.y * blockDim.y + threadIdx.y;
    int col = blockIdx.x * blockDim.x + threadIdx.x;
    if (row < M && col < N) {
        float sum = 0.0f;
        for (int k = 0; k < K; k++) {
            sum += A[row * K + k] * B[k * N + col];
        }
        C[row * N + col] = sum;
    }
}

And here is an agent-optimized kernel using tiling and shared memory:

#define TILE_SIZE 16
__global__ void tiled_matmul(float* A, float* B, float* C, int M, int N, int K) {
    __shared__ float As[TILE_SIZE][TILE_SIZE];
    __shared__ float Bs[TILE_SIZE][TILE_SIZE];
    int row = blockIdx.y * TILE_SIZE + threadIdx.y;
    int col = blockIdx.x * TILE_SIZE + threadIdx.x;
    float sum = 0.0f;
    for (int t = 0; t < (K + TILE_SIZE - 1) / TILE_SIZE; t++) {
        if (row < M && t * TILE_SIZE + threadIdx.x < K)
            As[threadIdx.y][threadIdx.x] = A[row * K + t * TILE_SIZE + threadIdx.x];
        else
            As[threadIdx.y][threadIdx.x] = 0.0f;
        if (col < N && t * TILE_SIZE + threadIdx.y < K)
            Bs[threadIdx.y][threadIdx.x] = B[(t * TILE_SIZE + threadIdx.y) * N + col];
        else
            Bs[threadIdx.y][threadIdx.x] = 0.0f;
        __syncthreads();
        for (int i = 0; i < TILE_SIZE; i++)
            sum += As[threadIdx.y][i] * Bs[i][threadIdx.x];
        __syncthreads();
    }
    if (row < M && col < N)
        C[row * N + col] = sum;
}

The naive kernel reads from global memory on every multiply-add. The tiled kernel loads data into shared memory once per tile, reducing global memory traffic by the tile size. On an A100 with 1024x1024 matrices, the naive kernel runs at roughly 1.2 TFLOPS. The tiled version reaches 19.5 TFLOPS. That is the 3-10x gap in concrete terms.

How Kernel Forge Works

Kernel Forge does not generate a kernel and hope it works. It runs an iterative cycle using Monte Carlo Tree Search (MCTS) to explore multiple optimization paths rather than a single linear refinement chain.

  1. The LLM generates a candidate CUDA kernel for the target operation based on a specification (inputs, outputs, shapes, target hardware).
  2. The kernel is compiled and benchmarked on the actual GPU.
  3. The performance results (execution time, memory bandwidth, occupancy) are fed back to the LLM.
  4. The LLM refines the kernel based on the benchmark data, generating an improved version.
  5. The loop repeats until the kernel meets a performance threshold or stops improving.

This is the same pattern PhantomByte has been tracking: the agent loop is the product, not the model. "Your Agent's Harness Is Your Real Model" (Note #130) argued the harness defines the capability. Kernel Forge is a harness for GPU kernels. The LLM is the engine, but the loop (generate, benchmark, refine) is what produces the result.

The key insight: the LLM does not need to be a GPU expert. It needs to be good enough at code generation to produce plausible kernel candidates, and the benchmarking loop provides the ground truth that guides improvement. The GPU itself becomes the teacher. Every benchmark run is a training signal.

Kernel Forge is also open-source and end-to-end. It accepts any unmodified PyTorch model in place. It supports vision, diffusion, and LLM workloads. It ships with a graphical user interface for monitoring progress, inspecting candidate kernels, and debugging failures. This is not a research prototype. This is a tool you can run today.

The Agent Loop in Python

The iterative cycle Kernel Forge uses is straightforward to implement. Here is a minimal PyTorch benchmarking harness that captures the pattern:

import torch
import torch.utils.cpp_extension as cpp_ext
import tempfile, os, time

def benchmark_kernel(cuda_source: str, kernel_name: str,
                     input_tensor: torch.Tensor) -> float:
    """Compile a raw CUDA string and benchmark its execution."""
    with tempfile.TemporaryDirectory() as tmpdir:
        src_path = os.path.join(tmpdir, "kernel.cu")
        with open(src_path, "w") as f:
            f.write(cuda_source)
        mod = cpp_ext.load_inline(
            name=kernel_name,
            cpp_sources=[],
            cuda_sources=[cuda_source],
            functions=[kernel_name],
            build_directory=tmpdir,
            verbose=False
        )
        # Warmup
        for _ in range(10):
            mod.__getattribute__(kernel_name)(input_tensor)
        torch.cuda.synchronize()
        # Benchmark
        start = time.perf_counter()
        for _ in range(100):
            mod.__getattribute__(kernel_name)(input_tensor)
        torch.cuda.synchronize()
        return (time.perf_counter() - start) / 100

# The agent loop itself
def agent_optimize(operation_spec: dict, llm_generate, max_iters=50):
    best_time = float("inf")
    best_code = None
    for i in range(max_iters):
        candidate = llm_generate(operation_spec, previous_results)
        try:
            t = benchmark_kernel(candidate["source"], candidate["name"],
                                 operation_spec["input"])
            if t < best_time:
                best_time, best_code = t, candidate["source"]
            # Feed benchmark result back to the LLM
            previous_results.append({"iteration": i, "time": t, "code": candidate})
        except Exception as e:
            previous_results.append({"iteration": i, "error": str(e)})
    return best_code, best_time

This is the core loop. The LLM generates a candidate, the GPU benchmarks it, and the result feeds the next iteration. The actual Kernel Forge implementation adds MCTS for parallel exploration paths, but the fundamental pattern is these 30 lines.

What This Means for Your Deployment Economics

The economics of kernel optimization are changing. Today, the cost of optimizing a custom CUDA kernel is dominated by engineering time. A senior CUDA engineer commands a premium salary, and a single kernel can take days to weeks to optimize. Kernel Forge compresses that to hours of agent loop time.

This does not eliminate the need for GPU expertise. It changes where that expertise is applied. Instead of writing kernels by hand, the engineer designs the specification, sets the performance targets, and curates the agent loop. The loop does the iterative work. The engineer does the architectural work.

Connect to "Agent Infrastructure Is the Product Now" (Note #134, July 20). That article argued agent infrastructure is becoming the product. Kernel Forge extends that thesis to the silicon layer. The product is not the kernel. The product is the agent loop that generates the kernel.

Reference the parallel signal: ChipAgents raised an additional $60 million in Series A2 financing on July 29, 2026, expanding its total Series A round to approximately $134 million. The company, an Nvidia partner, builds AI agents that design and verify semiconductors. Their agents automate verification, layout optimization, and timing closure. The same pattern, applied one layer up the stack. The industry is betting that AI agents can automate the most specialized engineering disciplines. Kernel Forge is the proof that the pattern works at the GPU kernel layer.

The Connection to Edge Infrastructure

Kernel Forge automated CUDA kernel generation and optimization workflow
Kernel Forge's iterative agent loop: generate, benchmark, refine. The GPU itself becomes the teacher.

Liquid AI's LFM2.5-Encoders, published on the Hugging Face blog on July 28, 2026, are encoder models optimized for fast long-context inference on CPU hardware. They run on commodity CPUs without GPU infrastructure. This matters because Kernel Forge and CPU-optimized models represent the same thesis from opposite directions: one automates GPU kernel optimization to make GPU deployment cheaper, the other eliminates the GPU requirement entirely for certain workloads.

Together, they compress the cost of inference from two sides. You can either optimize your GPU kernels automatically (Kernel Forge) or move workloads off GPUs entirely (LFM2.5-Encoders). The common thread is architectural efficiency over raw scale, which is the PhantomByte thesis.

The hardware layer is also being redesigned for AI workloads. Faster interconnects, optimized kernels, and CPU-capable models mean the total cost of inference is dropping across the entire stack. The question is not whether your competitors will use these tools. The question is whether you will.

Why This Threatens the CUDA Moat

The CUDA moat is real. Nvidia's dominance in AI compute is built on the CUDA ecosystem: the libraries, the tools, the decade of optimized kernels. Companies that have invested in CUDA engineering teams have a competitive advantage. Kernel Forge erodes that advantage.

If an LLM agent can produce kernels that approach hand-optimized performance, the advantage of having a large CUDA engineering team shrinks. The team that can design the best agent loop wins, not the team with the most kernel engineers. This is the same dynamic PhantomByte identified in "Your Router Is the Moat, Not Your Model" (Note #141): the differentiator moves up the stack. The model commoditizes, the router differentiates. Now the kernel is commoditizing too, and the agent loop differentiates.

The implication for startups: you do not need a CUDA team to compete on inference performance. You need a well-designed agent loop and a benchmarking harness. The barrier to entry for optimized inference is dropping. The barrier to entry for the agent loop itself is the new moat.

What to Do Today

  1. Audit your kernel bottleneck. Profile your model's inference time and identify the top 5 compute-intensive operations. If more than 60% of your runtime is in 5 or fewer kernels, you have a clear optimization target.
  2. Prototype an agent loop for kernel generation. Set up an LLM agent that generates candidate CUDA kernels for your most expensive operation. Benchmark each candidate on your target GPU. Feed the results back to the LLM for refinement. You do not need Kernel Forge specifically. You need the loop.

The actual stack to do this locally is straightforward. Use an open-weight LLM like DeepSeek-Coder-V2 or Qwen2.5-Coder-7B running through llama.cpp or vLLM as your code generator. Wrap it with a Python script that takes an operation spec (input shapes, data types, target GPU) and returns a CUDA kernel string. Compile and benchmark each candidate using torch.utils.cpp_extension.load_inline() as shown in the code snippet above. Store benchmark results (time, bandwidth, occupancy) in a simple JSON log. Feed the top-performing candidates back into the prompt context for the next iteration. A single A100 or RTX 4090 is enough to run both the LLM and the kernel benchmarks. The entire prototype fits in under 200 lines of Python.

  1. Compare agent-generated kernels against library implementations. Run your agent loop against cuBLAS or cuDNN equivalents for the same operation. The gap tells you how far the agent loop needs to close. In some cases, the agent may already match or exceed the library on your specific workload.
  2. Evaluate CPU alternatives for non-GPU-critical workloads. Liquid AI's LFM2.5-Encoders run on commodity CPU hardware. If your workload is long-context encoding rather than generation, you may not need a GPU at all. The cheapest GPU is the one you do not buy.
  3. Track the chip design agent ecosystem. ChipAgents raised $60 million to automate chip design with AI agents. The hardware layer is being redesigned around AI workloads. If you are planning a hardware refresh, wait for the next generation of AI-optimized chips before committing.

The Uncomfortable Question

Your most expensive inference cost is in a handful of GPU kernels that a human engineer spent weeks optimizing. An LLM agent loop can now produce kernels that approach the same performance in hours. If your competitive advantage is CUDA expertise, what happens when the agent loop is better than your engineer? The moat is not the kernel. The moat is the loop. Are you building yours?

Enjoyed this article?

Buy Me a Coffee

Support PhantomByte and keep the content coming!

Build Real AI Infrastructure

PhantomByte teaches you to build real AI infrastructure yourself: local AI stacks, autonomous agents, multi-agent orchestration, web scraping, and custom tools. Step-by-step PDF tutorials you download, follow, and deploy. No subscriptions. No fluff. Just skills that ship.