Profile and tune a CUDA kernel with an agent
They used a LangGraph agent to test CUDA kernel tweaks, verify results, and profile candidates with Nsight.
- What they did
- They started with a workload description or their own kernel, reference, and test cases. The agent suggested changes to the kernel and launch settings, while a C++ harness compiled each version with NVRTC and ran it through the CUDA Driver API. Python then compared results with NumPy and timed each candidate; if a version failed, the agent tried to repair it within the allowed iteration budget. Optional steps added Nsight Compute profiling and checks against NVIDIA documentation.
- How it went
- The README showed float32 GEMM running on an RTX 3060 Laptop GPU, and a second run picked up from the best kernel found earlier. It did not report speedup figures or compare the result with cuBLAS.
- Tips
- Be careful with generated scripts: they run on your machine without sandboxing, and API calls are billed to you. Treat any generated reference output as a helpful check, not as a full proof of correctness.
Try it yourself with Claude Code
I want to improve a CUDA kernel in [file path] for [operation]. Use a test harness to compile candidate versions with NVRTC, run them through the CUDA Driver API, compare outputs against [reference check, e.g. NumPy], and benchmark each one. Propose one change at a time, run Nsight Compute profiling when useful, and keep only versions that pass correctness. If a candidate fails, try to fix it within the current iteration limit. Pause and ask for my approval before any step that would send code, submit jobs, delete files, or make other irreversible changes. Finish by summarizing the best kernel, launch settings, and measured timings.
Fill in the [brackets]. Agents can make mistakes, so review anything before it is sent, paid or deleted.
Get 3 agent uses like this every morning
With the day's top AI news. Free, and one click to unsubscribe.
Related agent uses
Let an AI agent inspect a Windows crash dump
Use MCP to give an AI agent structured crash details from a Windows dump so it can track down the fault and propose a fix.
Review a feature and pass the findings to an engineer
One developer had an agent inspect a feature for problems, then handed the issue list to an engineer whose agent fixed most of them.
Send blocked jobs to whichever model can handle them
A commenter used a shared policy file and SQL task board to move rejected tasks from a local model to another model.
Revive old apps and sketch new ones with a coding agent
Terence Tao used a coding agent to port old Java applets to JavaScript and to build two new math visualizations in conversation.
Use agents to benchmark and tune Rust performance
Have an agent measure Rust code, make one optimization at a time, and keep only changes that improve runtime.
Add simple forgetting to agent memory
A developer added a basic forgetting layer to an agent’s memory and said it worked extremely well right away.