From CUDA to MLX: How K-Search Brings Decades of Kernel Expertise to Apple Silicon
K-Search, an LLM-driven evolutionary kernel search framework, was extended with an MLX backend and a structured CUDA-to-MLX translation layer. The layer has three parts: concept mapping tables (shared memory to threadgroup memory with a 32 KB limit, barriers, bandwidth differences), Metal-specific patterns such as simd_shuffle_xor reductions and the exp2 trick, and expert behaviours recast as assertions the search must preserve. With full translation context, an evolved attention kernel went from 0.26x to 0.97x of Apple's native MLX attention by rediscovering FlashAttention-2 techniques. An evolved Mamba SSM kernel reached ~20x prefill throughput over mlx-lm by using an associative parallel scan, while decode stayed roughly comparable. The bottleneck was the quality of hardware context given to the LLM, not its ability to write Metal code.
Related posts
- KernelEvolve: How Meta’s Ranking Engineer Agent Optimizes AI Infrastructure
Meta Engineering hardMasterKernelEvolve is Meta's agentic kernel-authoring system that treats kernel optimization as a search problem instead of one-shot LLM code generation. Monte Carlo tree search and evolutionary strategies explore hundreds of candidate kernels across Triton, CuTe DSL, FlyDSL, CUDA, HIP and MTIA C++. Nodes use configurable memory operators that draw on parent, sibling or no history. A retrieval-augmented, self-updating knowledge base supplies hardware documentation and distilled optimization skills, and an evaluation harness (TritonBench, PyTorch Profiler, NCU, Proton, MTIA Insight) feeds diagnoses of memory-bound, compute-bound or occupancy limits back to the LLM. Results include over 60% inference throughput gain for the Andromeda ads model on NVIDIA GPUs and over 25% training throughput gain on MTIA, achieved in hours rather than weeks of expert tuning.
- We Got Claude to Build CUDA Kernels and teach open models!
Hugging Face mediumAdeptupskill is a CLI that uses a strong teacher model (Claude Opus 4.5) to turn an agent trace into a portable Agent Skill (SKILL.md), auto-generates test cases, and measures skill lift on cheaper or local student models with and without the skill. Applied to building CUDA kernels with Hugging Face's kernel-builder, a ~520-token skill raised a quantized local GLM-4.7-Flash from 40% to 85% on the generated tests. The gains were not uniform across models. Some models used fewer tokens with the skill, while Opus gained no accuracy and spent more tokens, so each model should be evaluated on both accuracy and token cost before a skill is adopted.
- ParallelKernelBench: Frontier LLMs can't write fast multi-GPU kernels (yet)
Together AI hardMasterParallelKernelBench is a benchmark of 87 multi-GPU problems drawn from Megatron-LM, DeepSpeed, DeepEP, TensorRT-LLM, NeMo-RL and non-LLM workloads. In each problem a model must replace a PyTorch + NCCL reference with a CUDA kernel that moves data directly over NVLink using symmetric memory. Frontier models do poorly: the best (GPT-5.5) solves 28 problems zero-shot and only 31% beat the baseline even with three samples. Strong models fail mainly on rank coordination, collective ordering and the choice of transfer mechanism, and they rarely use TMA or NVLS. An agentic compile-test-benchmark loop lifted Gemini 3 Pro to 35 correct and 26 faster solutions before plateauing at about 20 steps, though models did produce some novel fast kernels, such as a fused vocab-parallel log-prob for NeMo-RL's GRPO.
- Custom Kernels for All from Codex and Claude
Hugging Face mediumAdeptHugging Face packaged CUDA kernel expertise (GPU architecture guides for H100/A100/T4, diffusers and transformers integration patterns, vectorized kernel templates, benchmark scripts) into an agent skill that lets Claude and Codex generate complete kernel-builder projects with PyTorch bindings. Agent-written RMSNorm kernels averaged 1.88x over PyTorch for LTX-Video and 1.94x for Qwen3-8B on H100 in BF16, with Qwen3 speedups growing from 1.58x at 128 tokens to 2.47x at 8192. End to end, LTX-Video gained only 6% (1.43x with torch.compile), consistent with RMSNorm taking about 5% of compute. The post also walks through building all PyTorch/CUDA variants with Nix and publishing to the Kernel Hub for one-line loading via get_kernel.
- Beyond Prompting: How Algorithmic Evolution Doubled our Training Speed
Klarna Engineering mediumAdeptKlarna used Google DeepMind's AlphaEvolve to evolve nearly 6,000 candidate versions of the PyTorch training pipeline for a large transformer trained on payment events. Over three weeks it raised throughput from 49 to about 97 samples per second under strict determinism, while also improving model quality. Early generations found mixed precision, async CPU-GPU transfers and on-device metric accumulation. Opening the forward pass and data loader to evolution led to deeper rewrites: direct scaled dot-product attention calls in place of PyTorch Transformer modules, and a pre-allocated contiguous dataset buffer sliced into batches. Key lessons: impose hard constraints such as reproducibility from the start (a non-deterministic TF32/cuDNN path reached 143 samples/s but could never be deployed), set plateau-based early stopping, and use a stronger LLM, which raised valid-program rates from about a third to 86–97%.