Can a compute kernel carefully optimized for NVIDIA GPUs help write faster programs for a different kind of chip? In July 2026, authors from Berkeley and IBM Research described one approach: add an Apple MLX backend to the kernel search framework K-Search, then distill the optimization experience embodied in CUDA kernels into constraints and implementation hints aimed at Apple GPUs. The authors report that the generated Attention kernel reaches 0.97 times the speed of Apple's native implementation; in a separate Mamba test, prefill throughput under specific conditions is about 20 times that of the mlx-lm implementation it was compared with.[1]

GPU kernels carry out the low-level computation inside a model. The same mathematical operation can be implemented in many ways, and how the data is tiled, where it is stored, and when threads synchronize all affect speed. The CUDA ecosystem has accumulated a great many optimizations for these problems, but Apple Silicon uses a different GPU architecture and programming interface. If CUDA code is simply handed to a model to translate, the result may compile and still carry over an unsuitable data layout, tile size, or set of memory assumptions.[1]

Search for an optimization plan first, then generate code

K-Search was originally built for GPU kernel optimization, and its core idea is to manage optimization ideas separately from concrete code implementations. Researchers give the system a task specification and an evaluator: the former describes the reference computation, the goal, and the task requirements, while the latter compiles candidate programs, checks their results, and measures performance. A language model proposes modifications and generates code, and feedback from running it is then used to decide where the search goes next.[2]

It organizes the plans to be tried into a search tree. Branches of the tree can represent competing optimization directions, while a single path can combine several steps of modification. The model draws on experience so far to estimate priorities for the actions still to be explored, picks a direction, then generates and tests an implementation; if there is no progress for a while, it updates the search state and tries other branches. In this way, one faulty implementation or a temporary slowdown does not immediately cause an entire optimization idea to be discarded.[1][2]

For example, the authors show one Attention search node: have the SIMD thread group complete part of the softmax reduction in registers, to reduce thread-group synchronization. The node also records the expected hardware gain, register pressure, implementation difficulty, and the model's confidence. These are estimates made during search; whether a candidate plan actually works still has to be judged from compilation and runtime feedback once the code has been generated.[1]

The original K-Search paper tested four classes of CUDA kernels from FlashInfer on NVIDIA H100 and B200. Each method was given a budget of 120 candidate evaluations per kernel class and was run three times; the paper reports that K-Search's average final score was higher than those of OpenEvolve and ShinkaEvolve, the methods it was compared with. These results support the design of the search framework itself, and the later MLX work goes on to examine whether it can make use of cross-platform experience.[2]

What gets translated is optimization knowledge

To search on Apple Silicon, candidate kernels first have to compile, run, and be timed on the target platform. The authors added an MLX task adapter to K-Search, connected it to the Metal/C++ interface and MLX measurement tools, and revised the code-generation prompts to target Metal and MLX.[1]

The more important layer is a structured mapping of knowledge from CUDA to MLX. It links concepts in CUDA to the mechanisms available in Metal and also supplies the hardware constraints of the target platform. For example, CUDA's notion of shared memory can correspond to Metal's threadgroup memory, and CUDA's thread synchronization operations need to be converted into the appropriate Metal threadgroup barriers. The mapping tells the search system which resources and operations to consider, rather than asking it to copy the original program line by line.[1]

Beyond a glossary of corresponding terms, the translation layer also provides implementation patterns for Apple GPUs, along with computational properties distilled from expert kernels that must be preserved during search. For instance, the softmax in Attention can use the exponential identity eˣ = 2^(x log₂e) to arrange the computation in a form suited to the target hardware's exponential instructions. What the search system receives is therefore not a ready-made answer but a set of leads that can be combined, modified, and tested against runtime results.[1]

Attention: close to the speed of the native implementation

In the Attention experiment, the authors compared a naive implementation, evolutionary search with no additional context, and search supplied with the full translation context. Taking Apple's native Attention kernel as the reference, the article reports speed rising from 0.26 times to 0.97 times; the latter means the generated kernel reaches 97% of the reference speed and is still slightly slower than the reference implementation.[1]

According to the authors, once it had the full context, the search process implemented strategies such as threadgroup-memory tiling, online softmax, a K transpose aimed at memory access, and base-2 exponential computation. Together these steps change how data movement and computation are organized: tiling, for example, lets the program process data in batches, and online softmax lets the normalization advance tile by tile. The progress here lies in rewriting the ideas of existing high-performance kernels as searchable plans on the target platform.[1]

Mamba: parallel scan changes prefill

The authors also tested kernels for the Mamba state space model. The computation it faces differs from Attention: each state in the sequence has to be updated from the previous state. The article uses an M1 Max with 64 GB of memory, runs mamba-370m in half precision, and compares the authors' implementation, the community mlx-lm implementation, and a PyTorch reference implementation.[1]

At a prefill sequence length of 2048, the authors' implementation reaches a throughput of 6612 tokens per second while the mlx-lm implementation it was compared with reaches 326, a difference of about 20 times; at length 4096 the figures are 6743 and 339 respectively. For single-token decoding the numbers are 152 versus 116 per second, about 1.31 times. The gap is not the same in the two phases.[1]

The authors attribute the main prefill advantage to a parallel prefix scan. Although the state update appears to depend on the previous time step, each step can be expressed as a pair of coefficients; the transformations for adjacent steps can be merged, and the merge operation is associative. The full sequence can therefore be processed in parallel in groups, with the intermediate results then combined. Organized this way, the number of parallel dependency steps needed for a sequence of length N can fall from linear to logarithmic.[1]

During prefill the input sequence is already available for processing, so there is an opportunity to scan in parallel; during token-by-token decoding, each step has only the one newly produced token and cannot be unrolled along the full input sequence in the same way. The authors point out that the mlx-lm implementation used in the comparison does not apply a parallel scan to this state update. This contrast explains why the prefill gain is far larger than the decoding gain, and it also shows that how the baseline is implemented affects the multiple.[1]

This work splits cross-platform migration into two tasks: first convert the knowledge in existing kernels into rules and patterns the target hardware can use, then let the search process choose implementations through compilation and measurement. Attention shows a result close to the native kernel, while Mamba shows the change in throughput that comes from how the algorithm is organized; the authors also plan to extend the method to more kernels and to other hardware architectures.[1]

References

  1. Shiyi Cao, Gal Bloch, Assaf Toledo, Michael Factor, Gil Vernik, Joseph E. Gonzalez. From CUDA to MLX: How K-Search Brings Decades of Kernel Expertise to Apple Silicon. 2026-07-29.

  2. Shiyi Cao, Ziming Mao, Joseph E. Gonzalez, Ion Stoica. K-Search: LLM Kernel Generation via Co-Evolving Intrinsic World Model. 2026-02-22, updated 2026-02-26.

  3. Research Methods · Rituals can be imitated; understanding cannot be faked.

  4. Compiled and published by the Scholay one-stop academic platform. If anything here infringes your rights, please report it and it will be taken down.

  5. Also published on Enter Scholar, a community for scholars in the age of AI.