-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add x86_64 compute levels as additional system types
When performing distributed builds of machine learning packages, it would be nice if builders without the required SIMD instructions can be excluded as build nodes. Since x86_64 has accumulated a large number of different instruction set extensions, listing all possible extensions would be unwieldy. AMD, Intel, Red Hat, and SUSE have recently defined four different microarchitecture levels that are now part of the x86-64 psABI supplement and will be used in glibc 2.33: https://gitlab.com/x86-psABIs/x86-64-ABI https://lwn.net/Articles/844831/ This change uses libcpuid to detect CPU features and then uses them to add the supported x86_64 levels to the additional system types. For example on a Ryzen 3700X: $ ~/aps/bin/nix -vv --version | grep "Additional system" Additional system types: i686-linux, x86_64-v1-linux, x86_64-v2-linux, x86_64-v3-linux
- Loading branch information
Showing
9 changed files
with
126 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#include "types.hh" | ||
|
||
#if HAVE_LIBCPUID | ||
#include <libcpuid/libcpuid.h> | ||
#endif | ||
|
||
namespace nix { | ||
|
||
#if HAVE_LIBCPUID | ||
|
||
StringSet computeLevels() { | ||
StringSet levels; | ||
|
||
if (!cpuid_present()) | ||
return levels; | ||
|
||
cpu_raw_data_t raw; | ||
cpu_id_t data; | ||
|
||
if (cpuid_get_raw_data(&raw) < 0) | ||
return levels; | ||
|
||
if (cpu_identify(&raw, &data) < 0) | ||
return levels; | ||
|
||
if (!(data.flags[CPU_FEATURE_CMOV] && | ||
data.flags[CPU_FEATURE_CX8] && | ||
data.flags[CPU_FEATURE_FPU] && | ||
data.flags[CPU_FEATURE_FXSR] && | ||
data.flags[CPU_FEATURE_MMX] && | ||
data.flags[CPU_FEATURE_SSE] && | ||
data.flags[CPU_FEATURE_SSE2])) | ||
return levels; | ||
|
||
levels.insert("x86_64-v1"); | ||
|
||
if (!(data.flags[CPU_FEATURE_CX16] && | ||
data.flags[CPU_FEATURE_LAHF_LM] && | ||
data.flags[CPU_FEATURE_POPCNT] && | ||
// SSE3 | ||
data.flags[CPU_FEATURE_PNI] && | ||
data.flags[CPU_FEATURE_SSSE3] && | ||
data.flags[CPU_FEATURE_SSE4_1] && | ||
data.flags[CPU_FEATURE_SSE4_2])) | ||
return levels; | ||
|
||
levels.insert("x86_64-v2"); | ||
|
||
if (!(data.flags[CPU_FEATURE_AVX] && | ||
data.flags[CPU_FEATURE_AVX2] && | ||
data.flags[CPU_FEATURE_F16C] && | ||
data.flags[CPU_FEATURE_FMA3] && | ||
// LZCNT | ||
data.flags[CPU_FEATURE_ABM] && | ||
data.flags[CPU_FEATURE_MOVBE])) | ||
return levels; | ||
|
||
levels.insert("x86_64-v3"); | ||
|
||
if (!(data.flags[CPU_FEATURE_AVX512F] && | ||
data.flags[CPU_FEATURE_AVX512BW] && | ||
data.flags[CPU_FEATURE_AVX512CD] && | ||
data.flags[CPU_FEATURE_AVX512DQ] && | ||
data.flags[CPU_FEATURE_AVX512VL])) | ||
return levels; | ||
|
||
levels.insert("x86_64-v4"); | ||
|
||
return levels; | ||
} | ||
|
||
#else | ||
|
||
StringSet computeLevels() { | ||
return StringSet{}; | ||
} | ||
|
||
#endif // HAVE_LIBCPUID | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include "types.hh" | ||
|
||
namespace nix { | ||
|
||
StringSet computeLevels(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
source common.sh | ||
|
||
if [[ $(uname -ms) = "Linux x86_64" ]]; then | ||
# x86_64 CPUs must always support the baseline | ||
# microarchitecture level. | ||
nix -vv --version | grep -q "x86_64-v1-linux" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters