anvil-editor: init at 0.4
[NixPkgs.git] / pkgs / applications / science / math / mxnet / default.nix
blob880caaff5afb6ef00289f5e1cf989cc687b1656b
1 { config, stdenv, lib, fetchurl, fetchpatch, bash, cmake
2 , opencv4, gtest, blas, gomp, llvmPackages, perl
3 , cudaSupport ? config.cudaSupport, cudaPackages ? { }, nvidia_x11
4 , cudnnSupport ? cudaSupport
5 }:
7 let
8   inherit (cudaPackages) backendStdenv cudatoolkit cudaFlags cudnn;
9 in
11 assert cudnnSupport -> cudaSupport;
13 stdenv.mkDerivation rec {
14   pname = "mxnet";
15   version = "1.9.1";
17   src = fetchurl {
18     name = "apache-mxnet-src-${version}-incubating.tar.gz";
19     url = "mirror://apache/incubator/mxnet/${version}/apache-mxnet-src-${version}-incubating.tar.gz";
20     hash = "sha256-EephMoF02MKblvNBl34D3rC/Sww3rOZY+T442euMkyI=";
21   };
23   patches = [
24     # Remove the following two patches when updating mxnet to 2.0.
25     (fetchpatch {
26       name = "1-auto-disable-sse-for-non-x86.patch";
27       url = "https://github.com/apache/incubator-mxnet/commit/55e69871d4cadec51a8bbb6700131065388cb0b9.patch";
28       hash = "sha256-uaMpM0F9HRtEBXz2ewB/dlbuKaY5/RineCPUE2T6CHU=";
29     })
30     (fetchpatch {
31       name = "2-auto-disable-sse-for-non-x86.patch";
32       url = "https://github.com/apache/incubator-mxnet/commit/c1b96f562f55dfa024ac941d7b104f00e239ee0f.patch";
33       excludes = ["ci/docker/runtime_functions.sh"];
34       hash = "sha256-r1LbC8ueRooW5tTNakAlRSJ+9aR4WXXoEKx895DgOs4=";
35     })
36   ];
38   nativeBuildInputs = [ cmake perl ];
40   buildInputs = [ opencv4 gtest blas.provider ]
41     ++ lib.optional stdenv.cc.isGNU gomp
42     ++ lib.optional stdenv.cc.isClang llvmPackages.openmp
43     # FIXME: when cuda build is fixed, remove nvidia_x11, and use /run/opengl-driver/lib
44     ++ lib.optionals cudaSupport [ cudatoolkit nvidia_x11 ]
45     ++ lib.optional cudnnSupport cudnn;
47   cmakeFlags =
48     [ "-DUSE_MKL_IF_AVAILABLE=OFF" ]
49     ++ (if cudaSupport then [
50       "-DUSE_OLDCMAKECUDA=ON"  # see https://github.com/apache/incubator-mxnet/issues/10743
51       "-DCUDA_ARCH_NAME=All"
52       "-DCUDA_HOST_COMPILER=${backendStdenv.cc}/bin/cc"
53       "-DMXNET_CUDA_ARCH=${builtins.concatStringsSep ";" cudaFlags.realArches}"
54     ] else [ "-DUSE_CUDA=OFF" ])
55     ++ lib.optional (!cudnnSupport) "-DUSE_CUDNN=OFF";
57   env.NIX_CFLAGS_COMPILE = toString [
58     # Needed with GCC 12
59     "-Wno-error=uninitialized"
60   ];
62   postPatch = ''
63     substituteInPlace 3rdparty/mkldnn/tests/CMakeLists.txt \
64       --replace "/bin/bash" "${bash}/bin/bash"
66     # Build against the system version of OpenMP.
67     # https://github.com/apache/incubator-mxnet/pull/12160
68     rm -rf 3rdparty/openmp
69   '';
71   postInstall = ''
72     rm "$out"/lib/*.a
73   '';
75   # used to mark cudaSupport in python310Packages.mxnet as broken;
76   # other attributes exposed for consistency
77   passthru = {
78     inherit cudaSupport cudnnSupport cudatoolkit cudnn;
79   };
81   meta = with lib; {
82     description = "Lightweight, Portable, Flexible Distributed/Mobile Deep Learning with Dynamic, Mutation-aware Dataflow Dep Scheduler";
83     homepage = "https://mxnet.incubator.apache.org/";
84     maintainers = with maintainers; [ abbradar ];
85     license = licenses.asl20;
86     platforms = platforms.unix;
87     # Build failures when linking mxnet_unit_tests: https://gist.github.com/6d17447ee3557967ec52c50d93b17a1d
88     broken = cudaSupport;
89   };