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