---
title: "From CUDA to MLX: How K-Search Brings Decades of Kernel Expertise to Apple Silicon"
description: "K-Search, an LLM-driven evolutionary kernel search framework, was extended with an MLX backend and a structured CUDA-to-MLX translation layer."
url: "https://swe.quest/articles/from-cuda-to-mlx-how-k-search-brings-decades-of-kernel-expertise-to-apple-610eff297d34e6f2"
canonical: "https://bair.berkeley.edu/blog/2026/07/29/cuda-to-mlx-k-search/"
source: "Berkeley AI Research"
published: "2026-07-29"
difficulty: "hard"
kind: "Research"
reading_minutes: 11
tags: ["inference","performance","hardware","ai-coding","llms"]
---

# From CUDA to MLX: How K-Search Brings Decades of Kernel Expertise to Apple Silicon

A post on [Berkeley AI Research](https://swe.quest/sources/bair.md), published 2026-07-29, 11 min read, Research. Original: [https://bair.berkeley.edu/blog/2026/07/29/cuda-to-mlx-k-search/](https://bair.berkeley.edu/blog/2026/07/29/cuda-to-mlx-k-search/)

## Summary

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.

Written by swe.quest, not by the author.

**Difficulty:** Hard: written for specialists in the field

## Topics

- [Inference & serving](https://swe.quest/tags/inference.md) (AI & ML)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [Hardware](https://swe.quest/tags/hardware.md) (Infrastructure)
- [AI for coding](https://swe.quest/tags/ai-coding.md) (AI & ML)
- [LLMs](https://swe.quest/tags/llms.md) (AI & ML)

## Prerequisites

- GPU kernel programming ([easy posts on Hardware](https://swe.quest/tags/hardware.md?difficulty=easy))
- CUDA shared memory and warps
- FlashAttention
- state space models

## Keywords

K-Search, MLX, Apple Silicon, Metal, CUDA, FlashAttention-2, Mamba, mlx-lm

## Related posts

- [KernelEvolve: How Meta’s Ranking Engineer Agent Optimizes AI Infrastructure](https://swe.quest/articles/kernelevolve-how-meta-s-ranking-engineer-agent-optimizes-ai-infrastructure-d31b329bdf84a06a.md): Meta Engineering · 2026-04-02 · Hard · 14 min read · AI agents, Performance engineering, Hardware, Compilers, Recommendations & ranking
  KernelEvolve is Meta's agentic kernel-authoring system that treats kernel optimization as a search problem instead of one-shot LLM code generation.
- [We Got Claude to Build CUDA Kernels and teach open models!](https://swe.quest/articles/we-got-claude-to-build-cuda-kernels-and-teach-open-models-729005bab002af9e.md): Hugging Face · 2026-01-28 · Medium · 13 min read · AI agents, AI for coding, Evaluation, LLMs
  upskill 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.
- [ParallelKernelBench: Frontier LLMs can't write fast multi-GPU kernels (yet)](https://swe.quest/articles/parallelkernelbench-frontier-llms-can-t-write-fast-multi-gpu-kernels-yet-416eb937565c8218.md): Together AI · 2026-06-23 · Hard · 10 min read · AI for coding, Evaluation, Hardware, Performance engineering, Distributed systems
  ParallelKernelBench is a benchmark of 87 multi-GPU problems drawn from Megatron-LM, DeepSpeed, DeepEP, TensorRT-LLM, NeMo-RL and non-LLM workloads.
- [Custom Kernels for All from Codex and Claude](https://swe.quest/articles/custom-kernels-for-all-from-codex-and-claude-9d652cbc33fa9001.md): Hugging Face · 2026-02-13 · Medium · 9 min read · AI for coding, Performance engineering, Inference & serving, Hardware, Python
  Hugging 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.
- [Beyond Prompting: How Algorithmic Evolution Doubled our Training Speed](https://swe.quest/articles/beyond-prompting-how-algorithmic-evolution-doubled-our-training-speed-3669307c6d5f1431.md): Klarna Engineering · 2026-03-30 · Medium · 7 min read · Model training, Performance engineering, AI for coding, Payments & fintech
  Klarna 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.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
