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