GPU kernel

A GPU kernel is a function written to run on a graphics processor, executed in parallel by many threads at once; an AI model runs on the chip as a long sequence of such kernels.

On a GPU, work is launched as kernels. Nvidia's CUDA programming guide defines a kernel as a function that, when called, is executed many times in parallel by many different threads, instead of once like an ordinary function. Each thread gets its own ID and handles its own piece of the data. Threads are grouped into blocks, and threads in the same block can share a small, very fast pool of on-chip memory and wait for one another.

Every operation in an AI model, from the large matrix multiplications at its heart to smaller steps such as softmax and normalisation, ends up as one or more kernels. Most developers never write one: frameworks such as PyTorch call libraries of kernels that chip makers and specialists have tuned by hand, such as Nvidia's cuBLAS for matrix maths. But the quality of those kernels decides how much of a chip's theoretical speed a model actually gets.

Often the limit is not arithmetic but moving data. FlashAttention, published in May 2022 by Tri Dao and colleagues, rewrote the attention step of transformers to work on tiles of data held in the GPU's fast on-chip memory, cutting trips to the slower main memory. It made GPT-2 training about three times faster at a sequence length of about 1,000 tokens while still computing exact attention, not an approximation. Combining several operations into one kernel, as FlashAttention does, is called kernel fusion.

Kernels are also part of why Nvidia is hard to displace. Years of kernels written and tuned for its hardware make up much of the CUDA advantage, and moving a model to another company's chips means making sure equivalent kernels exist and run well there. Tools try to make kernels easier and more portable: OpenAI released Triton, a Python-like language for writing GPU kernels, in July 2021, saying it could produce half-precision matrix multiplication kernels matching cuBLAS in under 25 lines of code.

Writing kernels has become a test for AI itself. KernelBench, a benchmark released in February 2025, asks language models to write fast, correct kernels for 250 PyTorch workloads. At release, the best reasoning models matched the speed of the standard PyTorch version in fewer than 20 percent of cases. When a lab reports that AI-written kernels beat human ones, the useful questions are whether the kernels were checked for correctness and what baseline they were compared against.

Common questions

What is a CUDA kernel?

A CUDA kernel is a GPU kernel written with Nvidia's CUDA platform: a function that the GPU runs in parallel across many threads, each handling part of the data. It is marked in code so that it runs on the GPU, and the programmer chooses how many threads and blocks to launch it with.

Why do GPU kernels matter for AI costs?

A model's speed on a chip depends heavily on how well its kernels use the hardware, especially how they move data between memory and the processing cores. Better kernels mean more work from the same GPUs, which lowers the cost of training and serving models. FlashAttention, a rewritten attention kernel, made GPT-2 training about three times faster.

What is kernel fusion?

Kernel fusion combines several operations that would normally run as separate kernels into one. Each separate kernel writes its results to the GPU's main memory and the next one reads them back, so fusing them saves memory traffic and time.

Can AI write GPU kernels?

It can, with mixed results. On the KernelBench benchmark, released in February 2025, the best models at the time produced kernels that were both correct and as fast as the standard PyTorch versions in fewer than 20 percent of cases. Reported successes need careful checks for correctness and fair comparisons.

Finding more

Search for "CUDA programming model kernels", "FlashAttention", "Triton GPU language" and "KernelBench" to see how kernels are written and measured. The best sources are chip makers' programming guides, the original papers on arXiv and the documentation of open-source projects such as PyTorch and Triton. Treat speed-up claims with care unless they name the hardware, the baseline and how correctness was checked.

Working out what this means for your business?

Aileron Shift builds the systems behind this site: AI newsrooms that research, write and publish on their own, marketing automation and WordPress hosting for companies that need to move faster than their competitors.