对比三种语言在不规则GPU任务中的表现,发现语言选择对性能影响巨大。
What Irregularity Costs: CUDA C++, Rust, and Triton on a Hash-Blocked GPU Workload

- 在不规则的哈希探测插入任务中,用不同语言实现同一内核。
- Rust接近手写CUDA性能,Triton慢超过10倍,因无法表达动态探查和原子操作。
- 适合需要高效处理不规则数据的开发者,尤其关注底层性能优化者。
GPU语言比较通常在分块密集线性代数上进行,各工具链表现相近。本文在同一哈希分块TSDF融合内核上,分别用CUDA C++、Rust(通过cuda-oxide)和Triton实现,并在具有相反特性的工作负载上测试:开放寻址哈希表、比较交换插入、依赖数据的每车道探测深度和竞争性散列。结果分化明显:规则阶段(遍历截断带并累加)三者性能相近;不规则阶段(探测与插入)中,Rust性能接近手写CUDA C++,而Triton慢于一个数量级。语言选择在常规任务中几乎无代价,在非常规任务中代价高昂。两个差距均源于语言无法表达特定机制:Triton的探测循环必须运行至编译时边界,且tl.atomic_cas无掩码,迫使使用无对应项的临时结构;而Rust虽指令、原子操作和寄存器使用更少,仍更慢,硬件计数器定位到L1驻留时间过长——因跨SM的原子加载需缓存一致性,导致每次访问都绕过L1缓存。Triton的固定探测上限还带来正确性问题:在普通负载因子下会静默丢弃区块,重建丢失表面区域却无告警。此外,报告并修复了cuda-oxide的一个缺陷:在生成实际内核的构建模式下,作用域原子加载/存储根本无法调用。
原文摘要 · Abstract (English)
GPU language comparisons are almost always run on tiled dense linear algebra, where every toolchain is good and the differences are small. We implement the same hash-blocked TSDF fusion kernel in CUDA C++, in Rust through NVIDIA's cuda-oxide, and in Triton, and measure it on a workload with the opposite character: an open-addressed hash table with compare-exchange insertion, data-dependent per-lane probe depth, and contended scatter. The result is a split. On the regular stage, which walks a truncation band and accumulates, all three languages land within a small factor of each other. On the irregular stage, which probes and inserts, Rust stays close to hand-written CUDA C++ while Triton is more than an order of magnitude slower. Language choice is nearly free on the work that is usually benchmarked and expensive on the work that is not. We attribute both gaps to specific things the languages cannot express, not to ratios. Triton's cost follows from a probe loop that must run to a compile-time bound and from tl.atomic_cas taking no mask, which forces a scratch structure with no counterpart in CUDA. Rust's cost was invisible in every instruction count: its kernel issues fewer instructions, fewer compare-exchanges and fewer registers at identical occupancy, yet was slower. Hardware counters located it in L1 residency. A GPU-scope atomic load must be coherent across SMs, no NVIDIA L1 is, so the type-correct way to read a shared location bypasses the cache on every access. Triton's bounded probe is also a correctness problem for fusion: at load factors an ordinary depth trajectory reaches, it silently discards blocks and the reconstruction loses patches of surface with nothing reported. We also report a defect found and fixed in cuda-oxide itself, now merged upstream: its scoped atomic load and store could not be called at all in the build mode that produces real kernels.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。