Numerical libraries choose CPU-specific (SIMD) code paths at run time,
e.g. AVX512 exp in NumPy or matrix multiplication kernels in
OpenBLAS, which can produce results differing in the last
bits on different CPUs. reproseed.sh therefore restricts them to the
x86-64 microarchitecture level given in
REPROSEED_CPU.
On x86-64 it defaults to x86-64-v3 (AVX2 and FMA, supported by most
CPUs since Intel Haswell and AMD Excavator/Zen), for which the
following variables are exported:
| Library | Variable | Value |
|---|---|---|
| NumPy | NPY_DISABLE_CPU_FEATURES |
see below |
| OpenBLAS | OPENBLAS_CORETYPE |
Haswell |
| MKL | MKL_CBWR |
AVX2 |
| PyTorch | ATEN_CPU_CAPABILITY |
avx2 |
| oneDNN | ONEDNN_MAX_CPU_ISA |
AVX2 |
| oneDNN < 2.5 | DNNL_MAX_CPU_ISA |
AVX2 |
NPY_DISABLE_CPU_FEATURESlists the AVX512 targets of NumPy < 2.4 (AVX512F AVX512_SKX AVX512_ICL AVX512_SPR) and >= 2.4 (X86_V4 AVX512_ICL AVX512_SPR), since disabling one target does not disable the others. It is not set if/proc/cpuinfoshows no AVX512, or ifNPY_ENABLE_CPU_FEATURESis set (NumPy refuses both).OPENBLAS_CORETYPEandATEN_CPU_CAPABILITYselect code for the level, which would crash on a CPU without AVX2 or FMA, so they are set only if/proc/cpuinfoconfirms those. That excludes some Pentium/Celeron/Atom CPUs, VMs with a generic CPU model (e.g.,qemu64), and non-Linux systems; results there might differ.OPENBLAS_CORETYPEaffects only OpenBLAS builds withDYNAMIC_ARCH, e.g. in NumPy wheels, Debian, conda-forge.MKL_CBWRbranches other thanAUTOandCOMPATIBLEare available only on Intel CPUs, others silently useAUTO, so MKL results can still differ between Intel and AMD CPUs. SetMKL_CBWR=COMPATIBLE(slower) to avoid that.- oneDNN is used by PyTorch and TensorFlow.
Variables already set by the caller, even to an empty value, are left
as they are. With REPROSEED_CPU=native none of them is set. It is the default on other
architectures (e.g., aarch64), for which no restrictions are implemented
(yet).
- NumPy and its OpenBLAS:
numpy.show_runtime()(OpenBLASarchitecturerequires threadpoolctl) - PyTorch:
torch.backends.cpu.get_cpu_capability() - oneDNN:
ONEDNN_VERBOSE=1
- NumPy warns on import about listed features it does not know (or, in
NumPy 1.20-1.24, the CPU lacks): with an
ImportWarning, hidden by default, since NumPy 1.25, but with a visibleRuntimeWarningbefore. If warnings are turned into errors (e.g.,filterwarnings = errorin pytest), ignore those, or setREPROSEED_CPU=native. - If
import numpyfails with "You cannot disable CPU feature ..., since it is part of the baseline optimizations", that NumPy was built to require AVX512. SetREPROSEED_CPU=native. - Results of multi-threaded computation (e.g., OpenBLAS, MKL, OpenMP
reductions, ANTs) can also depend on the number of threads, so
use the same
OMP_NUM_THREADS,OPENBLAS_NUM_THREADS,MKL_NUM_THREADS,ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADSetc. when comparing results.