nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 147 lines 4.3 kB view raw
1{ 2 lib, 3 stdenv, 4 fetchFromGitHub, 5 rocmUpdateScript, 6 cmake, 7 rocm-cmake, 8 rocsparse, 9 clr, 10 gfortran, 11 gtest, 12 openmp, 13 buildTests ? false, 14 buildBenchmarks ? false, 15 buildSamples ? false, 16 gpuTargets ? clr.localGpuTargets or [ ], 17}: 18 19# This can also use cuSPARSE as a backend instead of rocSPARSE 20stdenv.mkDerivation (finalAttrs: { 21 pname = "hipsparse"; 22 version = "7.1.1"; 23 24 outputs = [ 25 "out" 26 ] 27 ++ lib.optionals buildTests [ 28 "test" 29 ] 30 ++ lib.optionals buildSamples [ 31 "sample" 32 ]; 33 34 src = fetchFromGitHub { 35 owner = "ROCm"; 36 repo = "hipSPARSE"; 37 rev = "rocm-${finalAttrs.version}"; 38 hash = "sha256-zaMAsLfUYkMUiA2vnGiK0//+vZwugqt5T6xJU4FBrRo="; 39 }; 40 41 nativeBuildInputs = [ 42 cmake 43 rocm-cmake 44 clr 45 gfortran 46 ]; 47 48 buildInputs = [ 49 rocsparse 50 ] 51 ++ lib.optionals (buildTests || buildBenchmarks) [ 52 gtest 53 ] 54 ++ lib.optionals (buildTests || buildSamples) [ 55 openmp 56 ]; 57 58 cmakeFlags = [ 59 # Manually define CMAKE_INSTALL_<DIR> 60 # See: https://github.com/NixOS/nixpkgs/pull/197838 61 "-DCMAKE_INSTALL_BINDIR=bin" 62 "-DCMAKE_INSTALL_LIBDIR=lib" 63 "-DCMAKE_INSTALL_INCLUDEDIR=include" 64 (lib.cmakeBool "BUILD_CLIENTS_TESTS" buildTests) 65 (lib.cmakeBool "BUILD_CLIENTS_BENCHMARKS" buildBenchmarks) 66 (lib.cmakeBool "BUILD_CLIENTS_SAMPLES" buildSamples) 67 ] 68 ++ lib.optionals (gpuTargets != [ ]) [ 69 "-DAMDGPU_TARGETS=${lib.concatStringsSep ";" gpuTargets}" 70 ]; 71 72 # We have to manually generate the matrices 73 # CMAKE_MATRICES_DIR seems to be reset in clients/tests/CMakeLists.txt 74 postPatch = lib.optionalString buildTests '' 75 mkdir -p matrices 76 77 ln -s ${rocsparse.passthru.matrices.matrix-01}/*.mtx matrices 78 ln -s ${rocsparse.passthru.matrices.matrix-02}/*.mtx matrices 79 ln -s ${rocsparse.passthru.matrices.matrix-03}/*.mtx matrices 80 ln -s ${rocsparse.passthru.matrices.matrix-04}/*.mtx matrices 81 ln -s ${rocsparse.passthru.matrices.matrix-05}/*.mtx matrices 82 ln -s ${rocsparse.passthru.matrices.matrix-06}/*.mtx matrices 83 ln -s ${rocsparse.passthru.matrices.matrix-07}/*.mtx matrices 84 ln -s ${rocsparse.passthru.matrices.matrix-08}/*.mtx matrices 85 ln -s ${rocsparse.passthru.matrices.matrix-09}/*.mtx matrices 86 ln -s ${rocsparse.passthru.matrices.matrix-10}/*.mtx matrices 87 ln -s ${rocsparse.passthru.matrices.matrix-11}/*.mtx matrices 88 ln -s ${rocsparse.passthru.matrices.matrix-12}/*.mtx matrices 89 ln -s ${rocsparse.passthru.matrices.matrix-13}/*.mtx matrices 90 ln -s ${rocsparse.passthru.matrices.matrix-14}/*.mtx matrices 91 ln -s ${rocsparse.passthru.matrices.matrix-15}/*.mtx matrices 92 ln -s ${rocsparse.passthru.matrices.matrix-16}/*.mtx matrices 93 ln -s ${rocsparse.passthru.matrices.matrix-17}/*.mtx matrices 94 ln -s ${rocsparse.passthru.matrices.matrix-18}/*.mtx matrices 95 ln -s ${rocsparse.passthru.matrices.matrix-19}/*.mtx matrices 96 97 # Not used by the original cmake, causes an error 98 rm matrices/*_b.mtx 99 100 echo "deps/convert.cpp -> deps/mtx2csr" 101 hipcc deps/convert.cpp -O3 -o deps/mtx2csr 102 103 for mat in $(ls -1 matrices | cut -d "." -f 1); do 104 echo "mtx2csr: $mat.mtx -> $mat.bin" 105 deps/mtx2csr matrices/$mat.mtx matrices/$mat.bin 106 unlink matrices/$mat.mtx 107 done 108 109 substituteInPlace clients/tests/CMakeLists.txt \ 110 --replace "\''${PROJECT_BINARY_DIR}/matrices" "/build/source/matrices" 111 ''; 112 113 postInstall = 114 lib.optionalString buildTests '' 115 mkdir -p $test/bin 116 mv $out/bin/hipsparse-test $test/bin 117 mv /build/source/matrices $test 118 rmdir $out/bin 119 '' 120 + lib.optionalString buildSamples '' 121 mkdir -p $sample/bin 122 mv clients/staging/example_* $sample/bin 123 patchelf --set-rpath $out/lib:${ 124 lib.makeLibraryPath ( 125 finalAttrs.buildInputs 126 ++ [ 127 clr 128 gfortran.cc 129 ] 130 ) 131 } $sample/bin/example_* 132 ''; 133 134 passthru.updateScript = rocmUpdateScript { 135 name = finalAttrs.pname; 136 inherit (finalAttrs.src) owner; 137 inherit (finalAttrs.src) repo; 138 }; 139 140 meta = { 141 description = "ROCm SPARSE marshalling library"; 142 homepage = "https://github.com/ROCm/hipSPARSE"; 143 license = with lib.licenses; [ mit ]; 144 teams = [ lib.teams.rocm ]; 145 platforms = lib.platforms.linux; 146 }; 147})