Skip to content

feat :: --cpu-target builds for another CPU target - #451

Merged
HaoZeke merged 19 commits into
developfrom
feat/cpu-target
Nov 27, 2026
Merged

HaoZeke merged 19 commits into
developfrom
feat/cpu-target

Conversation

@HaoZeke

@HaoZeke HaoZeke commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Base: develop. Second of three PRs that merge in this order: feat/isa-audit, feat/cpu-target (this one), feat/cpu-target-vm. This branch contains develop (merged in, 57 commits) and feat/isa-audit, so once feat/isa-audit has merged this PR shows only the --cpu-target work. It does not contain __vm-run; that arrives with feat/cpu-target-vm.

What

eb-local --cpu-target TARGET recipe.eb builds for another CPU target on this machine and installs it where EESSI-extend puts software for that target. TARGET is an EESSI subdirectory (x86_64/amd/zen4) or its last component (zen4). --mask auto|cpuid|kvm|tcg picks the route; auto takes cpuid where the host can present the target, else kvm (same architecture), else tcg. The host's own target needs no mask.

This PR has the cpuid route and the shared parts:

  • x86_64: CPUID faulting through a preload library (compiled with the host cc on first use, cached by source hash, target triple and libc version), with the target's /proc/cpuinfo bound in an unprivileged user and mount namespace that keeps the caller's uid (a mapped root makes OpenMPI's prterun refuse). aarch64: masked getauxval plus the same cpuinfo bind.
  • Profiles for zen2, zen3, zen4, skylake_avx512, cascadelake, icelake, sapphirerapids, aarch64/neoverse_n1 and aarch64/generic: share/eb-local/mask/profiles.conf, generated by tools/mask/gen_profiles.py from tools/mask/targets.toml and the CPUID rule files made by tools/mask/gen_cpuid_rules.py.
  • A preflight inside the mask refuses the build unless /dev/fd, EESSI archdetect, archspec (when importable), gcc -march=native and the CPUID vendor all name the target, and CPUID faulting is active. A host without faulting is refused; there is no native fallback.
  • EESSI_SOFTWARE_SUBDIR_OVERRIDE is set to the target, and EasyBuild runs the stack's hooks plus one rule: GROMACS gets -DGMX_SIMD from the target, because GROMACS times FMA units for an Intel brand string and a Zen 5 host picks AVX2 for an Icelake tree.
  • After a successful build, eb-local audit-isa DIR --target TARGET runs on each installed directory; a non-zero exit fails the run (--no-audit skips it). Each directory gets easybuild/eb-local-build-mode.json (route, profile, host CPU, kernel, version, audit result).
  • --explain, replay hints and the submit sbatch lines carry the options; doctor --cpu-target reports faulting, /dev/kvm, QEMU binaries and the route auto takes.

--mask kvm|tcg call eb-local __vm-run --mode MODE --cpu-target TARGET [--allow-archspec-mismatch] -- COMMAND... and refuse, naming __vm-run, while this binary has none; feat/cpu-target-vm adds it. The audit step refuses the same way, without --no-audit, while audit-isa is missing; with feat/isa-audit merged it is present.

Checks

On a Zen 5 host (Ryzen 9 9950X, kernel 7.0), EESSI 2026.06 mounted, cpuid route, audit on:

  • bzip2-1.0.8-GCCcore-15.2.0.eb --rebuild under --cpu-target x86_64/amd/zen3 and x86_64/amd/zen4 (2 min 14 s and 2 min 7 s): preflight ok for archdetect, archspec, gcc -march=native (znver3, znver4), CPUID vendor and faulting; the audit step ran on the installed directory and passed; easybuild/eb-local-build-mode.json holds "route": "cpuid" and "isa_audit": "pass" in both trees.
  • eb-local audit-isa on the installed trees: zen3-built against zen3 and zen4, exit 0; zen4-built against zen4, exit 0; zen4-built against x86_64/amd/zen3, exit 1 with avx512f x486, avx512bw x113, avx512vl x307, avx512dq x46, avx512vbmi x4 in bunzip2 and bzcat.
  • zlib-2.3.2-GCCcore-15.2.0.eb under the zen3 mask passes its own audit: zlib-ng's run-time dispatched AVX-512 kernels print as dispatch (feat/isa-audit lists zlib).
  • The preflight passes for zen2, zen3, zen4, skylake_avx512, cascadelake and icelake; sapphirerapids is refused on this host (no AVX512-FP16 or AMX, which a mask cannot add).
  • The hook chains EESSI's eb_hooks.py and sets GMX_SIMD=AVX_512 for icelake, AVX2_256 for zen3, and leaves an explicit -DGMX_SIMD= alone.
  • zig build unit: 208 tests pass. zig build -Dtest-ops=true test: the same 43 failure lines as develop at aecc5a5 on this host, none new. CI: zig (x86_64 and aarch64) and shellcheck green on the merge commit (runs 45916937124 and 45916937205).

The aarch64 profiles are unit-tested for parsing, cpuinfo rewriting and preflight decisions; the tcg route in feat/cpu-target-vm exercises the aarch64 target under emulation.

gen_cpuid_rules.py maps the features a target lacks to the CPUID bits to
clear through GCC's own tables; gen_profiles.py assembles the profile data
file from targets.toml and the rule files. Rules exist for zen2, zen3, zen4,
skylake_avx512, cascadelake, icelake and sapphirerapids.
The cpuid route runs the build in an unprivileged user and mount namespace
that keeps the caller's uid, with a target /proc/cpuinfo bound over the real
one and a preload library that answers CPUID as the target. A preflight
inside the mask refuses the build unless EESSI archdetect, archspec, gcc and
the CPUID vendor all name the target. The kvm and tcg routes call the
__vm-run helper and refuse while this binary has none. The installed tree is
audited with audit-isa unless --no-audit, and each installed directory gets
easybuild/eb-local-build-mode.json. doctor --cpu-target reports what the host
can present.
@HaoZeke
HaoZeke merged commit d3ce39c into develop Nov 27, 2026
12 of 13 checks passed
@HaoZeke
HaoZeke deleted the feat/cpu-target branch November 27, 2026 03:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant