Determine 1: CUDA-to-MLX optimization translation map. CUDA optimization information may be translated into architecture-native MLX methods relatively than copied instruction-for-instruction.
We face a brand new epoch in computing. {Hardware} is altering quickly — not simply sooner GPUs, however a rising vary of chips from completely different distributors, every with its personal structure and sometimes tailor-made to particular AI workloads. Software program is altering simply as quick, and AI coding instruments now generate in minutes what took months of effort just a few years in the past.
With a lot of computing now centered on AI, GPU kernels are an important part of its success. These are the low-level applications that run contained in the GPU, and writing environment friendly ones is much from apparent — it takes years of experience to get proper. Transferring a kernel from one vendor’s {hardware} to a different is tougher nonetheless, and sometimes means rediscovering the identical optimizations from scratch. The CUDA ecosystem, for instance, has gathered a long time of hard-won kernel experience: hand-tuned implementations of consideration, state house fashions, and different essential operations representing 1000’s of engineering hours. Newer {hardware} ecosystems (Apple Silicon, customized AI accelerators, and others) are rising quick however lack this depth.
On this work we ask whether or not that experience may be transferred routinely. We constructed on Ok-Search, an evolutionary kernel search framework launched by Cao et al. at Berkeley Sky Lab that makes use of AI to optimize GPU kernels, and prolonged it with a backend for MLX — Apple’s machine-learning framework for its personal Apple Silicon chips. We developed a novel structured CUDA-to-MLX translation layer that lets Ok-Search take present CUDA kernels as a information base and adapt them into high-quality GPU kernels for Apple Silicon, relatively than rebuilding from scratch.
We present that our strategy reaches near-expert stage efficiency on Apple Silicon with 0.97x speedup in comparison with the native MLX Consideration kernel, and as much as a 20x prefill speedup over the neighborhood mlx-lm implementation on the Mamba SSM kernel; we report the numbers, and the way a lot of the acquire comes from the interpretation layer, within the sections beneath. Though we give attention to MLX kernels for Apple Silicon, the strategy isn’t particular to MLX and applies to any ecosystem the place CUDA experience is transferable.
Why MLX?
Apple’s MLX framework has seen exceptional adoption since late 2023. With Apple Silicon in tons of of hundreds of thousands of MacBooks and Mac Studios, MLX permits native AI inference with out cloud prices. The unified reminiscence structure makes it particularly enticing for mid-sized fashions (7B–70B parameters on M sequence chips).
But beneath this momentum lies a big hole: many performance-critical kernels that the NVIDIA ecosystem takes without any consideration: paged consideration, optimized SSM scan kernels, fused MoE routing are both absent or naive with out hardware-specific tuning. MLX runs fashions accurately however usually leaves vital efficiency on the desk.
This hole is what motivates the remainder of this publish.
What’s Ok-Search?
Ok-Search is an evolutionary kernel optimization framework initially developed by our first writer Shiyi Cao at UC Berkeley Sky Lab. Given a naive kernel and a {hardware} specification, it runs an iterative optimization loop: an LLM causes about which optimizations to attempt subsequent, a code-writing mannequin generates candidate kernels, and people candidates are compiled and benchmarked on actual {hardware}.
Measurements feed again into the search, which retains refining, pursuing promising instructions and dropping lifeless ends till efficiency converges.
Algorithm 1: Ok-Search by way of co-evolving world fashions. The search alternates between choosing essentially the most promising motion, instantiating and evaluating code till enchancment stagnates, and evolving the world mannequin by insert, replace, and prune operations. Tailored from Cao et al. (2026).
Search is grounded by a Spec: a domain-specific doc encoding {hardware} guidelines, optimization patterns, and mathematical constraints which retains generated code from hallucinating invalid primitives and ensures candidates will truly compile and run effectively.
In our runs, a single mannequin (Gemini 3.5 Professional Preview) performs each roles: it maintains the reasoning state and writes the kernels. The reasoning half is prompted as a “GPU kernel efficiency engineer” and requested to work by a hard and fast evaluation earlier than proposing something: classify the kernel (discount, scan, consideration/softmax, …), rewrite the reference computation in canonical type, map out knowledge format and entry patterns, and hypothesize the seemingly bottleneck (bandwidth, latency, compute, or synchronization) in every runtime regime. Solely then does it emit candidate optimizations, every as a single change implementable in a single iteration.
We name the persistent reasoning state a world mannequin. Quite than a flat listing of issues to attempt, it’s a resolution (prefix) tree: every root→leaf path composes a full optimization plan, and sibling branches are competing options. Each node is scored — an overall_rating in [0, 10], a confidence in [0, 1], and per-node impacts on reminiscence bandwidth, register strain, and compute/{hardware} match — so the search can rank partial plans and develop essentially the most promising ones. The tree persists and grows throughout rounds: refining an concept provides a baby node relatively than overwriting its mum or dad, and if the very best rating fails to enhance for just a few rounds (a stagnation window) the search backs off to discover an alternate department. A single node, because it seems mid-run on the eye kernel, appears like this:
{
"motion": "Substitute the threadgroup-memory softmax discount
with a register-only discount: every SIMD group
owns 8 question rows and reduces throughout lanes with
simd_shuffle_xor, eradicating a threadgroup_barrier.",
"difficulty_1_to_5": 4,
"impacts": {
"memory_bandwidth": 8,
"register_pressure": 4, // danger: spill if Br > 8
"compute_hw_fit": 9 // SIMD width 32; hold tile 8x8
},
"overall_rating_0_to_10": 8,
"confidence_0_to_1": 0.7
}
Itemizing 1: Instance Ok-Search world-model node. Every candidate optimization information a concrete motion, estimated {hardware} impacts, an general precedence ranking, and the mannequin’s confidence.
Determine 2: Overview of Ok-Search. The framework operates on a Search State $S_t$ structured as a search tree. The tree consists of Closed nodes (blue, visited states with connected program like $x_{12}$) and a Frontier of Open nodes (orange, pending hypotheses like $u_{13}$). The workflow iterates by three phases: (1) Motion Choice, the place essentially the most promising motion node is retrieved from the frontier primarily based on world mannequin estimated precedence rating $V$; (2) Native Refinement, the place a stochastic coverage $pi_{mathrm{code}}$ samples concrete implementations till stagnation; and (3) World Mannequin Replace, the place the LLM causes over the trajectory to replace the search tree by way of Insert (including new actions), Replace (adjusting $V$, e.g., $u_{11}$ dropping from 0.9 to 0.6), and Prune (eradicating much less promising nodes like $u_{10}$).
The unique Ok-Search paper evaluated this search technique on CUDA kernels from FlashInfer. Throughout GQA decode, MLA decode, MLA prefill, and MoE, Ok-Search improved extra persistently than OpenEvolve and ShinkaEvolve over the identical 120-iteration finances. These outcomes set up the search framework we construct on right here; the rest of this publish asks whether or not its optimization information can switch past CUDA.
Determine 3: Foremost outcomes from the unique Ok-Search paper. Throughout three runs, Ok-Search achieves stronger best-so-far search scores, per-workload kernel efficiency, and speedup distributions than OpenEvolve and ShinkaEvolve on 4 FlashInfer CUDA kernels. Reproduced precisely from Cao et al. (2026).
Constructing an MLX backend
To convey Ok-Search to Apple Silicon, we first constructed a local MLX backend. We applied a full MLX-specific activity adapter for Ok-Search, together with:
- An MLX activity backend in
k_search/duties/dealing with kernel compilation and execution on Apple Silicon by way of MLX’s Steel/C++ APIs. - Up to date kernel generator prompts for writing and modifying Steel/MLX kernels.
- MLX-specific benchmarking integration utilizing
mlx.coremeasurement utilities.
Translating CUDA experience to MLX
Nonetheless, the extra attention-grabbing problem was not merely operating Ok-Search on MLX. The important thing perception is that knowledgeable CUDA kernels encode a long time of optimization information that’s transferable to Apple GPU should you can bridge the conceptual hole. Merely handing an LLM a CUDA kernel and asking it to port it’s not sufficient: with out deep {hardware} context, it produces code that’s syntactically legitimate however architecturally unsuitable (unsuitable tile sizes, invalid primitives, mismatched reminiscence assumptions).
Our translation layer consists of:
- Idea mapping tables: A structured glossary of CUDA primitives and their MLX/Steel equivalents with exhausting constraints. For instance:
__shared__maps to Steelthreadgroupreminiscence however with a tough 32 KB restrict (vs. NVIDIA’s 48 KB)warp_reducemaps to MMA (most well-liked)__syncthreads()turns intothreadgroup_barrier(mem_flags::mem_tg)- H100’s ~3.35 TB/s HBM3 maps to M3 Max’s ~400 GB/s unified DRAM a bandwidth distinction that reshapes which optimizations are price pursuing.
- MLX-specific hints and patterns: Concrete code-level patterns for operations with no direct CUDA equal, resembling register-based row reductions utilizing
simd_shuffle_xorin an 8×8 MMA tile format, or the “exp2 trick” (changing $exp(x)$ with $exp_2(x log_2 e)$) for sooner softmax on Apple’s quick $exp_2$ {hardware} instruction. - Reusable assertions: Professional kernel behaviors reframed as properties the evolutionary search should protect, relatively than code to repeat.
Matching knowledgeable kernel efficiency: the Consideration kernel
We consider three configurations of an MLX consideration kernel for Apple Silicon: (1) a naive baseline, (2) pure evolution with no extra offered context, and (3) a full context translation layer, which provides the optimizer with architecture-specific implementation information extracted from high-performance kernels (e.g., FlashAttention-2), letting the evolutionary search motive about implementation methods relatively than ranging from a naive kernel. Collectively, these three configurations allow us to isolate the precise impression of the interpretation layer.
Determine 4: Efficiency scaling of the Consideration Kernel by stacked optimizations. The “Full Context” configuration efficiently discovers and implements superior methods like double buffering and loop unrolling, attaining near-expert efficiency.
The bounce from 0.26× to 0.97× the pace of Apple’s state-of-the-art consideration kernel — illustrates how a lot the interpretation layer issues. With full context, the developed kernel independently discovers the important thing optimizations in FlashAttention 2: threadgroup reminiscence tiling, on-line softmax, Ok-transposition for reminiscence entry, and the exp2 trick. The final of those replaces each softmax exponential with a base-2 exponential,
[e^x = 2^{x log_2 e},]
which is precise and lets the kernel use Apple’s quick quick::exp2() {hardware} instruction straight as a substitute of paying for a base conversion at runtime.
A 20× sooner prefill: the Mamba SSM kernel
To guage whether or not Ok-Search generalizes past consideration kernels, we utilized it to the state-space mannequin (SSM) kernel utilized by Mamba. Not like consideration, the computational bottleneck is a recurrent state replace relatively than a softmax, offering a considerably completely different optimization problem. We evaluate the developed implementation towards the neighborhood MLX implementation (mlx-lm) and the PyTorch reference implementation (mamba.py) on an M1 Max.
Evaluated on mamba-370m f16, M1 Max 64GB:
| Metric | mlx-mamba (ours) | mlx-lm (neighborhood) | mamba.py |
|---|---|---|---|
| Decode | 152 tok/s | 116 tok/s | 40 tok/s |
| Prefill L=512 | 5,751 tok/s | 329 tok/s | 1,089 tok/s |
| Prefill L=1024 | 6,010 tok/s | 327 tok/s | 1,127 tok/s |
| Prefill L=2048 | 6,612 tok/s | 326 tok/s | 1,092 tok/s |
| Prefill L=4096 | 6,743 tok/s | 339 tok/s | 1,042 tok/s |
Desk 1: Prefill and decode throughput on mamba-370m (f16, M1 Max 64GB). mlx-mamba (ours) reaches ~20× greater prefill throughput than the neighborhood mlx-lm baseline, whereas decode stays comparable.
The ~20× prefill speedup over mlx-lm comes down to 1 distinction: mlx-lm doesn’t implement a parallel scan for the SSM. The state recurrence
[h_t = bar{a}_t h_{t-1} + bar{b}_t]
appears inherently sequential, however every step may be written as a pair $(bar{a}_t, bar{b}_t)$ beneath the associative mix
[(a_2, b_2) circ (a_1, b_1) = left(a_2 a_1, a_2 b_1 + b_2right),]
which reproduces the recurrence precisely. As a result of the operator is associative, the entire sequence may be evaluated with a parallel (prefix) scan in $O(log N)$ dependent steps as a substitute of $O(N)$. mlx-lm skips this and processes tokens separately, leaving most of Apple Silicon’s compute idle; our developed Steel kernel applies the scan and makes a lot fuller use of GPU throughput. The acquire exhibits up in prefill, the place the complete sequence is out there to scan in parallel, and never in single-token decode, the place there is just one new token per step and no scan to parallelize — which is why the decode row is roughly flat whereas prefill is ~20×.
mamba.py is sluggish on each prefill and decode as a result of it’s a PyTorch reference implementation that falls again to CPU or MPS on Apple Silicon, forgoing the hardware-specific optimizations that MLX’s Steel backend makes doable.
What’s subsequent?
On the 2 kernels we studied, AI-driven evolutionary kernel search grounded in structured cross-platform translation information reached near-expert efficiency on Apple Silicon with out a crew of GPU consultants ranging from scratch. We don’t but understand how far this generalizes, however the result’s encouraging.
For us the principle takeaway is that the bottleneck was not the LLM’s capacity to put in writing Steel code, however the high quality of the context and constraints we gave it. Our CUDA translation layer converts present NVIDIA kernel experience into actionable steerage for Apple Silicon, and lets Ok-Search’s evolutionary search do the remaining.
We’re actively extending this work in a number of instructions: supporting new architectures, with present efforts centered on creating new kernels for the IBM Spyre AIU and broader {hardware} targets; including extra kernels resembling paged consideration and fused MoE routing; and enhancing integration with the Ok-Search evolution loop to make translation context much more automated.
Acknowledgements
This work was carried out by IBM Analysis and builds on Ok-Search from the UC Berkeley Sky Lab (Cao et al., 2026). We welcome collaboration and suggestions from the MLX and broader AI techniques communities. In case you are engaged on kernel optimization for non-CUDA {hardware}, we might love to listen to from you.
Quotation
@article{cao2026k,
title={Ok-Search: LLM Kernel Technology by way of Co-Evolving Intrinsic World Mannequin},
writer={Cao, Shiyi and Mao, Ziming and Gonzalez, Joseph E and Stoica, Ion},
journal={arXiv preprint arXiv:2602.19128},
yr={2026}
}
Appendix: Attempt it your self
The MLX backend is constructed on high of the open-source Ok-Search repo, so the outcomes right here may be reproduced straight. The steps are:
1. Clone and set up
git clone https://github.com/caoshiyi/Ok-Search.git
cd Ok-Search
uv pip set up openai wandb
uv pip set up git+https://github.com/caoshiyi/flashinfer-bench-ksearch.git
2. Set your credentials
Open the related script beneath scripts/ and set three variables on the high:
KSEARCH_ROOT=/path/to/Ok-Search
API_KEY=your-llm-api-key
3. Run kernel search
# Optimize Flash Consideration on Apple Silicon (world-model mode)
bash scripts/mac_flash_attention_wm.sh
# Or a Mamba SSM kernel, e.g. the selective scan
bash scripts/mamba_selective_scan_fwd_wm.sh
Full CLI reference and documentation are within the README.















