Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mkl: include Intel's libiomp.so in the MKL RPM unpack #52543

Merged
merged 1 commit into from Dec 19, 2018

Conversation

bhipple
Copy link
Contributor

@bhipple bhipple commented Dec 19, 2018

Since Intel's default openmp implementation is available in the same src
tarball, we can just include it in the package. This means that mkl now "just
works" without any environment variables, fragile setup-hooks, or forced
propagation.

Since the openmp implementation is only needed at runtime (and for test cases),
users can substitute a different one if they prefer by exporting it with
LD_PRELOAD, which is how Intel recommends handling this. If they do not do so,
libiomp.so lives next to libmkl_rt.so and thus will be in the RPATH as a
sane default.

Since this still comes from the same src tarball, we can ship it without losing
the fixed-output derivation; likewise, since Hydra is not building or caching
these, shipping these proprietary packages costs no bandwidth for the nix
community.

Motivation for this change

Fixes #48876 with a cleaner, more robust implementation than the one initially proposed in #48926

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Assured whether relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@bhipple
Copy link
Contributor Author

bhipple commented Dec 19, 2018

CC @FRidh @costrouc @markuskowa @veprbl @matthewbauer

I've tested this with numpy, numexpr, scipy and pandas, and it appears to work without issue, and without requiring env vars or setup hooks, which means usages outside of nix builds work. @tbenst I have not tried it with julia, but I suspect it should resolve your issue mentioned in the previous PR.

This takes the runtime package up from 655MB to 663MB, which is relatively minor; since it's not distributed by Hydra it should not cost the common nix infra anything, and for users it'll mean the package works out of the box, while still allowing for the LLVM openmp override if users want to use as much FOSS as possible.

Since Intel's default openmp implementation is available in the same src
tarball, we can just include it in the package. This means that `mkl` now "just
works" without any environment variables, fragile setup-hooks, or forced
propagation.

Since the openmp implementation is only needed at runtime (and for test cases),
users can substitute a different one if they prefer by exporting it with
`LD_PRELOAD`, which is how Intel recommends handling this. If they do not do so,
`libiomp.so` lives next to `libmkl_rt.so` and thus will be in the RPATH as a
sane default.

Since this still comes from the same src tarball, we can ship it without losing
the fixed-output derivation; likewise, since Hydra is not building or caching
these, shipping these proprietary packages costs no bandwidth for the nix
community.
@@ -66,8 +60,8 @@ stdenvNoCC.mkDerivation rec {
outputHashAlgo = "sha256";
outputHashMode = "recursive";
outputHash = if stdenvNoCC.isDarwin
then "1224dln7n8px1rk8biiggf77wjhxh8mzw0hd8zlyjm8i6j8w7i12"
else "0d8ai0wi8drp071acqkm1wv6vyg12010y843y56zzi1pql81xqvx";
then "0000000000000000000000000000000000000000000000000000"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@smaret can you run nix-build -A mkl and let me know what the Darwin hash is, as you did last time?
#47182 (comment)

BTW, is there a way for me to cross compile to Darwin and compute the hash on my own, or is that only available for FOSS platforms?

preBuild = ''
rm site.cfg
ln -s ${numpy.cfg} site.cfg
export LD_LIBRARY_PATH=${llvmPackages.openmp}/lib
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kind of stuff worked fine during the nix build and in nix shells, but fails immediately if you try to install and use it; this whole package as a whole has gotten significantly simpler now that we provide a sane default and just stick with Intel's recommendation to use a runtime LD_PRELOAD if you want something else, since it's not used at build-time and is binary compatible with the LLVM openmp.

@@ -71,8 +71,6 @@ in buildPythonPackage rec {
inherit blasImplementation cfg;
};

doCheck = blasImplementation != "mkl";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of the tests pass just fine now.

@@ -43,16 +30,23 @@ stdenvNoCC.mkDerivation rec {
'' else ''
rpmextract rpm/intel-mkl-common-c-${date}-${rel}-${date}-${rel}.noarch.rpm
rpmextract rpm/intel-mkl-core-rt-${date}-${rel}-${date}-${rel}.x86_64.rpm
rpmextract rpm/intel-openmp-19.0.0-${rel}-19.0.0-${rel}.x86_64.rpm
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the meat of the change: we're just unpacking this extra RPM and putting it next to libmkl_rt.so so it has its dependencies available. Since this comes in the same src tarball, we can maintain this package as an efficient fixed-output derivation while still keeping the nix expression relatively simple.

@FRidh FRidh merged commit 6206a34 into NixOS:master Dec 19, 2018
@bhipple
Copy link
Contributor Author

bhipple commented Dec 19, 2018

Thanks for the quick review and merge @FRidh! While this is ready-to-go for Linux, someone with a Mac needs to find out the output hash for this: https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/libraries/science/math/mkl/default.nix#L63

@agracie agracie mentioned this pull request Dec 27, 2018
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

numpy-mkl: undefined symbol: omp_get_num_procs
3 participants