summaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/mx/mxnet/package.nix
blob: ba12c3ad4642e5f67e99533beac75002b2abbb4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
{
  config,
  stdenv,
  lib,
  fetchurl,
  fetchpatch,
  bash,
  cmake,
  opencv4,
  gtest,
  blas,
  gomp,
  llvmPackages,
  perl,
  # mxnet cuda support is turned off, but dependencies like opencv can still be built with cudaSupport
  # and fail to compile without the cudatoolkit
  # mxnet cuda support will not be available, as mxnet requires version <=11
  cudaSupport ? config.cudaSupport,
  cudaPackages ? { },
}:

# mxnet is not maintained, and other projects are migrating away from it.
# https://github.com/apache/mxnet/issues/21206

stdenv.mkDerivation (finalAttrs: {
  pname = "mxnet";
  version = "1.9.1";

  strictDeps = true;
  __structuredAttrs = true;

  src = fetchurl {
    name = "apache-mxnet-src-${finalAttrs.version}-incubating.tar.gz";
    url = "mirror://apache/incubator/mxnet/${finalAttrs.version}/apache-mxnet-src-${finalAttrs.version}-incubating.tar.gz";
    hash = "sha256-EephMoF02MKblvNBl34D3rC/Sww3rOZY+T442euMkyI=";
  };

  patches = [
    # Remove the following two patches when updating mxnet to 2.0.
    (fetchpatch {
      name = "1-auto-disable-sse-for-non-x86.patch";
      url = "https://github.com/apache/incubator-mxnet/commit/55e69871d4cadec51a8bbb6700131065388cb0b9.patch";
      hash = "sha256-uaMpM0F9HRtEBXz2ewB/dlbuKaY5/RineCPUE2T6CHU=";
    })
    (fetchpatch {
      name = "2-auto-disable-sse-for-non-x86.patch";
      url = "https://github.com/apache/incubator-mxnet/commit/c1b96f562f55dfa024ac941d7b104f00e239ee0f.patch";
      excludes = [ "ci/docker/runtime_functions.sh" ];
      hash = "sha256-r1LbC8ueRooW5tTNakAlRSJ+9aR4WXXoEKx895DgOs4=";
    })
  ];

  nativeBuildInputs = [
    cmake
    perl
  ]
  ++ lib.optionals cudaSupport [
    cudaPackages.cuda_nvcc
  ];

  buildInputs = [
    opencv4
    gtest
    blas.provider
  ]
  ++ lib.optional stdenv.cc.isGNU gomp
  ++ lib.optional stdenv.cc.isClang llvmPackages.openmp
  ++ lib.optionals cudaSupport [
    # needed for OpenCV cmake module
    cudaPackages.cuda_cudart
  ];

  cmakeFlags = [
    (lib.cmakeFeature "CMAKE_POLICY_VERSION_MINIMUM" "3.5")
    "-DUSE_MKL_IF_AVAILABLE=OFF"
    "-DUSE_CUDA=OFF"
    "-DUSE_CUDNN=OFF"
  ];

  env.NIX_CFLAGS_COMPILE = toString [
    # Needed with GCC 12
    "-Wno-error=uninitialized"
  ];

  postPatch = ''
    substituteInPlace 3rdparty/mkldnn/tests/CMakeLists.txt \
      --replace "/bin/bash" "${bash}/bin/bash"

    # Build against the system version of OpenMP.
    # https://github.com/apache/incubator-mxnet/pull/12160
    rm -rf 3rdparty/openmp
  '';

  postInstall = ''
    rm "$out"/lib/*.a
  '';

  meta = {
    description = "Lightweight, Portable, Flexible Distributed/Mobile Deep Learning with Dynamic, Mutation-aware Dataflow Dep Scheduler";
    homepage = "https://mxnet.incubator.apache.org/";
    maintainers = [ ];
    license = lib.licenses.asl20;
    platforms = lib.platforms.linux;
  };
})