展示 HN:将同一份源码编译到 GPU 和 CPU
Show HN: Compile the same source for GPUs and CPUs

原始链接: https://github.com/ThrudTheBarbarian/xc

xc 是一种异构数据并行语言/编译器。xc 或 C 中的普通循环可由 xcc 编译,运行于 CPU 核心、GPU(Metal、CUDA、Vulkan、WebGPU)、多 GPU 或远程 GPU,并保留最快结果;内核由 xcc 生成并打包进可执行文件。仓库包含编译器、UXKit GUI 框架、捆绑的第三方库、Rocks 应用、基准测试、网站和工具。开发按独立流与隔离树组织;编译器测试/门禁仅读取编译器树,应用/框架针对已安装的 xcc 构建,而非内部路径。拉取请求保持 main 受门禁、变基、快进合并,且绝不强制推送。先按 compiler/USAGE.md 构建编译器,再构建其他树;机器相关设置放入 build.env。贡献遵循 CONTRIBUTING.md 和行为准则;安全报告为私密。项目寻求硬件出借/捐赠用于基准测试。

一位开发者宣布了“xc”/“xcc”,一种自动并行化普通循环并生成多核 CPU 代码和 GPU 内核(MSL、PTX、SPIR-V、WGSL)的编译器,无需 SDK。运行时,它在机器上对每个代码块进行基准测试,并保留更快的版本。它还通过 clang 处理普通 C 循环,无需 pragma。基准测试显示,xcc 在多个工作负载下平均比 GCC+OpenMP 快 2.1 倍,比 clang+OpenMP 快 3.0 倍,且结果已验证正确性。1.0.1 版本支持 Linux(x86-64 和 arm64,包括 Raspberry Pi 5)、macOS 和 Windows。C++ 支持仍在进行中,Pi 5 GPU 性能可能需要改进。作者寻求反馈和 bug 报告。
相关文章

原文

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.

Path Contents
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.

Stream Trees
Compiler compiler/ — the xcc toolchain: front end, IR, back ends, assemblers, linkers, simulators, standard library, tests and the differential gates.
Frameworks frameworks/uxkit/, frameworks/3p/ — the GUI framework and bundled third-party libraries.
Applications apps/ — programs built on the frameworks.
Website website/ — the site and the release archives it serves.
Tools tools/ — packaging, deployment and the C-to-xc converter.
Benchmarks benchmark/ — 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.

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.

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].

See LICENSING.md.

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...

联系我们 contact @ memedata.com