ashvardanian/FatWheels
소개
Starter kit for fat Python wheels: CPU kernels multi-versioned for AVX2, SVE & RVV, plus CUDA & ROCm kernels from one source, validated under QEMU, with reusable Clang, QEMU, GenMC, CUDA & ROCm CI images 🛞
개발 도구측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 기록 수집 중
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
OriginalFatWheels
FatWheels validates the design of hardware-tuned builds, multiversioned and monoversioned alike: one package or binary carrying many SIMD generations side by side, and GPU kernels for several generations and both NVIDIA and AMD in one build. It is small enough to read in an afternoon, so the build design is what you read:
- SIMD generations that combine.
Each capability builds on the ones below it, reusing their building blocks without duplicating their kernels: Haswell
vfmadd231pson 8 lanes, Skylake on 16 over Haswell's edges, Sapphire Rapids AMXtdpbf16pstiles over Skylake's bf16 rounding, and on Arm SVEfmlaunder SMEfmopaouter products. - GPU kernels that come together.
One build holds a shared-memory tile for every GPU, Ampere
mma.syncin bf16, Adamma.syncin e4m3, and AMD's CDNA3v_mfma_f32_16x16x16_bf16, and the driver's loader says which of them a device runs. - Both build kinds.
A multiversioned build carries every capability the toolchain compiles and picks the best at runtime, for distributing to a diverse fleet.
A monoversioned one keeps what its
-marchfloor implies, for identical machines, with shorter builds and smaller binaries that run only there. - Validated without the hardware.
test/conventions.pyturns every rule below into a test, and the images carry every tool it needs: Intel SDE for AVX-512 and AMX, QEMU for SVE and SME, CUDA and ROCm for both GPU vendors.
There is one operation, matmul, written once per capability with its hardware's own matrix instruction.
example/ shows how a higher-level project reuses its probe verdicts, kernels and GPU building blocks, and nothing else.
Two Flags
Every capability carries two flags, and every capability header reads them in the same order: the architecture, the capability's ARCH flag around its building blocks, then its TARGET around its kernels.
FATWHEELS_ARCH_<ARCH>_<CAPABILITY>_says the capability's code compiles in this unit.c/fatwheels/types.hdetects it from the unit's flags, or from compiling as a GPU vendor. The library's own build raises it with its probe's verdict, since only compiling tells that atargetattribute builds what the flags do not enable. It never reads a target, and a capability's flag also holds wherever a capability built on it holds, so Skylake's unit sees Haswell's building blocks.FATWHEELS_TARGET_<CAPABILITY>says this unit has the capability's kernels. A CPU target defaults to its capability's own detection, a GPU floor to its vendor, and a GPU generation to 0, since a unit cannot see which codes it compiles for. It is public:0drops kernels, and1shows the declarations of kernels a linked library holds, even to a unit whose flags enable nothing.
A capability's unit, like src/capabilities/sapphireamx.c, sets the targets of the capabilities it builds on to 0, so each kernel is defined once.
GPU building blocks are static __device__ __forceinline__, so every generation's blocks compile under every code, and a unit that writes the floor target to 0 gets the blocks it calls and no library kernel at all.
Device Placement
fw_devices lists every GPU of the build's vendors, NVIDIA's then AMD's, with the generations each one loads, asking each loader once.
fw_placement_resolve places positions in that table on one vendor and the best generation every listed device loads, and a launch runs on table[positions[i]].vendor_ordinal.
It refuses a list that spans vendors or shares no generation, so every device of a job runs the same kernels.
test/placement.py checks it on emulated machines, like two Blackwell RTX cards beside two H100s and two MI300Xs, through fake tables that load a generation wherever its compiled codes run.
Building
The library builds with CMake, and the Python package with scikit-build-core over it:
cmake --preset clang-floor && cmake --build --preset clang-floor
pip install . # FATWHEELS_CUDA_ARCH="80;89;120" adds `fatwheels.cuda`
pytest test/matmul.py # every capability this machine runs, against serial
FATWHEELS_MARCHsets the floor every unit compiles at, likex86-64-v3.FATWHEELS_MULTIVERSIONED=OFFbuilds monoversioned, keeping only what the floor implies.FATWHEELS_TARGET_<CAPABILITY>=0drops a capability, and=1vouches for one in a monoversioned build.FATWHEELS_CUDA_ARCHandFATWHEELS_ROCM_ARCHlist the GPU codes. Each generation's unit compiles only for the codes that run it.
import numpy as np
import fatwheels
a, b = np.ones((64, 32), np.float32), np.ones((32, 48), np.float32)
fatwheels.capabilities() # ['skylake', 'haswell', 'serial'] on an AVX-512 machine
fatwheels.matmul(a, b) # the best capability
fatwheels.matmul(a, b, capability="serial")
if fatwheels.cuda:
fatwheels.cuda.capabilities() # ['ada', 'ampere', 'cuda'], as the driver loads them
Images
Three images, built from the Dockerfile here, carry every tool the checks need and serve other projects' CI as they are:
| Tag | Platforms | Contents |
|---|---|---|
cpu |
amd64, arm64 | Ubuntu 26.04, Clang 23, GCC 15, CMake, Ninja, static QEMU, GCC 15 sysroots, Intel SDE |
verify |
amd64, arm64 | Ubuntu 26.04, GenMC v0.20, Spin 6.5.3, Clang 22 for GenMC and its clients |
gpu |
amd64, arm64 | CUDA 13.5, Clang 23, Clang 22 to host NVCC, and on amd64 ROCm 10.0 |
Each image has one command:
docker run --rm -v "$PWD:/work" -w /work ghcr.io/ashvardanian/fatwheels:cpu python3 -m pytest test/conventions.py -m cpu
docker run --rm -v "$PWD:/work" -w /work ghcr.io/ashvardanian/fatwheels:gpu python3 -m pytest test/conventions.py -m "cuda or rocm"
python3 -m pytest test/conventions.py --run-devices # on the host, where the GPU drivers are
The cpu checks build x86 natively, run Skylake and Sapphire Rapids under SDE, and run AArch64 under QEMU with SVE and SME on and off.
Intel's licence allows redistributing SDE unmodified, and its notices ship in /opt/sde/Licenses.
AMD publishes ROCm for x86-64 alone, so the Arm gpu image carries CUDA only.
NVCC's front end rejects libstdc++ 15's <atomic> under a Clang 23 host, so gpu sets CUDAHOSTCXX=clang++-22, and GenMC v0.20 in verify does not compile against LLVM 23.
Every pin is an ARG: UBUNTU, ROCM and LLVM at the top of the file, and QEMU_VERSION, SDE_VERSION, GENMC_COMMIT, SPIN_COMMIT and CUDA with their checksums in their stages.
Publishing
The Images workflow builds every image natively on x86-64 and Arm runners whenever main changes the Dockerfile, and on demand.
It pushes <target>-<commit>-<arch>, then joins both architectures into <target>-<commit> and <target>, and lists each digest in the run's summary for workflows to pin.
A registry cache per target and architecture and timestamps pinned to the commit keep unchanged stages byte-identical, so a bumped pin uploads only the layers it changes.
관련 프로젝트 살펴보기
불러오는 중…