lol
1{ lib
2, stdenv
3, callPackage
4, stdenvNoCC
5, fetchurl
6, rpmextract
7, _7zz
8, darwin
9, validatePkgConfig
10, enableStatic ? stdenv.hostPlatform.isStatic
11}:
12
13/*
14 For details on using mkl as a blas provider for python packages such as numpy,
15 numexpr, scipy, etc., see the Python section of the NixPkgs manual.
16*/
17let
18 # Release notes and download URLs are here:
19 # https://registrationcenter.intel.com/en/products/
20 version = "${mklVersion}.${rel}";
21
22 mklVersion = "2023.1.0";
23 rel = if stdenvNoCC.isDarwin then "43558" else "46342";
24
25 # Intel openmp uses its own versioning.
26 openmpVersion = "2023.1.0";
27 openmpRel = "46305";
28
29 # Thread Building Blocks release.
30 tbbVersion = "2021.9.0";
31 tbbRel = "43484";
32
33 shlibExt = stdenvNoCC.hostPlatform.extensions.sharedLibrary;
34
35 oneapi-mkl = fetchurl {
36 url = "https://yum.repos.intel.com/oneapi/intel-oneapi-mkl-${mklVersion}-${mklVersion}-${rel}.x86_64.rpm";
37 hash = "sha256-PGLPNnR+11AmmaNxldeze/l2Kw/4+mfjB+RqsPhP6oM=";
38 };
39
40 oneapi-mkl-common = fetchurl {
41 url = "https://yum.repos.intel.com/oneapi/intel-oneapi-mkl-common-${mklVersion}-${mklVersion}-${rel}.noarch.rpm";
42 hash = "sha256-wztTE2R/IdG6ujGf7KFocpRmXzlZSnEKopTBOlPPlBw=";
43 };
44
45 oneapi-mkl-common-devel = fetchurl {
46 url = "https://yum.repos.intel.com/oneapi/intel-oneapi-mkl-common-devel-${mklVersion}-${mklVersion}-${rel}.noarch.rpm";
47 hash = "sha256-MWa8mpyFM4zgDLup+EzFRM+N2Oxf0o6FBBRM8mAanbI=";
48 };
49
50 oneapi-mkl-devel = fetchurl {
51 url = "https://yum.repos.intel.com/oneapi/intel-oneapi-mkl-devel-${mklVersion}-${mklVersion}-${rel}.x86_64.rpm";
52 hash = "sha256-Arq5kXktI92031XqfV0pkzQCHaFsTRKX05iOA/fPNOs=";
53 };
54
55 oneapi-openmp = fetchurl {
56 url = "https://yum.repos.intel.com/oneapi/intel-oneapi-openmp-${mklVersion}-${mklVersion}-${openmpRel}.x86_64.rpm";
57 hash = "sha256-cyBD3P4AEvyreP4pP3BE+yyDB+ptblOQ9GYI8ysGsIM=";
58 };
59
60 oneapi-tbb = fetchurl {
61 url = "https://yum.repos.intel.com/oneapi/intel-oneapi-tbb-${tbbVersion}-${tbbVersion}-${tbbRel}.x86_64.rpm";
62 hash = "sha256-pzJpQdiYVpcKDShePak2I0uEh7u08vJgX7OBF5p5yAM=";
63 };
64
65in stdenvNoCC.mkDerivation ({
66 pname = "mkl";
67 inherit version;
68
69 dontUnpack = stdenvNoCC.isLinux;
70
71 unpackPhase = if stdenvNoCC.isDarwin then ''
72 7zz x $src
73 '' else null;
74
75 nativeBuildInputs = [ validatePkgConfig ] ++ (if stdenvNoCC.isDarwin
76 then
77 [ _7zz darwin.cctools ]
78 else
79 [ rpmextract ]);
80
81 buildPhase = if stdenvNoCC.isDarwin then ''
82 for f in bootstrapper.app/Contents/Resources/packages/*/cupPayload.cup; do
83 tar -xf $f
84 done
85 mkdir -p opt/intel
86 mv _installdir opt/intel/oneapi
87 '' else ''
88 rpmextract ${oneapi-mkl}
89 rpmextract ${oneapi-mkl-common}
90 rpmextract ${oneapi-mkl-common-devel}
91 rpmextract ${oneapi-mkl-devel}
92 rpmextract ${oneapi-openmp}
93 rpmextract ${oneapi-tbb}
94 '';
95
96 installPhase = ''
97 for f in $(find . -name 'mkl*.pc') ; do
98 bn=$(basename $f)
99 substituteInPlace $f \
100 --replace $\{MKLROOT} "$out" \
101 --replace "lib/intel64" "lib"
102
103 sed -r -i "s|^prefix=.*|prefix=$out|g" $f
104 done
105
106 for f in $(find opt/intel -name 'mkl*iomp.pc') ; do
107 substituteInPlace $f --replace "../compiler/lib" "lib"
108 done
109
110 # License
111 install -Dm0655 -t $out/share/doc/mkl opt/intel/oneapi/mkl/${mklVersion}/licensing/license.txt
112
113 # Dynamic libraries
114 mkdir -p $out/lib
115 cp -a opt/intel/oneapi/mkl/${mklVersion}/lib/${lib.optionalString stdenvNoCC.isLinux "intel64"}/*${shlibExt}* $out/lib
116 cp -a opt/intel/oneapi/compiler/${mklVersion}/${if stdenvNoCC.isDarwin then "mac" else "linux"}/compiler/lib/${lib.optionalString stdenvNoCC.isLinux "intel64_lin"}/*${shlibExt}* $out/lib
117 cp -a opt/intel/oneapi/tbb/${tbbVersion}/lib/${lib.optionalString stdenvNoCC.isLinux "intel64/gcc4.8"}/*${shlibExt}* $out/lib
118
119 # Headers
120 cp -r opt/intel/oneapi/mkl/${mklVersion}/include $out/
121
122 # CMake config
123 cp -r opt/intel/oneapi/mkl/${mklVersion}/lib/cmake $out/lib
124 '' +
125 (if enableStatic then ''
126 install -Dm0644 -t $out/lib opt/intel/oneapi/mkl/${mklVersion}/lib/${lib.optionalString stdenvNoCC.isLinux "intel64"}/*.a
127 install -Dm0644 -t $out/lib/pkgconfig opt/intel/oneapi/mkl/${mklVersion}/lib/pkgconfig/*.pc
128 '' else ''
129 cp opt/intel/oneapi/mkl/${mklVersion}/lib/${lib.optionalString stdenvNoCC.isLinux "intel64"}/*${shlibExt}* $out/lib
130 install -Dm0644 -t $out/lib/pkgconfig opt/intel/oneapi/mkl/${mklVersion}/lib/pkgconfig/*dynamic*.pc
131 '') + ''
132 # Setup symlinks for blas / lapack
133 ln -s $out/lib/libmkl_rt${shlibExt} $out/lib/libblas${shlibExt}
134 ln -s $out/lib/libmkl_rt${shlibExt} $out/lib/libcblas${shlibExt}
135 ln -s $out/lib/libmkl_rt${shlibExt} $out/lib/liblapack${shlibExt}
136 ln -s $out/lib/libmkl_rt${shlibExt} $out/lib/liblapacke${shlibExt}
137 '' + lib.optionalString stdenvNoCC.hostPlatform.isLinux ''
138 ln -s $out/lib/libmkl_rt${shlibExt} $out/lib/libblas${shlibExt}".3"
139 ln -s $out/lib/libmkl_rt${shlibExt} $out/lib/libcblas${shlibExt}".3"
140 ln -s $out/lib/libmkl_rt${shlibExt} $out/lib/liblapack${shlibExt}".3"
141 ln -s $out/lib/libmkl_rt${shlibExt} $out/lib/liblapacke${shlibExt}".3"
142 '';
143
144 # fixDarwinDylibName fails for libmkl_cdft_core.dylib because the
145 # larger updated load commands do not fit. Use install_name_tool
146 # explicitly and ignore the error.
147 postFixup = lib.optionalString stdenvNoCC.isDarwin ''
148 for f in $out/lib/*.dylib; do
149 install_name_tool -id $out/lib/$(basename $f) $f || true
150 done
151 install_name_tool -change @rpath/libiomp5.dylib $out/lib/libiomp5.dylib $out/lib/libmkl_intel_thread.dylib
152 install_name_tool -change @rpath/libtbb.12.dylib $out/lib/libtbb.12.dylib $out/lib/libmkl_tbb_thread.dylib
153 install_name_tool -change @rpath/libtbbmalloc.2.dylib $out/lib/libtbbmalloc.2.dylib $out/lib/libtbbmalloc_proxy.dylib
154 '';
155
156 # Per license agreement, do not modify the binary
157 dontStrip = true;
158 dontPatchELF = true;
159
160 passthru.tests = {
161 pkg-config-dynamic-iomp = callPackage ./test { enableStatic = false; execution = "iomp"; };
162 pkg-config-static-iomp = callPackage ./test { enableStatic = true; execution = "iomp"; };
163 pkg-config-dynamic-seq = callPackage ./test { enableStatic = false; execution = "seq"; };
164 pkg-config-static-seq = callPackage ./test { enableStatic = true; execution = "seq"; };
165 };
166
167 meta = with lib; {
168 description = "Intel OneAPI Math Kernel Library";
169 longDescription = ''
170 Intel OneAPI Math Kernel Library (Intel oneMKL) optimizes code with minimal
171 effort for future generations of Intel processors. It is compatible with your
172 choice of compilers, languages, operating systems, and linking and
173 threading models.
174 '';
175 homepage = "https://software.intel.com/en-us/mkl";
176 sourceProvenance = with sourceTypes; [ binaryNativeCode ];
177 license = licenses.issl;
178 platforms = [ "x86_64-linux" "x86_64-darwin" ];
179 maintainers = with maintainers; [ bhipple ];
180 };
181} // lib.optionalAttrs stdenvNoCC.isDarwin {
182 src = fetchurl {
183 url = "https://registrationcenter-download.intel.com/akdlm/IRC_NAS/087a9190-9d96-4b8c-bd2f-79159572ed89/m_onemkl_p_${mklVersion}.${rel}_offline.dmg";
184 hash = "sha256-bUaaJPSaLr60fw0DzDCjPvY/UucHlLbCSLyQxyiAi04=";
185 };
186})