1{
2 stdenv,
3 lib,
4 addDriverRunpath,
5 buildPythonPackage,
6 fetchFromGitHub,
7 cmake,
8 cython_0,
9 numpy,
10 six,
11 nose,
12 mako,
13 config,
14 cudaSupport ? config.cudaSupport,
15 cudaPackages ? { },
16 openclSupport ? true,
17 ocl-icd,
18 clblas,
19}:
20
21buildPythonPackage rec {
22 pname = "libgpuarray";
23 version = "0.7.6";
24 format = "setuptools";
25
26 src = fetchFromGitHub {
27 owner = "Theano";
28 repo = "libgpuarray";
29 rev = "v${version}";
30 sha256 = "0ksil18c9ign4xrv5k323flhvdy6wdxh8szdd3nivv31jc3zsdri";
31 };
32
33 # requires a GPU
34 doCheck = false;
35
36 configurePhase = "cmakeConfigurePhase";
37
38 libraryPath = lib.makeLibraryPath (
39 lib.optionals cudaSupport (
40 with cudaPackages;
41 [
42 cudatoolkit.lib
43 cudatoolkit.out
44 ]
45 )
46 ++ lib.optionals openclSupport ([ clblas ] ++ lib.optional (!stdenv.isDarwin) ocl-icd)
47 );
48
49 preBuild = ''
50 make -j$NIX_BUILD_CORES
51 make install
52
53 export NIX_CFLAGS_COMPILE="-L $out/lib -I $out/include $NIX_CFLAGS_COMPILE"
54
55 cd ..
56 '';
57
58 postFixup =
59 ''
60 rm $out/lib/libgpuarray-static.a
61 ''
62 + lib.optionalString (!stdenv.isDarwin) ''
63 function fixRunPath {
64 p=$(patchelf --print-rpath $1)
65 patchelf --set-rpath "$p:$libraryPath" $1
66 }
67
68 fixRunPath $out/lib/libgpuarray.so
69 ''
70 + lib.optionalString cudaSupport ''
71 addDriverRunpath $out/lib/libgpuarray.so
72 '';
73
74 propagatedBuildInputs = [
75 numpy
76 six
77 mako
78 ];
79
80 nativeBuildInputs = [
81 cmake
82 cython_0
83 ] ++ lib.optionals cudaSupport [ addDriverRunpath ];
84
85 buildInputs = [ nose ];
86
87 meta = with lib; {
88 homepage = "https://github.com/Theano/libgpuarray";
89 description = "Library to manipulate tensors on GPU";
90 license = licenses.free;
91 maintainers = with maintainers; [ artuuge ];
92 platforms = platforms.unix;
93 };
94}