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