xc - Write one loop, run on every CPU and GPU
Show HN: Compile the same source for GPUs and CPUs
xc is a heterogeneous data-parallel language and compiler that lets you write an ordinary loop in xc or C and have it automatically run across every CPU core, on GPUs via Metal, CUDA, Vulkan, or WebGPU, or even across multiple GPUs from different vendors at once. The xcc compiler generates kernels itself and embeds them in the executable, so no GPU toolkit is needed at build time. It keeps whichever backend is fastest, making high-performance parallel computing accessible without specialized GPU programming. The project includes a GUI framework, tools, and benchmarks, with documentation and downloads at compile-xc.org.
Write an ordinary loop, in xc or in C, and xcc runs it across every CPU core, on the GPU through Metal, CUDA, Vulkan or WebGPU, across several GPUs from different vendors at once, or on a GPU on another machine, and keeps whichever is fastest.
- eliasdejong
Being able to take a C program and have it auto-parallelize across heterogeneous hardware accelerators certainly sounds attractive, but it's harder than it sounds because you are effectively talking to multiple computers at the same time and it becomes a distributed systems problem. It's very difficult to abstract over the communication latency, bandwidth limits and architecture differences. For example the accelerator could have a completely different address space or pointer size.
I'm curious about the author's opinion on MLIR / Mojo, which are also trying to solve the problem of compiling for heterogenous hardware. Iirc they decided that the underlying hardware boundaries are sufficiently large that you still need to explicit control over what runs where.
- Conscat
I only looked a little bit, but I noticed some things like the integer types and OS #ifdefs look different from "normal" C. Is this compatible with generic C code out there today? A bit hard to tell how compatible it is with C idioms besides what the standard strictly requires. Impressive results, this is great!
- spacedcowboy
One thing I might also want to point out is that the language will also compile down to WASM and use WGSL to do the data-parallel parts - I do mention that above in passing, but everyone looks at the highlight figures :)
Benchmarks are available at the docs site [1] for a lot more involved data, it does pretty well even in CPU mode...