about summary refs log tree commit diff
path: root/pkgs/development/python-modules/libgpuarray/default.nix
blob: 751d9b2f706d92ef15c224dc1e22018c1907063c (plain) (blame)
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
{
  stdenv,
  lib,
  addDriverRunpath,
  buildPythonPackage,
  fetchFromGitHub,
  cmake,
  cython_0,
  numpy,
  six,
  nose,
  mako,
  config,
  cudaSupport ? config.cudaSupport,
  cudaPackages ? { },
  openclSupport ? true,
  ocl-icd,
  clblas,
}:

buildPythonPackage rec {
  pname = "libgpuarray";
  version = "0.7.6";
  format = "setuptools";

  src = fetchFromGitHub {
    owner = "Theano";
    repo = "libgpuarray";
    rev = "v${version}";
    sha256 = "0ksil18c9ign4xrv5k323flhvdy6wdxh8szdd3nivv31jc3zsdri";
  };

  # requires a GPU
  doCheck = false;

  configurePhase = "cmakeConfigurePhase";

  libraryPath = lib.makeLibraryPath (
    lib.optionals cudaSupport (
      with cudaPackages;
      [
        cudatoolkit.lib
        cudatoolkit.out
      ]
    )
    ++ lib.optionals openclSupport ([ clblas ] ++ lib.optional (!stdenv.isDarwin) ocl-icd)
  );

  preBuild = ''
    make -j$NIX_BUILD_CORES
    make install

    export NIX_CFLAGS_COMPILE="-L $out/lib -I $out/include $NIX_CFLAGS_COMPILE"

    cd ..
  '';

  postFixup =
    ''
      rm $out/lib/libgpuarray-static.a
    ''
    + lib.optionalString (!stdenv.isDarwin) ''
      function fixRunPath {
        p=$(patchelf --print-rpath $1)
        patchelf --set-rpath "$p:$libraryPath" $1
      }

      fixRunPath $out/lib/libgpuarray.so
    ''
    + lib.optionalString cudaSupport ''
      addDriverRunpath $out/lib/libgpuarray.so
    '';

  propagatedBuildInputs = [
    numpy
    six
    mako
  ];

  nativeBuildInputs = [
    cmake
    cython_0
  ] ++ lib.optionals cudaSupport [ addDriverRunpath ];

  buildInputs = [ nose ];

  meta = with lib; {
    homepage = "https://github.com/Theano/libgpuarray";
    description = "Library to manipulate tensors on GPU";
    license = licenses.free;
    maintainers = with maintainers; [ artuuge ];
    platforms = platforms.unix;
  };
}