Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
0b732f0
feat(mask): generators for CPUID rules and mask profiles
HaoZeke Nov 26, 2026
1533e4f
feat(mask): CPUID mask preload source and generated profiles
HaoZeke Nov 26, 2026
cdd29cc
feat(mask): armmask preload, CPUID probe and EasyBuild hook for the G…
HaoZeke Nov 26, 2026
eda6091
feat: --cpu-target and --mask build for another CPU target
HaoZeke Nov 26, 2026
51c0aae
fix(mask): CPUID probe reads the extended model for the base family i…
HaoZeke Nov 26, 2026
014245b
fix: read the gcc native target without ending the pipe early
HaoZeke Nov 26, 2026
441a146
fix: write the build-mode record into the read-only installation dire…
HaoZeke Nov 26, 2026
dc782d7
fix: a build drops the cpu-target variables from the caller's shell
HaoZeke Nov 26, 2026
0c31522
docs: build for another CPU target, --cpu-target and --mask reference
HaoZeke Nov 26, 2026
d0b7ad2
docs: reword the another-CPU guide
HaoZeke Nov 26, 2026
c8853a2
test: --cpu-target options, refusals and the preflight
HaoZeke Nov 26, 2026
4fb3bc1
test: the doctor report names CPUID on every architecture
HaoZeke Nov 26, 2026
fbb0651
fix: keep the mask helpers out of the command list, document the publ…
HaoZeke Nov 26, 2026
9eba33a
test: usage refusals exit 2
HaoZeke Nov 27, 2026
9a76152
Merge origin/develop into feat/cpu-target
HaoZeke Nov 27, 2026
e713992
Merge remote-tracking branch 'origin/feat/isa-audit' into stack/cpu-t…
HaoZeke Nov 27, 2026
0d7abb3
docs(cpu-target): word the GMX_SIMD log line so Org 9.7 and 9.8 expor…
HaoZeke Nov 27, 2026
ec2bb08
Merge remote-tracking branch 'origin/feat/isa-audit' into stack/cpu-t…
HaoZeke Nov 27, 2026
1642a13
Merge remote-tracking branch 'origin/feat/isa-audit' into tmp/feat/cp…
HaoZeke Nov 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 26 additions & 12 deletions build.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
const std = @import("std");

/// The mask sources and data that cpumask.zig embeds, as imports of `mod`.
fn addMaskFiles(b: *std.Build, mod: *std.Build.Module) void {
const files = [_][2][]const u8{
.{ "mask_profiles", "share/eb-local/mask/profiles.conf" },
.{ "mask_cpuidmask_c", "share/eb-local/mask/cpuidmask.c" },
.{ "mask_armmask_c", "share/eb-local/mask/armmask.c" },
.{ "mask_probe_c", "share/eb-local/mask/cpuid-probe.c" },
.{ "mask_hooks_py", "share/eb-local/mask/eb_local_hooks.py" },
};
for (files) |f| mod.addAnonymousImport(f[0], .{ .root_source_file = b.path(f[1]) });
}

pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{ .default_target = .{ .abi = .musl, .cpu_model = .baseline } });
const optimize = b.standardOptimizeOption(.{ .preferred_optimize_mode = .ReleaseSafe });
Expand Down Expand Up @@ -28,8 +40,12 @@ pub fn build(b: *std.Build) void {
.{ .name = "build_options", .module = options.createModule() },
},
});
addMaskFiles(b, mod);
const exe = b.addExecutable(.{ .name = "eb-local", .root_module = mod, .linkage = .static });
b.installArtifact(exe);
// The sources and profiles the binary embeds, for reading and for builds
// that compile the preload library by hand.
b.installDirectory(.{ .source_dir = b.path("share/eb-local/mask"), .install_dir = .prefix, .install_subdir = "share/eb-local/mask" });

// The Zig autodoc site, into <prefix>/docs, which the documentation
// serves at api/. A compile of its own: asking the installed binary for
Expand Down Expand Up @@ -58,19 +74,17 @@ pub fn build(b: *std.Build) void {
suite_options.addOption([]const u8, "commit", commit);
suite_options.addOption(bool, "test_ops", true);
const suite_common = b.dependency("zig_common", .{ .target = target, .optimize = .Debug });
break :blk b.addExecutable(.{
.name = "eb-local",
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = .Debug,
.imports = &.{
.{ .name = "zig_common", .module = suite_common.module("zig_common") },
.{ .name = "build_options", .module = suite_options.createModule() },
},
}),
.linkage = .static,
const suite_mod = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = .Debug,
.imports = &.{
.{ .name = "zig_common", .module = suite_common.module("zig_common") },
.{ .name = "build_options", .module = suite_options.createModule() },
},
});
addMaskFiles(b, suite_mod);
break :blk b.addExecutable(.{ .name = "eb-local", .root_module = suite_mod, .linkage = .static });
};
const suite = b.addSystemCommand(&.{ "bash", "-c", "EB_LOCAL_BIN=\"$(realpath \"$0\")\" exec python3 -m unittest discover -s tests" });
suite.addArtifactArg(suite_exe);
Expand Down
1 change: 1 addition & 0 deletions changelog.d/+cpu-target.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
`--cpu-target TARGET` builds an easyconfig for another CPU target than the build host's, with `--mask auto|cpuid|kvm|tcg` choosing the route. The `cpuid` route runs the build with CPUID faulting and a target `/proc/cpuinfo` in an unprivileged namespace, refuses to build unless EESSI archdetect, archspec, gcc and the CPUID vendor name the target, pins the GROMACS SIMD level to the target, audits the installed tree and records the route in `easybuild/eb-local-build-mode.json`; `doctor --cpu-target` reports what the host can present.
89 changes: 89 additions & 0 deletions docs/howto/build-for-another-cpu.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<!-- Generated from docs/orgmode/howto/build-for-another-cpu.org by docs/export.el; edit that file. -->

# Build for another CPU target

A build on a Zen 5 machine installs for `x86_64/amd/zen5`.
These steps build the same recipe for `x86_64/amd/zen4`, `x86_64/amd/zen3`, or an Intel target such as `x86_64/intel/icelake`, on that machine, so the tree is installed in the subdirectory the nodes of that target read.

## Before you start

- eb-local that builds on this machine, as [Install software on top of EESSI with EasyBuild](install-software.md) describes; on a workstation without Slurm, add `--workstation`.
- A C compiler (`cc`), `unshare` and `mount` on `PATH`, for the `cpuid` route.
- The easyconfig of the package. Here it is `zlib-2.3.2-GCCcore-15.2.0.eb`.

## Check what this machine can present

```bash
eb-local doctor --cpu-target zen4
```

The lines under `host:` say whether CPUID faulting works (AMD CPUs need Linux 6.17 or later), whether `/dev/kvm` and the QEMU binaries exist, and the last line says which route `--mask auto` takes for the target.
A target with no mask profile, or a host that cannot present it, shows as a `warn` line with the reason.

## Build

```bash
eb-local --workstation --cpu-target zen4 zlib-2.3.2-GCCcore-15.2.0.eb --robot
```

`zen4` means `x86_64/amd/zen4`; the full subdirectory works too, and a short name that two architectures share, such as `generic`, needs the architecture.
Before `eb` starts, the build prints one line per check, all inside the mask:

```text
eb-local: --cpu-target x86_64/amd/zen4, cpuid route (CPUID faulting, namespaced /proc/cpuinfo)
eb-local: preflight ok: /dev/fd exists
eb-local: preflight ok: EESSI archdetect names x86_64/amd/zen4
eb-local: preflight ok: archspec names zen4
eb-local: preflight ok: gcc -march=native is znver4
eb-local: preflight ok: CPUID vendor is AuthenticAMD
eb-local: preflight ok: CPUID faulting is active
```

A line that says `FAILED` stops the build before any compile.
The package installs below `<prefix>/versions/2026.06/software/linux/x86_64/amd/zen4/`.

`eb-local --explain --cpu-target zen4 ...` prints the route and the variables it sets, and runs nothing.

## Read the record of how it was built

Each directory the build installed has `easybuild/eb-local-build-mode.json`:

```json
{
"cpu_target": "x86_64/amd/zen4",
"route": "cpuid",
"profile": "x86_64/amd/zen4",
"host_cpu": "AMD Ryzen 9 9950X 16-Core Processor",
"kernel": "7.0.13-arch1-1-rg",
"eb_local_version": "3.5.0",
"isa_audit": "pass"
}
```

`isa_audit` is `skipped` with `--no-audit`.
The audit, `eb-local audit-isa DIR --target TARGET`, looks for instructions the target does not have; a failure fails the run and the installed tree stays for inspection.

## When a build refuses

| Message | Meaning |
|---|---|
| `CPUID faulting is not available` | The kernel cannot make `CPUID` fault. Use `--mask kvm` on the same architecture, or run on a newer kernel. |
| `the zen4 profile cannot be shown on a GenuineIntel CPU` | The profile for an AMD target keeps the host's vendor string; an Intel host cannot present it. |
| `this CPU lacks avx512_fp16` | A mask removes features and cannot add them. `sapphirerapids` needs a host that has AVX512-FP16 and AMX. |
| `no mask profile exists for ...` | Only the virtual machine routes can present that target. |
| `preflight FAILED: archspec names ...` | An easyblock that asks archspec would build for another CPU than the tree is labelled for. |
| `/dev/fd is missing` | EESSI's `eessi_archdetect.sh` fails without it and EESSI falls back to the generic target. |
| `__vm-run` | This eb-local has no virtual machine helper; the `kvm` and `tcg` routes refuse. |

## GROMACS and Intel targets

GROMACS chooses the SIMD level of a CPU whose brand string says Intel by timing AVX-512 FMA loops.
A Zen 5 core measures one unit and GROMACS picks `AVX2_256`, so an Ice Lake tree built there would be an AVX2 build, unlike the tree EESSI ships.
A `--cpu-target` build adds `-DGMX_SIMD` from the target to every GROMACS configure line (`AVX_512` for `skylake_avx512`, `cascadelake`, `icelake`, `sapphirerapids`, `zen4` and `zen5`; `AVX2_256` for `haswell`, `zen2` and `zen3`), unless the easyconfig sets it.
The EasyBuild log of the build says `eb-local: setting GMX_SIMD=LEVEL for CPU target TARGET`.

## What the mask does not reach

- Statically linked programs, and code that runs before the dynamic loader's constructors, see the real CPU.
- On x86\_64, the `cpuid` route masks the CPUID instruction only. `XGETBV` is not trapped, so a feature that GCC reads from the extended control registers, such as AMX, stays as the host has it.
- On aarch64 the kernel's emulated reads of ID registers cannot be masked; `getauxval` and `/proc/cpuinfo` are.
1 change: 1 addition & 0 deletions docs/howto/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ eb-without-a-site-file
build-for-every-node-type
build-against-a-site-gpu-module
build-for-profiling
build-for-another-cpu
install-what-eessi-lacks
find-what-is-wrong
refresh-the-module-cache
Expand Down
87 changes: 87 additions & 0 deletions docs/orgmode/howto/build-for-another-cpu.org
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#+title: Build for another CPU target

A build on a Zen 5 machine installs for =x86_64/amd/zen5=.
These steps build the same recipe for =x86_64/amd/zen4=, =x86_64/amd/zen3=, or an Intel target such as =x86_64/intel/icelake=, on that machine, so the tree is installed in the subdirectory the nodes of that target read.

* Before you start

- eb-local that builds on this machine, as [[file:install-software.org][Install software on top of EESSI with EasyBuild]] describes; on a workstation without Slurm, add =--workstation=.
- A C compiler (=cc=), =unshare= and =mount= on =PATH=, for the =cpuid= route.
- The easyconfig of the package. Here it is =zlib-2.3.2-GCCcore-15.2.0.eb=.

* Check what this machine can present

#+begin_src bash
eb-local doctor --cpu-target zen4
#+end_src

The lines under =host:= say whether CPUID faulting works (AMD CPUs need Linux 6.17 or later), whether =/dev/kvm= and the QEMU binaries exist, and the last line says which route =--mask auto= takes for the target.
A target with no mask profile, or a host that cannot present it, shows as a =warn= line with the reason.

* Build

#+begin_src bash
eb-local --workstation --cpu-target zen4 zlib-2.3.2-GCCcore-15.2.0.eb --robot
#+end_src

=zen4= means =x86_64/amd/zen4=; the full subdirectory works too, and a short name that two architectures share, such as =generic=, needs the architecture.
Before =eb= starts, the build prints one line per check, all inside the mask:

#+begin_example
eb-local: --cpu-target x86_64/amd/zen4, cpuid route (CPUID faulting, namespaced /proc/cpuinfo)
eb-local: preflight ok: /dev/fd exists
eb-local: preflight ok: EESSI archdetect names x86_64/amd/zen4
eb-local: preflight ok: archspec names zen4
eb-local: preflight ok: gcc -march=native is znver4
eb-local: preflight ok: CPUID vendor is AuthenticAMD
eb-local: preflight ok: CPUID faulting is active
#+end_example

A line that says =FAILED= stops the build before any compile.
The package installs below =<prefix>/versions/2026.06/software/linux/x86_64/amd/zen4/=.

=eb-local --explain --cpu-target zen4 ...= prints the route and the variables it sets, and runs nothing.

* Read the record of how it was built

Each directory the build installed has =easybuild/eb-local-build-mode.json=:

#+begin_src json
{
"cpu_target": "x86_64/amd/zen4",
"route": "cpuid",
"profile": "x86_64/amd/zen4",
"host_cpu": "AMD Ryzen 9 9950X 16-Core Processor",
"kernel": "7.0.13-arch1-1-rg",
"eb_local_version": "3.5.0",
"isa_audit": "pass"
}
#+end_src

=isa_audit= is =skipped= with =--no-audit=.
The audit, =eb-local audit-isa DIR --target TARGET=, looks for instructions the target does not have; a failure fails the run and the installed tree stays for inspection.

* When a build refuses

| Message | Meaning |
|---------+---------|
| =CPUID faulting is not available= | The kernel cannot make =CPUID= fault. Use =--mask kvm= on the same architecture, or run on a newer kernel. |
| =the zen4 profile cannot be shown on a GenuineIntel CPU= | The profile for an AMD target keeps the host's vendor string; an Intel host cannot present it. |
| =this CPU lacks avx512_fp16= | A mask removes features and cannot add them. =sapphirerapids= needs a host that has AVX512-FP16 and AMX. |
| =no mask profile exists for ...= | Only the virtual machine routes can present that target. |
| =preflight FAILED: archspec names ...= | An easyblock that asks archspec would build for another CPU than the tree is labelled for. |
| =/dev/fd is missing= | EESSI's =eessi_archdetect.sh= fails without it and EESSI falls back to the generic target. |
| =__vm-run= | This eb-local has no virtual machine helper; the =kvm= and =tcg= routes refuse. |

* GROMACS and Intel targets

GROMACS chooses the SIMD level of a CPU whose brand string says Intel by timing AVX-512 FMA loops.
A Zen 5 core measures one unit and GROMACS picks =AVX2_256=, so an Ice Lake tree built there would be an AVX2 build, unlike the tree EESSI ships.
A =--cpu-target= build adds =-DGMX_SIMD= from the target to every GROMACS configure line (=AVX_512= for =skylake_avx512=, =cascadelake=, =icelake=, =sapphirerapids=, =zen4= and =zen5=; =AVX2_256= for =haswell=, =zen2= and =zen3=), unless the easyconfig sets it.
The EasyBuild log of the build says =eb-local: setting GMX_SIMD=LEVEL for CPU target TARGET=.

* What the mask does not reach

- Statically linked programs, and code that runs before the dynamic loader's constructors, see the real CPU.
- On x86_64, the =cpuid= route masks the CPUID instruction only. =XGETBV= is not trapped, so a feature that GCC reads from the extended control registers, such as AMX, stays as the host has it.
- On aarch64 the kernel's emulated reads of ID registers cannot be masked; =getauxval= and =/proc/cpuinfo= are.
1 change: 1 addition & 0 deletions docs/orgmode/howto/index.org
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ eb-without-a-site-file
build-for-every-node-type
build-against-a-site-gpu-module
build-for-profiling
build-for-another-cpu
install-what-eessi-lacks
find-what-is-wrong
refresh-the-module-cache
Expand Down
Loading
Loading