Show HN: Compile the same source for GPUs and CPUs

Hacker News Top Tools

Summary

Show HN: xc is a heterogeneous data-parallel language whose xcc compiler runs the same source across CPU cores and GPUs (Metal, CUDA, Vulkan, WebGPU, multi-vendor and remote GPUs), picking the fastest backend with kernels embedded in the executable.

I&#x27;m writing a language called xc and its compiler, xcc for the last 6 months or so (full disclosure: with a lot of help from Claude). I&#x27;ve finally got version 1 (actually v1.0.1) out, for Linux (x86-64 and arm64, including the Pi 5), macOS and Windows.<p>The idea: you write an ordinary loop, the compiler works out whether it can run in parallel, and it emits both a multi-core CPU version and GPU kernels (MSL, PTX, SPIR-V or WGSL, all generated by xcc itself without needing an SDK installed).<p>At run time the program measures each block on that machine and keeps the faster placement.<p>Examples:<p>- On an M3 Max a Mandelbrot block takes 13.7 ms on all 16 cores and 1.3 ms on the GPU<p>- On a Ryzen 9955HX&#x27;s 2-CU integrated Radeon the GPU loses to the 32 CPU threads, so it stays on the CPU.<p>The compiler also reads plain old C via clang&#x27;s front end and does the same thing to C loops, with no pragmas. Comparing xcc to OpenMP for both gcc and clang (with the helping hand of &quot;#pragma omp parallel for&quot; gives (times in ms):<p><pre><code> xcc gcc+omp clang+omp mandel_deep 371 2170 2231 mandelbrot 2.45 12.2 12.8 md5 9.39 16.1 13.4 md5_mask 8.17 12.1 13.4 nbody 0.45 1.29 9.92 perlin 5.87 4.38 7.05 saxpy 2.26 2.18 2.32 </code></pre> Geometric mean: xcc is 2.1x faster than GCC+OpenMP and 3.0x faster than clang+OpenMP.<p>All the builds are checked to make sure they give the same result - no point having a benchmark that doesn&#x27;t produce the same result! xcc has a notable win for nbody, because its vectorisation is better (across bodies) but perlin has been a bit of a bugbear throughout the leading-up-to-v1 timespan.<p>Platform-specific binary tarballs, the sources, OpenMP versions and method are on the site (linked from github), and there are Phoronix Test Suite profiles if you&#x27;d like to run them yourself.<p>It&#x27;s only just made v1 so there&#x27;s a few rough edges: C++ through clang is in-progress (but not official yet), and the Pi 5&#x27;s GPU is slow. Not sure if that&#x27;s the Pi or the code yet...<p>There&#x27;s more to the language but I don&#x27;t want this to be an essay! The real, honest-to-$deity cool thing is the <i>automatic</i> parallelising of standard C&#x2F;xc loops and being able to run that code on the GPU with <i>no boilerplate</i> - &quot;ARC for Algorithms&quot; (what Objective-C&#x27;s ARC did for memory management), it &quot;just works&quot;.<p>Very keen to get feedback and fix any gaps. I think it&#x27;s generally useful right now, but it is &quot;v1&quot; - Bug reports welcome as GitHub issues...
Original Article
View Cached Full Text

Cached at: 11/22/26, 09:23 AM

ThrudTheBarbarian/xc

Source: https://github.com/ThrudTheBarbarian/xc

xc

xc is a heterogeneous data-parallel language. 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. The kernels are generated by xcc itself and carried in the executable, so a build needs no GPU toolkit. Documentation, benchmarks and downloads are at https://compile-xc.org.

This repository holds the compiler, its GUI framework and the tools and applications built with them.

PathContents
compiler/The xcc toolchain: front end, IR, back ends, assemblers, linkers, simulators and standard library.
frameworks/uxkit/UXKit, the cross-platform GUI framework.
frameworks/3p/Bundled third-party libraries, such as tls (Mbed TLS and its shim).
apps/rocks/Rocks, a GEM resource and UI editor.
benchmark/Benchmark and report generation for the compiler.
website/site/The documentation site for https://compile-xc.org.
website/downloads/Release archives served by the site. These are not tracked.
tools/release/Packaging and deployment scripts.
tools/c2xc/A converter from C to xc.

How the repository is divided

It is one repository, but it is worked on as several separate streams, and each stream stays inside its own tree.

StreamTrees
Compilercompiler/ — the xcc toolchain: front end, IR, back ends, assemblers, linkers, simulators, standard library, tests and the differential gates.
Frameworksframeworks/uxkit/, frameworks/3p/ — the GUI framework and bundled third-party libraries.
Applicationsapps/ — programs built on the frameworks.
Websitewebsite/ — the site and the release archives it serves.
Toolstools/ — packaging, deployment and the C-to-xc converter.
Benchmarksbenchmark/ — the benchmark runs and their reports.

Two rules keep the streams’ work apart:

  • A change is made in one tree. Compiler work stays in compiler/ and framework work stays in frameworks/; the compiler’s tests and gates read only the compiler’s own tree and never frameworks/.
  • An application or framework builds against the installed xcc toolchain, as an external project would, and never against paths inside compiler/. Something that only builds in a full checkout is a bug, because it cannot build for anyone else.

Pull requests, from outside contributors and from the streams alike, keep main always gated:

  • Each stream works on its own branch, in its own worktree. Its work is rebased on origin/main, gated, and then fast-forwarded onto main.
  • main is never force-pushed. A release is cut from main while the streams carry on with the next round on their branches.
  • Work under way has an issue labelled with its stream and in progress, so nobody else starts the same thing.

private/ is not part of the repository. It is ignored by git and holds the working rules, the notes on open and fixed bugs, and other material that is never published. Nothing under it is ever committed.

Building

Build and install the compiler first (see compiler/USAGE.md), then build whichever other tree you are working in against it.

Settings that depend on your machines, such as the Linux test host or the location of the GEM desktop sources, live in build.env at the repository root. Copy build.env.template to build.env and fill in the values you need. build.env is ignored by git. A variable left empty turns off the step that needs it.

Contributing

Pull requests are welcome. CONTRIBUTING.md says how a change gets into main: the contributor licence agreement you sign once, where changes go, and how to build and test with an installed release. Everyone taking part agrees to the code of conduct. Security problems are reported privately, as SECURITY.md describes.

Hardware we would like to test on

Every benchmark figure on the site is measured on hardware the project has bought, and the machines that matter most for data-parallel work are expensive. A loan or donation goes straight into the compiler: a back end and a runtime tuned on the device, kept working by being tested on it every release, and its figures published beside the others. We would most like:

  • Discrete AMD GPUs, Radeon and Instinct: xc reaches them through Vulkan today, and has only an integrated Radeon to measure on.
  • Intel GPUs, Arc and data-centre parts, through Vulkan.
  • Data-centre NVIDIA GPUs and multi-GPU servers, where tiling across many cards, and across machines, is meant to pay.
  • Arm servers (Graviton, Ampere, Grace) and their wider vector units.
  • RISC-V boards with the vector extension, and their GPUs.
  • Fast interconnect: 25, 100 GbE or InfiniBand between GPU machines, for xcd.

If you make or sell hardware like this and would like xc to run well on it, write to [email protected].

Licensing

See LICENSING.md.

Checkin history

My apologies but I wasn’t great at keeping private details out of the ~3000 or so checkins made to get this far, and the thought of going back and changing everything didn’t really appeal. So, clean start, and I’ll be more diligent from now on…

Similar Articles

Vx – One Language, Every Chip

Hacker News Top

Vx is a systems programming language for heterogeneous computing (CPU, GPU, NPU) that encodes device memory topologies directly in its type system, using machine files and formal verification to catch data-movement and memory bugs at compile time.

A hackable compiler to generate efficient fused GPU kernels for AI models [P]

Reddit r/MachineLearning

The author presents a custom, hackable ML compiler written in Python that lowers LLMs to optimized CUDA kernels through a multi-stage IR pipeline, achieving performance competitive with or superior to PyTorch on specific operations. The article details the compiler's optimization passes, lowering rules, and CLI usage for generating efficient fused GPU kernels.