From 9732c44225910d5726ff95a7ab8c9a4684dfec4d Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Sun, 3 Mar 2019 14:21:04 +0100 Subject: [PATCH 1/2] dlib: add flag to disable AVX support Especially older hardware doesn't support AVX instructions. DLib is still functional there, but significantly slower[1]. By setting `avxInstructions` to false, DLib will be compiled without this feature. [1] http://dlib.net/compile.html --- doc/package-notes.xml | 27 +++++++++++++++++++ pkgs/development/libraries/dlib/default.nix | 5 ++++ .../python-modules/dlib/default.nix | 7 ++++- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/doc/package-notes.xml b/doc/package-notes.xml index e23593107d8d..c93f99d256b9 100644 --- a/doc/package-notes.xml +++ b/doc/package-notes.xml @@ -882,6 +882,33 @@ citrix_receiver.override { On NixOS it can be installed using the following expression: { pkgs, ... }: { fonts.fonts = with pkgs; [ noto-fonts-emoji ]; +} + + + +
+ DLib + + + DLib is a modern, C++-based toolkit which + provides several machine learning algorithms. + + +
+ Compiling without AVX support + + + Especially older CPUs don't support + AVX + (Advanced Vector Extensions) instructions that are used by DLib to + optimize their algorithms. + + + + On the affected hardware errors like Illegal instruction will occur. + In those cases AVX support needs to be disabled: +self: super: { + dlib = super.dlib.override { avxSupport = false; }; }
diff --git a/pkgs/development/libraries/dlib/default.nix b/pkgs/development/libraries/dlib/default.nix index a88b3f1b9b68..67a56855bb79 100644 --- a/pkgs/development/libraries/dlib/default.nix +++ b/pkgs/development/libraries/dlib/default.nix @@ -1,5 +1,8 @@ { stdenv, lib, fetchFromGitHub, cmake, pkgconfig, libpng, libjpeg , guiSupport ? false, libX11 + + # see http://dlib.net/compile.html +, avxSupport ? true }: stdenv.mkDerivation rec { @@ -17,6 +20,8 @@ stdenv.mkDerivation rec { rm -rf dlib/external ''; + cmakeFlags = [ "-DUSE_AVX_INSTRUCTIONS=${if avxSupport then "yes" else "no"}" ]; + enableParallelBuilding = true; nativeBuildInputs = [ cmake pkgconfig ]; buildInputs = [ libpng libjpeg ] ++ lib.optional guiSupport libX11; diff --git a/pkgs/development/python-modules/dlib/default.nix b/pkgs/development/python-modules/dlib/default.nix index 90e2c526789f..c200b6959b64 100644 --- a/pkgs/development/python-modules/dlib/default.nix +++ b/pkgs/development/python-modules/dlib/default.nix @@ -1,12 +1,17 @@ -{ buildPythonPackage, dlib, python, pytest }: +{ buildPythonPackage, dlib, python, pytest, avxSupport ? true }: buildPythonPackage { inherit (dlib) name src nativeBuildInputs buildInputs meta; + # although AVX can be enabled, we never test with it. Some Hydra machines + # fail because of this, however their build results are probably used on hardware + # with AVX support. checkPhase = '' ${python.interpreter} nix_run_setup test --no USE_AVX_INSTRUCTIONS ''; + setupPyBuildFlags = [ "--${if avxSupport then "yes" else "no"} USE_AVX_INSTRUCTIONS" ]; + patches = [ ./build-cores.patch ]; checkInputs = [ pytest ]; From 6fec5aac83e7ad4206050fab82d8e913a8f657bf Mon Sep 17 00:00:00 2001 From: Maximilian Bosch Date: Sun, 3 Mar 2019 14:23:27 +0100 Subject: [PATCH 2/2] pythonPackages.face_recognition: 1.2.2 -> 1.2.3 There's no git tag for 1.2.3, hence we need to pin to the corresponding revision because we build from a git source. After recent breakage on Hydra[1], the tests were disabled. Although some build machines don't support AVX, we shouldn't use a DLib without AVX as the builder's result is also used on modern machines with AVX support. Before merging changes, maintainers should run the check phase locally in a `nix-shell`. [1] https://hydra.nixos.org/build/89533530 --- .../python-modules/face_recognition/default.nix | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/pkgs/development/python-modules/face_recognition/default.nix b/pkgs/development/python-modules/face_recognition/default.nix index b532c7d19f73..2856eeeab1b9 100644 --- a/pkgs/development/python-modules/face_recognition/default.nix +++ b/pkgs/development/python-modules/face_recognition/default.nix @@ -4,13 +4,13 @@ buildPythonPackage rec { pname = "face_recognition"; - version = "1.2.2"; + version = "1.2.3"; src = fetchFromGitHub { repo = pname; owner = "ageitgey"; - rev = "v${version}"; - sha256 = "17jnyr80j1p74gyvh1jabvwd3zsxvip2y7cjhh2g6gsjv2dpvrjv"; + rev = "634db2e4309a365cee2503cb65d6f2e88f519d1e"; + sha256 = "06zw5hq417d5yp17zynhxhb73074lx2qy64fqfzf711rw5vrn2mx"; }; postPatch = '' @@ -19,6 +19,15 @@ buildPythonPackage rec { propagatedBuildInputs = [ pillow click dlib numpy face_recognition_models ]; + # Our dlib is compiled with AVX instructions by default which breaks + # with "Illegal instruction" on some builders due to missing hardware features. + # + # As this makes the build fairly unreliable, it's better to skip the test and to ensure that + # the build is working and after each change to the package, manual testing should be done. + doCheck = false; + + # Although tests are disabled by default, checkPhase still exists, so + # maintainers can check the package's functionality locally before modifying it. checkInputs = [ flake8 pytest glibcLocales ]; checkPhase = '' LC_ALL="en_US.UTF-8" py.test