Merge pull request #61019 from volth/gcc.arch-amd

platform.gcc.arch: support for AMD CPUs
This commit is contained in:
John Ericson 2020-09-01 22:31:16 -04:00 committed by GitHub
commit 1965a241fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 168 additions and 95 deletions

View File

@ -0,0 +1,77 @@
{ lib }:
rec {
# platform.gcc.arch to its features (as in /proc/cpuinfo)
features = {
default = [ ];
# x86_64 Intel
westmere = [ "sse3" "ssse3" "sse4_1" "sse4_2" "aes" ];
sandybridge = [ "sse3" "ssse3" "sse4_1" "sse4_2" "aes" "avx" ];
ivybridge = [ "sse3" "ssse3" "sse4_1" "sse4_2" "aes" "avx" ];
haswell = [ "sse3" "ssse3" "sse4_1" "sse4_2" "aes" "avx" "avx2" "fma" ];
broadwell = [ "sse3" "ssse3" "sse4_1" "sse4_2" "aes" "avx" "avx2" "fma" ];
skylake = [ "sse3" "ssse3" "sse4_1" "sse4_2" "aes" "avx" "avx2" "fma" ];
skylake-avx512 = [ "sse3" "ssse3" "sse4_1" "sse4_2" "aes" "avx" "avx2" "avx512" "fma" ];
# x86_64 AMD
btver1 = [ "sse3" "ssse3" "sse4_1" "sse4_2" ];
btver2 = [ "sse3" "ssse3" "sse4_1" "sse4_2" "aes" "avx" ];
bdver1 = [ "sse3" "ssse3" "sse4_1" "sse4_2" "sse4a" "aes" "avx" "fma" "fma4" ];
bdver2 = [ "sse3" "ssse3" "sse4_1" "sse4_2" "sse4a" "aes" "avx" "fma" "fma4" ];
bdver3 = [ "sse3" "ssse3" "sse4_1" "sse4_2" "sse4a" "aes" "avx" "fma" "fma4" ];
bdver4 = [ "sse3" "ssse3" "sse4_1" "sse4_2" "sse4a" "aes" "avx" "avx2" "fma" "fma4" ];
znver1 = [ "sse3" "ssse3" "sse4_1" "sse4_2" "sse4a" "aes" "avx" "avx2" "fma" ];
znver2 = [ "sse3" "ssse3" "sse4_1" "sse4_2" "sse4a" "aes" "avx" "avx2" "fma" ];
# other
armv5te = [ ];
armv6 = [ ];
armv7-a = [ ];
armv8-a = [ ];
mips32 = [ ];
loongson2f = [ ];
};
# a superior CPU has all the features of an inferior and is able to build and test code for it
inferiors = {
# x86_64 Intel
default = [ ];
westmere = [ ];
sandybridge = [ "westmere" ] ++ inferiors.westmere;
ivybridge = [ "sandybridge" ] ++ inferiors.sandybridge;
haswell = [ "ivybridge" ] ++ inferiors.ivybridge;
broadwell = [ "haswell" ] ++ inferiors.haswell;
skylake = [ "broadwell" ] ++ inferiors.broadwell;
skylake-avx512 = [ "skylake" ] ++ inferiors.skylake;
# x86_64 AMD
btver1 = [ ];
btver2 = [ ]; # TODO: fill this (need testing)
bdver1 = [ ]; # TODO: fill this (need testing)
bdver2 = [ ]; # TODO: fill this (need testing)
bdver3 = [ ]; # TODO: fill this (need testing)
bdver4 = [ ]; # TODO: fill this (need testing)
znver1 = [ ]; # TODO: fill this (need testing)
znver2 = [ ]; # TODO: fill this (need testing)
# other
armv5te = [ ];
armv6 = [ ];
armv7-a = [ ];
armv8-a = [ ];
mips32 = [ ];
loongson2f = [ ];
};
predicates = let
featureSupport = feature: x: builtins.elem feature features.${x};
in {
sse3Support = featureSupport "sse3";
ssse3Support = featureSupport "ssse3";
sse4_1Support = featureSupport "sse4_1";
sse4_2Support = featureSupport "sse4_2";
sse4_aSupport = featureSupport "sse4a";
avxSupport = featureSupport "avx";
avx2Support = featureSupport "avx2";
avx512Support = featureSupport "avx512";
aesSupport = featureSupport "aes";
fmaSupport = featureSupport "fma";
fma4Support = featureSupport "fma4";
};
}

View File

@ -7,6 +7,7 @@ rec {
inspect = import ./inspect.nix { inherit lib; };
platforms = import ./platforms.nix { inherit lib; };
examples = import ./examples.nix { inherit lib; };
architectures = import ./architectures.nix { inherit lib; };
# Elaborate a `localSystem` or `crossSystem` so that it contains everything
# necessary.
@ -126,6 +127,7 @@ rec {
else throw "Don't know how to run ${final.config} executables.";
} // mapAttrs (n: v: v final.parsed) inspect.predicates
// mapAttrs (n: v: v final.platform.gcc.arch or "default") architectures.predicates
// args;
in assert final.useAndroidPrebuilt -> final.isAndroid;
assert lib.foldl

View File

@ -587,16 +587,10 @@ in
nix.systemFeatures = mkDefault (
[ "nixos-test" "benchmark" "big-parallel" "kvm" ] ++
optionals (pkgs.stdenv.isx86_64 && pkgs.hostPlatform.platform ? gcc.arch) (
# a x86_64 builder can run code for `platform.gcc.arch` and minor architectures:
[ "gccarch-${pkgs.hostPlatform.platform.gcc.arch}" ] ++ {
sandybridge = [ "gccarch-westmere" ];
ivybridge = [ "gccarch-westmere" "gccarch-sandybridge" ];
haswell = [ "gccarch-westmere" "gccarch-sandybridge" "gccarch-ivybridge" ];
broadwell = [ "gccarch-westmere" "gccarch-sandybridge" "gccarch-ivybridge" "gccarch-haswell" ];
skylake = [ "gccarch-westmere" "gccarch-sandybridge" "gccarch-ivybridge" "gccarch-haswell" "gccarch-broadwell" ];
skylake-avx512 = [ "gccarch-westmere" "gccarch-sandybridge" "gccarch-ivybridge" "gccarch-haswell" "gccarch-broadwell" "gccarch-skylake" ];
}.${pkgs.hostPlatform.platform.gcc.arch} or []
optionals (pkgs.hostPlatform.platform ? gcc.arch) (
# a builder can run code for `platform.gcc.arch` and inferior architectures
[ "gccarch-${pkgs.hostPlatform.platform.gcc.arch}" ] ++
map (x: "gccarch-${x}") lib.systems.architectures.inferiors.${pkgs.hostPlatform.platform.gcc.arch}
)
);

View File

@ -10,15 +10,13 @@ stdenv.mkDerivation rec {
sha256 = "1nym0p2djws8ylkpr0kgpxfa6fxdlh46cmvz0gn5vd02jzgs0aww";
};
outputs = [ "out" "dev" ];
configureFlags = {
configureFlags = [
# Prevent nauty from sniffing some cpu features. While those are very
# widely available, it can lead to nasty bugs when they are not available:
# https://groups.google.com/forum/#!topic/sage-packaging/Pe4SRDNYlhA
default = [ "--disable-clz" "--disable-popcnt" ];
westmere = [ "--disable-clz" ];
sandybridge = [ "--disable-clz" ];
ivybridge = [ "--disable-clz" ];
}.${stdenv.hostPlatform.platform.gcc.arch or "default"} or [];
"--${if stdenv.hostPlatform.sse4_2Support then "enable" else "disable"}-popcnt"
"--${if stdenv.hostPlatform.sse4_aSupport then "enable" else "disable"}-clz"
];
installPhase = ''
mkdir -p "$out"/{bin,share/doc/nauty} "$dev"/{lib,include/nauty}

View File

@ -64,18 +64,26 @@ let
# older compilers (for example bootstrap's GCC 5) fail with -march=too-modern-cpu
isGccArchSupported = arch:
if isGNU then
{ skylake = versionAtLeast ccVersion "6.0";
{ # Intel
skylake = versionAtLeast ccVersion "6.0";
skylake-avx512 = versionAtLeast ccVersion "6.0";
cannonlake = versionAtLeast ccVersion "8.0";
icelake-client = versionAtLeast ccVersion "8.0";
icelake-server = versionAtLeast ccVersion "8.0";
knm = versionAtLeast ccVersion "8.0";
# AMD
znver1 = versionAtLeast ccVersion "6.0";
znver2 = versionAtLeast ccVersion "9.0";
}.${arch} or true
else if isClang then
{ cannonlake = versionAtLeast ccVersion "5.0";
{ # Intel
cannonlake = versionAtLeast ccVersion "5.0";
icelake-client = versionAtLeast ccVersion "7.0";
icelake-server = versionAtLeast ccVersion "7.0";
knm = versionAtLeast ccVersion "7.0";
# AMD
znver1 = versionAtLeast ccVersion "4.0";
znver2 = versionAtLeast ccVersion "9.0";
}.${arch} or true
else
false;

View File

@ -1,5 +1,5 @@
{ stdenv, fetchFromGitHub, readline, libedit, bc
, avxSupport ? false
, avxSupport ? stdenv.hostPlatform.avxSupport
}:
stdenv.mkDerivation rec {

View File

@ -2,7 +2,7 @@
, guiSupport ? false, libX11
# see http://dlib.net/compile.html
, avxSupport ? true
, avxSupport ? stdenv.hostPlatform.avxSupport
, cudaSupport ? true
}:

View File

@ -31,19 +31,21 @@ stdenv.mkDerivation rec {
configureFlags = [
"--with-blas-libs=-lcblas"
"--with-lapack-libs=-llapacke"
] ++ stdenv.lib.optionals stdenv.isx86_64 {
] ++ stdenv.lib.optionals stdenv.isx86_64 [
# disable SIMD instructions (which are enabled *when available* by default)
# for now we need to be careful to disable *all* relevant versions of an instruction set explicitly (https://github.com/linbox-team/fflas-ffpack/issues/284)
default = [ "--disable-sse3" "--disable-ssse3" "--disable-sse41" "--disable-sse42" "--disable-avx" "--disable-avx2" "--disable-avx512f" "--disable-avx512dq" "--disable-avx512vl" "--disable-fma" "--disable-fma4" ];
westmere = [ "--disable-avx" "--disable-avx2" "--disable-avx512f" "--disable-avx512dq" "--disable-avx512vl" "--disable-fma" "--disable-fma4" ];
sandybridge = [ "--disable-avx2" "--disable-avx512f" "--disable-avx512dq" "--disable-avx512vl" "--disable-fma" "--disable-fma4" ];
ivybridge = [ "--disable-avx2" "--disable-avx512f" "--disable-avx512dq" "--disable-avx512vl" "--disable-fma" "--disable-fma4" ];
haswell = [ "--disable-fma4" ];
broadwell = [ "--disable-fma4" ];
skylake = [ "--disable-fma4" ];
skylake-avx512 = [ "--disable-fma4" ];
}.${stdenv.hostPlatform.platform.gcc.arch or "default"};
"--${if stdenv.hostPlatform.sse3Support then "enable" else "disable"}-sse3"
"--${if stdenv.hostPlatform.ssse3Support then "enable" else "disable"}-ssse3"
"--${if stdenv.hostPlatform.sse4_1Support then "enable" else "disable"}-sse41"
"--${if stdenv.hostPlatform.sse4_2Support then "enable" else "disable"}-sse42"
"--${if stdenv.hostPlatform.avxSupport then "enable" else "disable"}-avx"
"--${if stdenv.hostPlatform.avx2Support then "enable" else "disable"}-avx2"
"--${if stdenv.hostPlatform.avx512Support then "enable" else "disable"}-avx512f"
"--${if stdenv.hostPlatform.avx512Support then "enable" else "disable"}-avx512dq"
"--${if stdenv.hostPlatform.avx512Support then "enable" else "disable"}-avx512vl"
"--${if stdenv.hostPlatform.fmaSupport then "enable" else "disable"}-fma"
"--${if stdenv.hostPlatform.fma4Support then "enable" else "disable"}-fma4"
];
doCheck = true;
meta = with stdenv.lib; {

View File

@ -27,16 +27,13 @@ mkDerivation rec {
# Detection script is broken
"-DQGLVIEWER_INCLUDE_DIR=${libqglviewer}/include/QGLViewer"
"-DG2O_BUILD_EXAMPLES=OFF"
] ++ lib.optionals stdenv.isx86_64 ([ "-DDO_SSE_AUTODETECT=OFF" ] ++ {
default = [ "-DDISABLE_SSE3=ON" "-DDISABLE_SSE4_1=ON" "-DDISABLE_SSE4_2=ON" "-DDISABLE_SSE4_A=ON" ];
westmere = [ "-DDISABLE_SSE4_A=ON" ];
sandybridge = [ "-DDISABLE_SSE4_A=ON" ];
ivybridge = [ "-DDISABLE_SSE4_A=ON" ];
haswell = [ "-DDISABLE_SSE4_A=ON" ];
broadwell = [ "-DDISABLE_SSE4_A=ON" ];
skylake = [ "-DDISABLE_SSE4_A=ON" ];
skylake-avx512 = [ "-DDISABLE_SSE4_A=ON" ];
}.${stdenv.hostPlatform.platform.gcc.arch or "default"});
] ++ lib.optionals stdenv.isx86_64 [
"-DDO_SSE_AUTODETECT=OFF"
"-DDISABLE_SSE3=${ if stdenv.hostPlatform.sse3Support then "OFF" else "ON"}"
"-DDISABLE_SSE4_1=${if stdenv.hostPlatform.sse4_1Support then "OFF" else "ON"}"
"-DDISABLE_SSE4_2=${if stdenv.hostPlatform.sse4_2Support then "OFF" else "ON"}"
"-DDISABLE_SSE4_A=${if stdenv.hostPlatform.sse4_aSupport then "OFF" else "ON"}"
];
meta = with lib; {
description = "A General Framework for Graph Optimization";

View File

@ -17,17 +17,17 @@ stdenv.mkDerivation rec {
configureFlags = [
"--disable-optimization"
] ++ stdenv.lib.optionals stdenv.isx86_64 {
] ++ stdenv.lib.optionals stdenv.isx86_64 [
# disable SIMD instructions (which are enabled *when available* by default)
default = [ "--disable-sse3" "--disable-ssse3" "--disable-sse41" "--disable-sse42" "--disable-avx" "--disable-avx2" "--disable-fma" "--disable-fma4" ];
westmere = [ "--disable-avx" "--disable-avx2" "--disable-fma" "--disable-fma4" ];
sandybridge = [ "--disable-avx2" "--disable-fma" "--disable-fma4" ];
ivybridge = [ "--disable-avx2" "--disable-fma" "--disable-fma4" ];
haswell = [ "--disable-fma4" ];
broadwell = [ "--disable-fma4" ];
skylake = [ "--disable-fma4" ];
skylake-avx512 = [ "--disable-fma4" ];
}.${stdenv.hostPlatform.platform.gcc.arch or "default"};
"--${if stdenv.hostPlatform.sse3Support then "enable" else "disable"}-sse3"
"--${if stdenv.hostPlatform.ssse3Support then "enable" else "disable"}-ssse3"
"--${if stdenv.hostPlatform.sse4_1Support then "enable" else "disable"}-sse41"
"--${if stdenv.hostPlatform.sse4_2Support then "enable" else "disable"}-sse42"
"--${if stdenv.hostPlatform.avxSupport then "enable" else "disable"}-avx"
"--${if stdenv.hostPlatform.avx2Support then "enable" else "disable"}-avx2"
"--${if stdenv.hostPlatform.fmaSupport then "enable" else "disable"}-fma"
"--${if stdenv.hostPlatform.fma4Support then "enable" else "disable"}-fma4"
];
# On darwin, tests are linked to dylib in the nix store, so we need to make
# sure tests run after installPhase.

View File

@ -39,18 +39,17 @@ stdenv.mkDerivation rec {
configureFlags = [
"--with-blas-libs=-lblas"
"--disable-optimization"
] ++ stdenv.lib.optionals stdenv.isx86_64 {
] ++ stdenv.lib.optionals stdenv.isx86_64 [
# disable SIMD instructions (which are enabled *when available* by default)
default = [ "--disable-sse3" "--disable-ssse3" "--disable-sse41" "--disable-sse42" "--disable-avx" "--disable-avx2" "--disable-fma" "--disable-fma4" ];
westmere = [ "--disable-avx" "--disable-avx2" "--disable-fma" "--disable-fma4" ];
sandybridge = [ "--disable-avx2" "--disable-fma" "--disable-fma4" ];
ivybridge = [ "--disable-avx2" "--disable-fma" "--disable-fma4" ];
haswell = [ "--disable-fma4" ];
broadwell = [ "--disable-fma4" ];
skylake = [ "--disable-fma4" ];
skylake-avx512 = [ "--disable-fma4" ];
}.${stdenv.hostPlatform.platform.gcc.arch or "default"}
++ stdenv.lib.optionals withSage [
"--${if stdenv.hostPlatform.sse3Support then "enable" else "disable"}-sse3"
"--${if stdenv.hostPlatform.ssse3Support then "enable" else "disable"}-ssse3"
"--${if stdenv.hostPlatform.sse4_1Support then "enable" else "disable"}-sse41"
"--${if stdenv.hostPlatform.sse4_2Support then "enable" else "disable"}-sse42"
"--${if stdenv.hostPlatform.avxSupport then "enable" else "disable"}-avx"
"--${if stdenv.hostPlatform.avx2Support then "enable" else "disable"}-avx2"
"--${if stdenv.hostPlatform.fmaSupport then "enable" else "disable"}-fma"
"--${if stdenv.hostPlatform.fma4Support then "enable" else "disable"}-fma4"
] ++ stdenv.lib.optionals withSage [
"--enable-sage"
];

View File

@ -255,18 +255,18 @@ stdenv.mkDerivation {
"-no-warnings-are-errors"
]
++ (
if (!stdenv.hostPlatform.isx86_64)
then [ "-no-sse2" ]
else lib.optionals (compareVersion "5.9.0" >= 0) {
default = [ "-sse2" "-no-sse3" "-no-ssse3" "-no-sse4.1" "-no-sse4.2" "-no-avx" "-no-avx2" ];
westmere = [ "-sse2" "-sse3" "-ssse3" "-sse4.1" "-sse4.2" "-no-avx" "-no-avx2" ];
sandybridge = [ "-sse2" "-sse3" "-ssse3" "-sse4.1" "-sse4.2" "-avx" "-no-avx2" ];
ivybridge = [ "-sse2" "-sse3" "-ssse3" "-sse4.1" "-sse4.2" "-avx" "-no-avx2" ];
haswell = [ "-sse2" "-sse3" "-ssse3" "-sse4.1" "-sse4.2" "-avx" "-avx2" ];
broadwell = [ "-sse2" "-sse3" "-ssse3" "-sse4.1" "-sse4.2" "-avx" "-avx2" ];
skylake = [ "-sse2" "-sse3" "-ssse3" "-sse4.1" "-sse4.2" "-avx" "-avx2" ];
skylake-avx512 = [ "-sse2" "-sse3" "-ssse3" "-sse4.1" "-sse4.2" "-avx" "-avx2" ];
}.${stdenv.hostPlatform.platform.gcc.arch or "default"}
if (!stdenv.hostPlatform.isx86_64) then [
"-no-sse2"
] else if (compareVersion "5.9.0" >= 0) then [
"-sse2"
"${if stdenv.hostPlatform.sse3Support then "" else "-no"}-sse3"
"${if stdenv.hostPlatform.ssse3Support then "" else "-no"}-ssse3"
"${if stdenv.hostPlatform.sse4_1Support then "" else "-no"}-sse4.1"
"${if stdenv.hostPlatform.sse4_2Support then "" else "-no"}-sse4.2"
"${if stdenv.hostPlatform.avxSupport then "" else "-no"}-avx"
"${if stdenv.hostPlatform.avx2Support then "" else "-no"}-avx2"
] else [
]
)
++ [
"-no-mips_dsp"

View File

@ -1,4 +1,6 @@
{ buildPythonPackage, dlib, python, pytest, more-itertools, avxSupport ? true, lib }:
{ buildPythonPackage, stdenv, lib, dlib, python, pytest, more-itertools
, avxSupport ? stdenv.hostPlatform.avxSupport
}:
buildPythonPackage {
inherit (dlib) name src nativeBuildInputs buildInputs meta;

View File

@ -23,9 +23,9 @@
, xlaSupport ? cudaSupport
# Default from ./configure script
, cudaCapabilities ? [ "3.5" "5.2" ]
, sse42Support ? builtins.elem (stdenv.hostPlatform.platform.gcc.arch or "default") ["westmere" "sandybridge" "ivybridge" "haswell" "broadwell" "skylake" "skylake-avx512"]
, avx2Support ? builtins.elem (stdenv.hostPlatform.platform.gcc.arch or "default") [ "haswell" "broadwell" "skylake" "skylake-avx512"]
, fmaSupport ? builtins.elem (stdenv.hostPlatform.platform.gcc.arch or "default") [ "haswell" "broadwell" "skylake" "skylake-avx512"]
, sse42Support ? stdenv.hostPlatform.sse4_2Support
, avx2Support ? stdenv.hostPlatform.avx2Support
, fmaSupport ? stdenv.hostPlatform.fmaSupport
# Darwin deps
, Foundation, Security
}:

View File

@ -23,9 +23,9 @@
, xlaSupport ? cudaSupport
# Default from ./configure script
, cudaCapabilities ? [ "3.5" "5.2" ]
, sse42Support ? builtins.elem (stdenv.hostPlatform.platform.gcc.arch or "default") ["westmere" "sandybridge" "ivybridge" "haswell" "broadwell" "skylake" "skylake-avx512"]
, avx2Support ? builtins.elem (stdenv.hostPlatform.platform.gcc.arch or "default") [ "haswell" "broadwell" "skylake" "skylake-avx512"]
, fmaSupport ? builtins.elem (stdenv.hostPlatform.platform.gcc.arch or "default") [ "haswell" "broadwell" "skylake" "skylake-avx512"]
, sse42Support ? stdenv.hostPlatform.sse4_2Support
, avx2Support ? stdenv.hostPlatform.avx2Support
, fmaSupport ? stdenv.hostPlatform.fmaSupport
# Darwin deps
, Foundation, Security
}:

View File

@ -32,15 +32,9 @@ let
# do not set GCC's -march=xxx based on builder's /proc/cpuinfo
"-DUSE_OPTIMIZE_FOR_ARCHITECTURE=OFF"
# also avoid using builder's /proc/cpuinfo
] ++
{ westmere = [ "-DHAVE_SSE42=ON" "-DASM_OPTIMIZATIONS=ON" ];
sandybridge = [ "-DHAVE_SSE42=ON" "-DASM_OPTIMIZATIONS=ON" ];
ivybridge = [ "-DHAVE_SSE42=ON" "-DASM_OPTIMIZATIONS=ON" ];
haswell = [ "-DHAVE_SSE42=ON" "-DASM_OPTIMIZATIONS=ON" ];
broadwell = [ "-DHAVE_SSE42=ON" "-DASM_OPTIMIZATIONS=ON" ];
skylake = [ "-DHAVE_SSE42=ON" "-DASM_OPTIMIZATIONS=ON" ];
skylake-avx512 = [ "-DHAVE_SSE42=ON" "-DASM_OPTIMIZATIONS=ON" ];
}.${stdenv.hostPlatform.platform.gcc.arch or ""} or [ "-DHAVE_SSE42=OFF" "-DASM_OPTIMIZATIONS=OFF" ];
"-DHAVE_SSE42=${if stdenv.hostPlatform.sse4_2Support then "ON" else "OFF"}"
"-DASM_OPTIMIZATIONS=${if stdenv.hostPlatform.sse4_2Support then "ON" else "OFF"}"
];
enableParallelBuilding = true;

View File

@ -1,5 +1,5 @@
{ stdenv, fetchgit, curl, jansson, autoconf, automake
, aesni ? true }:
, aesni ? stdenv.hostPlatform.aesSupport }:
let
rev = "8393e03089c0abde61bd5d72aba8f926c3d6eca4";

View File

@ -1,8 +1,8 @@
{ stdenv, fetchFromGitHub
, boost, zlib, openssl
, upnpSupport ? true, miniupnpc ? null
, aesniSupport ? false
, avxSupport ? false
, aesniSupport ? stdenv.hostPlatform.aesSupport
, avxSupport ? stdenv.hostPlatform.avxSupport
}:
assert upnpSupport -> miniupnpc != null;