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