Show HN: Compile the same source for GPUs and CPUs
xc is a heterogeneous data-parallel compiler that automatically targets CPUs and various GPUs from C or native source without requiring a GPU toolkit.
summary is enough The project overview and author comments give a clear picture of how the compiler bridges C to LLVM IR for auto-parallelization.
summary
xc is a new heterogeneous data-parallel language and compiler toolchain that runs ordinary loops across multi-core CPUs, local GPUs, or remote machines. For C source files, the compiler integrates via Clang-generated LLVM IR, enabling automatic parallelization and vectorization without requiring vendor-specific GPU toolkits. The repository includes its own IR, back ends, assemblers, linkers, and a cross-platform GUI framework. The author explains that it can also target WebAssembly and WebGPU for broader compatibility.
key points
- Compiles native xc or standard C code via LLVM IR to run across CPU cores, multiple GPUs, or remote machines simultaneously.
- Generates its own GPU kernels for Metal, CUDA, Vulkan, and WebGPU, eliminating the need for vendor-specific SDKs during builds.
- Includes a complete self-hosted toolchain with front end, IR, back ends, linkers, and a cross-platform GUI framework.
who should read it
Systems programmers and compiler engineers interested in automatic hardware acceleration and parallelization.
discussion positive
consensus
Commenters find the automatic heterogeneous parallelization claims impressive but point out the immense difficulty of handling disparate address spaces and distributed systems challenges.
Yeah, I probably could have been a bit clearer on that front :) This is what's going on...
1) If you compile a program named myfile.xc, then xcc will run natively, it wants to see 'xc' style types (u8, u16, i32, float, etc). This is xc compiling its own language.
2) If you compile a program named myfile.c, then xcc will look up how to compile a non-native type (in this case .c) and find it has a rule to "run clang with various options to produce LLVM Intermediate Representation (IR)'. It does that, then reads and parses the LLVM IR into its own IR, and everything else proceeds as …
The author clarifies how standard C files are parsed through Clang and LLVM IR to leverage the compiler's auto-parallelization pipeline.
Generated by an LLM from the article and thread. Check the sources before relying on it.