-
-
Notifications
You must be signed in to change notification settings - Fork 15.4k
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: wrap with openmp in LD_LIBRARY_PATH #48926
Conversation
CC @FRidh @costrouc @xeji @orivej this follows up on my original intention to make Using this, I can successfully build
which is significantly further than I get without it (fails immediately otherwise). Moreover, this package also builds and tests with mkl + openmp: (Note that I'm adding |
SO_NEEDED entry directly to the library, since the license prevents | ||
modification. | ||
*/ | ||
let | ||
version = "${date}.${rel}"; | ||
date = "2019.0"; | ||
rel = "117"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you look at this in split view with whitespace ignored, I didn't really change much; it's just that there's a let ... in ...
in this file now, so the indentation is different.
}; | ||
|
||
libvar = if stdenvNoCC.isDarwin then "DYLD_LIBRARY_PATH" else "LD_LIBRARY_PATH"; | ||
in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose this is unfriendly to overlays being able to override mkl
versions easily. Is there an idiomatic way to proceed? Pass all the versions and fixed-output shas as defaulted parameters? Seems clunky enough that I bet a user who wants to fork it will just copy the expression.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just expose unwrapped mkl
as attribute in pkgs
? Then it can be overridden like any other package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense; updated accordingly!
No attempt on aarch64-linux (full log) The following builds were skipped because they don't evaluate on aarch64-linux: mkl Partial log (click to expand)
|
No attempt on x86_64-linux (full log) The following builds were skipped because they don't evaluate on x86_64-linux: mkl Partial log (click to expand)
|
|
||
libvar = if stdenvNoCC.isDarwin then "DYLD_LIBRARY_PATH" else "LD_LIBRARY_PATH"; | ||
in | ||
stdenvNoCC.mkDerivation rec { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for wrapping. Let's create a hook with makeSetupHook. When the hook is needed, it can be added to the buildInputs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we have to wrap if we want to maintain the large binaries being in a fixed-output derivation, since otherwise our output hash changes based on openmp
(or the setupHook arg). @veprbl's suggestion to expose both attributes instead of keeping the unwrapped one private seems like the best of both worlds, though.
No attempt on aarch64-linux (full log) The following builds were skipped because they don't evaluate on aarch64-linux: mkl Partial log (click to expand)
|
No attempt on x86_64-linux (full log) The following builds were skipped because they don't evaluate on x86_64-linux: mkl Partial log (click to expand)
|
Ping @FRidh any further comments or suggestions for improvement? |
No attempt on aarch64-linux (full log) The following builds were skipped because they don't evaluate on aarch64-linux: mkl Partial log (click to expand)
|
No attempt on x86_64-linux (full log) The following builds were skipped because they don't evaluate on x86_64-linux: mkl Partial log (click to expand)
|
Fixes NixOS#48876. We could also fix this in `numpy` itself, but since any other package using the multi-threaded portions of `mkl` needs this, it makes sense to fix it in the source itself. As mentioned, the upstream binary is very large, so we create a wrapper package for the openmp-dependent setup hook to avoid rebuilding `mkl` itself. With this fix, the setup-hook allows us to simplify `numexpr`; likewise, both `numpy` and `numexpr` pass all of their test cases.
b413feb
to
e8c6458
Compare
@@ -71,8 +74,6 @@ in buildPythonPackage rec { | |||
inherit blasImplementation cfg; | |||
}; | |||
|
|||
doCheck = blasImplementation != "mkl"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Numpy actualy passes all of its test cases with mkl
as its blas
implementation.
@@ -28,6 +28,9 @@ in buildPythonPackage rec { | |||
nativeBuildInputs = [ gfortran pytest ]; | |||
buildInputs = [ blas ]; | |||
|
|||
# If the blas imlementation is MKL, we need to propagate it for the setup-hook. | |||
propagatedBuildInputs = [ ] ++ lib.optional (blasImplementation == "mkl") blas; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since callers all the way up to the top of the stack will need to run mkl
's setup-hook
, it has to be propagated as far as I can tell.
@@ -47,4 +41,4 @@ buildPythonPackage rec { | |||
homepage = "https://github.com/pydata/numexpr"; | |||
license = lib.licenses.mit; | |||
}; | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The setup hook makes mkl
and numpy
"just work", without any customization needed in numexpr
; this passes all of its test cases for both python2 and python3.
No attempt on aarch64-linux (full log) The following builds were skipped because they don't evaluate on aarch64-linux: mkl Partial log (click to expand)
|
No attempt on x86_64-linux (full log) The following builds were skipped because they don't evaluate on x86_64-linux: mkl Partial log (click to expand)
|
Any chance you could take a look, @FRidh? I'm happy to make further changes if you have suggestions for improvement. |
I tried to use these changes to compile Julia with MKL, but I unfortunately I still see
@bhipple any thoughts? https://github.com/tbenst/nixpkgs/blob/master/pkgs/development/compilers/julia-mkl/shared.nix Edit: I believe this happens during the test phase. It seems like Julia itself compiles ok, but when testing the various .jl files, Julia spits this out when it tries to compile .jl code using MKL |
Actually, I've found a much better and more robust way to do this, and will open up a follow-up PR this weekend with the details. The implementation in this PR works -- but only if you're in a builder context where you've sourced the information, which means finished/tested packages may be unusable. |
Fixes #48876. We could also fix this in
numpy
itself, but since any otherpackage using the multi-threaded portions of
mkl
needs this, it makes sense tofix it in the source itself.
As mentioned, the upstream binary is very large, so we create a wrapper package
for the openmp-dependent setup hook to avoid rebuilding
mkl
itself.Things done
sandbox
innix.conf
on non-NixOS)nix-shell -p nox --run "nox-review wip"
./result/bin/
)nix path-info -S
before and after)