Skip to content

Latest commit

 

History

History
95 lines (85 loc) · 5.6 KB

cpu-features.md

File metadata and controls

95 lines (85 loc) · 5.6 KB

Restricting CPU features

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_FEATURES lists 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/cpuinfo shows no AVX512, or if NPY_ENABLE_CPU_FEATURES is set (NumPy refuses both).
  • OPENBLAS_CORETYPE and ATEN_CPU_CAPABILITY select code for the level, which would crash on a CPU without AVX2 or FMA, so they are set only if /proc/cpuinfo confirms 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_CORETYPE affects only OpenBLAS builds with DYNAMIC_ARCH, e.g. in NumPy wheels, Debian, conda-forge.
  • MKL_CBWR branches other than AUTO and COMPATIBLE are available only on Intel CPUs, others silently use AUTO, so MKL results can still differ between Intel and AMD CPUs. Set MKL_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).

Checking code paths in use

Caveats

  • 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 visible RuntimeWarning before. If warnings are turned into errors (e.g., filterwarnings = error in pytest), ignore those, or set REPROSEED_CPU=native.
  • If import numpy fails with "You cannot disable CPU feature ..., since it is part of the baseline optimizations", that NumPy was built to require AVX512. Set REPROSEED_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_THREADS etc. when comparing results.