cd /news/ai-agents/does-an-ai-agent-spend-more-writing-… · home › topics › ai-agents › article
[ARTICLE · art-180408] src=praveenperera.com ↗ pub= topic=ai-agents verified=true sentiment=· neutral

Does an AI agent spend more writing GPU kernels in Rust? I measured cuda-oxide against CUDA C++

Running 34 headless Claude Code sessions with Opus 5.5 across four GPU kernel tasks, a developer measured that cuda-oxide sessions cost about 1.9× as much as CUDA C++ on short tasks and 1.5× on the hardest task, with all kernels passing and running at the same speed. The extra cost is the agent learning cuda-oxide rather than writing the kernel: roughly $0.60 to $0.90 per session on short tasks and up to $1.83 on long ones, because material the agent read stays in its context. Kernel-making cost fell within the spread between sessions in both languages, and on the window-attention task cuda-oxide was cheaper to make at $0.47 versus $0.58 for C++.

recommendation

Budget for the agent's context, not just its output: cuda-oxide sessions cost 1.9× CUDA C++ on short tasks because read API material stays in context, so preload a skill file and prebuild the backend to cut setup tokens.

more in playbook: Controlling LLM cost
read7 min views2 publishedDec 2, 2026
Does an AI agent spend more writing GPU kernels in Rust? I measured cuda-oxide against CUDA C++
Image: source

Note: I ran these sessions on November 2, on a cuda-oxide version from before 0.4. cuda-oxide has shipped 0.4 and 0.5 since then, and both bugs below are now fixed. I haven’t rerun the tasks, but I expect most of the results to still hold.

After I wrote about moving speakrs onto Rust GPU kernels, a cuda-oxide maintainer asked whether anyone had measured how many tokens an agent spends writing kernels in cuda-oxide compared with CUDA C++. I hadn’t. So I ran 34 Claude Code sessions across four kernel tasks, half writing CUDA C++ and half writing cuda-oxide, and every one of them passed. Making the kernel cost about the same in both languages, and the kernels ran at the same speed. The extra cost of cuda-oxide is the agent learning it: about $0.60 to $0.90 a session on short tasks, and up to $1.83 on long ones, because what it read stays in its context. In total, cuda-oxide sessions cost about 1.9× as much as C++ on the short tasks and 1.5× on the hardest one.

The agents wrote every kernel. I wrote the tasks: the specs, the reference kernels to match or beat, and the evaluator that checks correctness and times each kernel on an RTX 5090.

Contents #

The result #

Task Runs per language C++ total C++ making cuda-oxide total cuda-oxide making cuda-oxide learning
3 small kernels, split-KV attention combine 4 $0.72 $0.72 $1.38 $0.77 $0.61
8 ViT kernels, within 1.10× of a tuned reference 5 $1.02 $0.99 $1.89 $1.19 $0.70
Window attention, within 1.10× of FlashAttention-2 5 $0.61 $0.58 $1.23 $0.47 $0.76
Window attention, at most 0.90× of the same reference 3 $3.73 $3.68 $5.47 $4.03 $1.44

Costs are means per session at API prices. Making cost is within the spread between sessions on every task. The widest gap is the eight-kernel task, at 1.2×, and C++ sessions alone ranged from $0.73 to $1.58 on it. On the window-attention task cuda-oxide was cheaper to make. From the second task on, the C++ sessions also read a skill file, and that is their $0.03 to $0.05 of learning.

How I measured it #

Every session is headless Claude Code with Opus 5.5 at high effort, in a fresh container with no GPU. The agent gets a spec, a reference to match or beat, and one tool, gpu-eval, which sends its PTX to an RTX 5090 and reports the ABI check, correctness against an f64 reference, a compute-sanitizer memcheck and timing against the reference. A task is done when gpu-eval prints RESULT: PASS.

The C++ sessions use nvcc 13.2. The cuda-oxide sessions use my fork of cuda-oxide, which was upstream as of late October plus 12 fixes from my ports, with the backend prebuilt so setup costs no tokens. Most of those fixes have since landed upstream. From the second task on, both get the same skill file of GPU kernel rules. The cuda-oxide copy adds notes on the cuda-oxide API, and the C++ copy swaps those for language-neutral build checks.

I split each session’s cost into learning and making. Learning is every API call that only reads cuda-oxide material or the skill, plus what the later calls pay to carry that material in their context. Making is everything else: writing, building, testing and tuning.

The four tasks get harder as they go:

  • 3 small kernels. A split-KV attention combine from another model I ported to cuda-oxide, at head dimensions 32, 64 and 256.
  • 8 ViT kernels. Layernorm, masked softmax, bias plus GELU, transpose, bilinear resize, RoPE with a QKV split, f32 to bf16 and a row gather, each within 1.10× of tuned C++ versions.
  • Window attention. One fused FlashAttention-style kernel for bf16 windows of 576 tokens, within 1.10× of a FlashAttention-2 reference I wrote for this. The reference usesmma.sync tensor cores,ldmatrix , double-bufferedcp.async and swizzled shared memory, and runs at about 197 TFLOP/s.
  • Window attention, 10% faster. The same kernel at most 0.90× the reference’s time. I ran this one twice: the first spec carried over a rule from the easier task that decided which sessions passed, so I dropped that round and use the rerun.

The kernels are the same #

I re-timed every final kernel together in one GPU session, three rounds each, so all the ratios come from the same state of the card.

The attention kernels are where I expected the languages to separate. They use the hardware features the simpler kernels never touch: tensor-core mma.sync, ldmatrix, async copies and swizzled shared memory. They didn’t separate. Both languages produced the FlashAttention-2 design with no stack frames, and the cuda-oxide kernels did all of it with cuda-oxide’s own intrinsics and no inline PTX.

Where the learning cost comes from #

The extra spend is context. A cuda-oxide session reads 26 to 76K tokens of cuda-oxide source, docs and examples before it writes a kernel, takes about twice as many turns, and then sends that material with every later call. Output tokens stay close to C++.

That makes learning a cost per session that grows with the session. On the short tasks it was $0.55 to $0.89. On the 10%-faster task, where sessions made 25 to 60 gpu-eval calls, it was $1.02 to $1.83. As a share of the total it still shrinks: cuda-oxide cost about 1.9× C++ on the short tasks and 1.5× on that one.

The skill helps. On the first task I also ran cuda-oxide without it, and those sessions paid $0.76 to $0.94 on average to learn, against $0.60 with it.

Most of the hard task’s cost is tuning after the pass #

On the 10%-faster task, every session passed within its first two full checks and then kept tuning, to 7 to 65 gpu-eval calls for C++ and 25 to 60 for cuda-oxide. The cheapest C++ session stopped early and cost $1.08. The most expensive kept going and cost $6.63. How long a session kept tuning moved its cost more than the language did.

I haven’t confirmed why they kept going. The gate sits close to the run-to-run timing noise, about ±1.5%, which rewards margin. The same skill on the 1.10× attention task stopped at the first pass.

Two cuda-oxide bugs #

The cuda-oxide sessions hit two problems the C++ sessions had no equivalent of. Both reproduced on the upstream version I tested, and I filed both. Both are fixed in cuda-oxide 0.4:

  • #1704 :libm::sqrtf pulls libm’s x86sqrtss inline assembly into device code, and codegen fails with “InlineAsm not yet implemented”.f32::sqrt worked.#1733 fixed it.
  • #1705 : a constant-trip loop with a large body, such as one that callserff , stays rolled, and any register array it indexes goes to a.local stack frame. nvcc and clang unroll the same four-step loop in C++ with no frame.#[unroll] worked around it. I fixed it in#1732 , which unrolls these loops the way clang does.

Both were in the skill for the later tasks, and none of the later final kernels has either.

Lessons learned #

For an agent, cuda-oxide costs a reading fee, not a writing fee. It makes kernels at the same cost as C++, and they run as fast. The premium is reading the API, well under a dollar a session on most of these tasks.

A short, dense API reference would cut that fee. The skill’s cuda-oxide notes cut learning by about a third on the first task. The agents still read 26 to 76K tokens of cuda-oxide each session, mostly source and examples. The less of that an agent has to read, the less it carries through every later call.

What this doesn’t cover #

  • One model at one effort level. Other agents may learn the API faster or slower.
  • Three to five sessions per language per task. Sessions in the same language varied by 2× or more on the harder tasks, so gaps under about 20% are noise.
  • The cuda-oxide sessions used my fork plus the skill. On the first task, upstream cuda-oxide without the skill cost 2.25× C++, against 1.9× for the fork with the skill, with about the same making cost.
  • These tasks run about 90 to 830 lines of kernel code. My full model ports have dozens of kernels and hit compiler bugs these tasks are too small to reach.

If you’ve measured this with another model or agent, I’d like to see your numbers.

── more in #ai-agents 4 stories · sorted by recency
── more on @cuda-oxide 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/does-an-ai-agent-spe…] indexed:0 read:7min 2026-12-02 · —