1{ stdenv
2, lib
3, addOpenGLRunpath
4, buildPythonPackage
5, fetchFromGitHub
6, cmake
7, cython
8, numpy
9, six
10, nose
11, mako
12, config
13, cudaSupport ? config.cudaSupport
14, cudaPackages ? { }
15, openclSupport ? true, ocl-icd, clblas
16}:
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 lib.optionals cudaSupport (with cudaPackages; [ cudatoolkit.lib cudatoolkit.out ])
36 ++ lib.optionals openclSupport ([ clblas ] ++ lib.optional (!stdenv.isDarwin) ocl-icd)
37 );
38
39 preBuild = ''
40 make -j$NIX_BUILD_CORES
41 make install
42
43 export NIX_CFLAGS_COMPILE="-L $out/lib -I $out/include $NIX_CFLAGS_COMPILE"
44
45 cd ..
46 '';
47
48 postFixup = ''
49 rm $out/lib/libgpuarray-static.a
50 '' + lib.optionalString (!stdenv.isDarwin) ''
51 function fixRunPath {
52 p=$(patchelf --print-rpath $1)
53 patchelf --set-rpath "$p:$libraryPath" $1
54 }
55
56 fixRunPath $out/lib/libgpuarray.so
57 '' + lib.optionalString cudaSupport ''
58 addOpenGLRunpath $out/lib/libgpuarray.so
59 '';
60
61 propagatedBuildInputs = [
62 numpy
63 six
64 mako
65 ];
66
67 nativeBuildInputs = [
68 cmake
69 ] ++ lib.optionals cudaSupport [
70 addOpenGLRunpath
71 ];
72
73
74 buildInputs = [
75 cython
76 nose
77 ];
78
79 meta = with lib; {
80 homepage = "https://github.com/Theano/libgpuarray";
81 description = "Library to manipulate tensors on GPU.";
82 license = licenses.free;
83 maintainers = with maintainers; [ artuuge ];
84 platforms = platforms.unix;
85 };
86
87}