Research Papers 论文研究 17h ago Updated 2h ago 更新于 2小时前 50

From CUDA to MLX: How K-Search Brings Decades of Kernel Expertise to Apple Silicon 从CUDA到MLX:K-Search如何将数十年的内核经验带到Apple Silicon

The paper proposes a structured CUDA-to-MLX translation layer to transfer kernel optimization expertise from the mature CUDA ecosystem to newer hardware platforms like Apple Silicon, using the K-Search evolutionary framework. This approach enables automatic adaptation of hand-tuned CUDA kernels (e.g., attention, SSM) into high-performance MLX kernels without rebuilding from scratch, achieving near-expert performance levels. Results show up to 0.97x speedup over native MLX Attention kernels and u 提出了一种将CUDA内核优化知识自动迁移到Apple Silicon MLX框架的方法,通过结构化翻译层实现跨架构性能提升。 基于K-Search进化搜索框架扩展MLX后端,利用LLM驱动的内核生成与硬件基准测试闭环,实现注意力机制和SSM内核的显著加速。 在Mamba SSM预填充阶段获得最高20倍速度提升,注意力内核达到原生MLX性能的0.97倍,验证了专家知识迁移的可行性。 强调硬件异构化趋势下,建立可移植的kernel优化知识体系比单纯追求单点性能更具战略价值。 方法不依赖特定硬件,理论上适用于任何存在CUDA生态积累的新兴计算平台(如AMD ROCm、Google TPU等)。

72
Hot 热度
68
Quality 质量
75
Impact 影响力

Analysis 深度分析

TL;DR

  • The paper proposes a structured CUDA-to-MLX translation layer to transfer kernel optimization expertise from the mature CUDA ecosystem to newer hardware platforms like Apple Silicon, using the K-Search evolutionary framework.
  • This approach enables automatic adaptation of hand-tuned CUDA kernels (e.g., attention, SSM) into high-performance MLX kernels without rebuilding from scratch, achieving near-expert performance levels.
  • Results show up to 0.97x speedup over native MLX Attention kernels and up to 20x prefill speedup for Mamba SSM compared to community mlx-lm implementations.
  • The method is generalizable beyond MLX to any architecture where CUDA knowledge can be meaningfully translated rather than copied instruction-for-instruction.
  • K-Search uses an LLM-driven iterative search with a persistent world model tree to explore optimization paths, guided by hardware-specific specs that prevent invalid code generation.

Why It Matters

This work addresses a critical bottleneck in AI deployment: the fragmentation of hardware ecosystems and the loss of accumulated low-level optimization expertise when moving between platforms. By enabling automated transfer of GPU kernel knowledge, it reduces the engineering burden required to achieve peak performance on emerging architectures like Apple Silicon, democratizing access to high-efficiency computing without requiring years of specialized tuning experience per platform.

Technical Details

  • Built upon K-Search, an evolutionary kernel optimization framework that uses LLMs to iteratively propose, compile, and benchmark GPU kernel optimizations based on hardware specifications.
  • Introduced a novel structured translation layer that maps CUDA optimization patterns to MLX-native strategies rather than direct instruction copying, preserving semantic intent while adapting to architectural constraints.
  • Utilized a single LLM (Gemini 3.5 Pro Preview) functioning as both reasoning engine ("GPU kernel performance engineer") and code generator within a decision-tree world model that tracks partial optimization plans with scores for overall rating, confidence, and hardware impact metrics.
  • Applied domain-specific "Spec" documents encoding hardware rules, optimization patterns, and mathematical constraints to ensure generated kernels are valid and efficient, preventing hallucinations of unsupported primitives.
  • Evaluated on two key workloads: Attention kernels (achieving 0.97x relative to native MLX) and Mamba State Space Model kernels (showing up to 20x prefill speedup over mlx-lm baseline).

Industry Insight

As hardware diversity accelerates—with custom AI chips from multiple vendors and frameworks like MLX gaining traction—this approach offers a scalable solution to avoid reinventing optimization wheels for each new platform. Organizations investing in non-NVIDIA hardware should consider adopting similar knowledge-transfer methodologies to rapidly close performance gaps without massive R&D投入, while open-source communities could build shared specification libraries to enable cross-platform kernel portability. The success of this translation strategy suggests future AI toolchains may increasingly include automated legacy-kernel migration layers as standard components.

TL;DR

  • 提出了一种将CUDA内核优化知识自动迁移到Apple Silicon MLX框架的方法,通过结构化翻译层实现跨架构性能提升。
  • 基于K-Search进化搜索框架扩展MLX后端,利用LLM驱动的内核生成与硬件基准测试闭环,实现注意力机制和SSM内核的显著加速。
  • 在Mamba SSM预填充阶段获得最高20倍速度提升,注意力内核达到原生MLX性能的0.97倍,验证了专家知识迁移的可行性。
  • 强调硬件异构化趋势下,建立可移植的kernel优化知识体系比单纯追求单点性能更具战略价值。
  • 方法不依赖特定硬件,理论上适用于任何存在CUDA生态积累的新兴计算平台(如AMD ROCm、Google TPU等)。

为什么值得看

该工作解决了AI算力碎片化时代的核心痛点:如何在不同硬件架构间高效复用底层优化经验。对于开发者而言,它提供了一种系统化的方法将NVIDIA数十年的kernel工程积累转化为其他平台的性能优势;对行业而言,这标志着AI软件栈正从“硬件绑定”向“知识可迁移”范式转变,为降低多平台开发成本、加速新硬件 adoption 提供关键路径。

技术解析

  • 核心创新:设计CUDA-to-MLX结构化翻译映射表,将CUDA中的线程调度、内存布局、同步原语等优化策略转换为MLX等效表达,而非直接复制指令序列,保留语义适配性同时规避架构差异风险。
  • K-Search增强机制:引入世界模型(World Model)作为决策树结构存储优化路径,每个节点记录整体评分、置信度及带宽/寄存器压力影响指标,支持动态回溯与分支探索,避免陷入局部最优。
  • LLM协同推理流程:使用Gemini 3.5 Pro Preview统一承担“性能工程师”角色,先完成kernel分类、数据流分析、瓶颈假设等前置推理步骤,再输出原子级优化变更,确保候选代码符合硬件约束且可编译运行。
  • Spec驱动约束系统:通过领域特定规范文档强制限定生成操作符范围与数学合法性,防止LLM幻觉产生无效指令,保障所有候选方案能在目标设备上实际执行并参与性能评估。
  • 实证效果:在Apple M系列芯片上,经迁移优化的Attention kernel达原生MLX 97%效率,而Mamba SSM的prefill吞吐量较社区mlx-lm版本提升达20倍,证明知识迁移对稀疏模型尤其有效。

行业启示

  • 构建硬件无关的kernel知识库成为新竞争壁垒:未来AI框架竞争将不仅限于API易用性或模型支持广度,更取决于其能否整合跨平台优化经验库,建议头部厂商牵头建立标准化kernel迁移协议。
  • LLM辅助的低层系统编程将成为标配工具链:类似K-Search的模式可推广至编译器优化、驱动开发等领域,企业应投资训练具备硬件感知能力的专用Agent,替代人工调优的高门槛过程。
  • 边缘端AI部署将迎来性能拐点:随着本地推理需求增长,针对非GPU架构(如NPU、ASIC)的kernel自动优化工具链将极大释放消费级设备潜力,推动大模型在手机、PC上的实时应用落地。

Disclaimer: The above content is generated by AI and is for reference only. 免责声明:以上内容由 AI 生成,仅供参考。

Chip 芯片 GPU GPU Inference 推理 Research 科学研究