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