Determine 1: CUDA-to-MLX optimization translation map. CUDA optimization information will be translated into architecture-native MLX methods moderately than copied instruction-for-instruction.
We face a brand new epoch in computing. {Hardware} is altering quickly — not simply quicker GPUs, however a rising vary of chips from totally different distributors, every with its personal structure and infrequently 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 element of its success. These are the low-level packages that run contained in the GPU, and writing environment friendly ones is way from apparent — it takes years of experience to get proper. Transferring a kernel from one vendor’s {hardware} to a different is more durable nonetheless, and infrequently means rediscovering the identical optimizations from scratch. The CUDA ecosystem, for instance, has accrued a long time of hard-won kernel experience: hand-tuned implementations of consideration, state house fashions, and different crucial operations representing hundreds 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 will be transferred mechanically. 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, moderately than rebuilding from scratch.
We present that our method reaches near-expert degree 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 group mlx-lm implementation on the Mamba SSM kernel; we report the numbers, and the way a lot of the achieve comes from the interpretation layer, within the sections under. Though we concentrate on MLX kernels for Apple Silicon, the tactic is just not particular to MLX and applies to any ecosystem the place CUDA experience is transferable.
Why MLX?
Apple’s MLX framework has seen outstanding adoption since late 2023. With Apple Silicon in a whole lot of tens of millions 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 major hole: many performance-critical kernels that the NVIDIA ecosystem takes as a right: paged consideration, optimized SSM scan kernels, fused MoE routing are both absent or naive with out hardware-specific tuning. MLX runs fashions appropriately however typically leaves important efficiency on the desk.
This hole is what motivates the remainder of this put up.
What’s Ok-Search?
Ok-Search is an evolutionary kernel optimization framework initially developed by our first creator 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 strive 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 probably the most promising motion, instantiating and evaluating code till enchancment stagnates, and evolving the world mannequin by way of 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 really 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 way of 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 doubtless 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. Slightly than a flat record of issues to strive, it’s a resolution (prefix) tree: every root→leaf path composes a full optimization plan, and sibling branches are competing alternate 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 probably the most promising ones. The tree persists and grows throughout rounds: refining an concept provides a toddler node moderately than overwriting its guardian, and if the most effective 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, seems like this:
{
"motion": "Change 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, // threat: spill if Br > 8
"compute_hw_fit": 9 // SIMD width 32; maintain 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 data a concrete motion, estimated {hardware} impacts, an general precedence score, 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 hooked up program like $x_{12}$) and a Frontier of Open nodes (orange, pending hypotheses like $u_{13}$). The workflow iterates by way of three phases: (1) Motion Choice, the place probably the most promising motion node is retrieved from the frontier based mostly 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 funds. These outcomes set up the search framework we construct on right here; the rest of this put up asks whether or not its optimization information can switch past CUDA.
Determine 3: Primary 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 deliver Ok-Search to Apple Silicon, we first constructed a local MLX backend. We carried out a full MLX-specific process adapter for Ok-Search, together with:
- An MLX process 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 fascinating problem was not merely operating Ok-Search on MLX. The important thing perception is that professional CUDA kernels encode a long time of optimization information that’s transferable to Apple GPU when 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 incorrect (incorrect 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 arduous 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, comparable to 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 quicker softmax on Apple’s quick $exp_2$ {hardware} instruction. - Reusable assertions: Knowledgeable kernel behaviors reframed as properties the evolutionary search should protect, moderately than code to repeat.
Matching professional 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 further supplied 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 cause about implementation methods moderately 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 way of 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 velocity of Apple’s state-of-the-art consideration kernel — illustrates how a lot the interpretation layer issues. With full context, the advanced 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 actual 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× quicker 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 moderately than a softmax, offering a considerably totally different optimization problem. We examine the advanced implementation in opposition to the group 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 (group) | 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× larger prefill throughput than the group 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]
seems inherently sequential, however every step will be written as a pair $(bar{a}_t, bar{b}_t)$ underneath 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 will 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 advanced Steel kernel applies the scan and makes a lot fuller use of GPU throughput. The achieve exhibits up in prefill, the place the total sequence is accessible 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 no workforce of GPU specialists ranging from scratch. We don’t but understand how far this generalizes, however the result’s encouraging.
For us the primary takeaway is that the bottleneck was not the LLM’s means to jot down 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 steering 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 growing new kernels for the IBM Spyre AIU and broader {hardware} targets; including extra kernels comparable to paged consideration and fused MoE routing; and enhancing integration with the Ok-Search evolution loop to make translation context much more computerized.
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 methods communities. If you’re 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},
creator={Cao, Shiyi and Mao, Ziming and Gonzalez, Joseph E and Stoica, Ion},
journal={arXiv preprint arXiv:2602.19128},
12 months={2026}
}
Appendix: Strive it your self
The MLX backend is constructed on high of the open-source Ok-Search repo, so the outcomes right here will be reproduced straight. The steps are:
1. Clone and set up
git clone
cd Ok-Search
uv pip set up openai wandb
uv pip set up git+
2. Set your credentials
Open the related script underneath 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.


Leave a Reply