Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at flake-libs 161 lines 4.9 kB view raw
1{ 2 lib, 3 stdenv, 4 fetchFromGitHub, 5 fetchzip, 6 rocmUpdateScript, 7 cmake, 8 rocm-cmake, 9 rocprim, 10 clr, 11 gfortran, 12 git, 13 gtest, 14 boost, 15 python3Packages, 16 buildTests ? false, 17 buildBenchmarks ? false, # Seems to depend on tests 18 gpuTargets ? clr.localGpuTargets or clr.gpuTargets, 19}: 20 21stdenv.mkDerivation (finalAttrs: { 22 pname = "rocsparse${clr.gpuArchSuffix}"; 23 version = "6.3.3"; 24 25 outputs = 26 [ 27 "out" 28 ] 29 ++ lib.optionals (buildTests || buildBenchmarks) [ 30 "test" 31 ] 32 ++ lib.optionals buildBenchmarks [ 33 "benchmark" 34 ]; 35 36 src = fetchFromGitHub { 37 owner = "ROCm"; 38 repo = "rocSPARSE"; 39 rev = "rocm-${finalAttrs.version}"; 40 hash = "sha256-6Cut5rbyqKFzHaXfJZGApyY9Mj1Zq/+U8MkXgy4X4Pw="; 41 }; 42 43 nativeBuildInputs = [ 44 cmake 45 # no ninja, it buffers console output and nix times out long periods of no output 46 rocm-cmake 47 clr 48 gfortran 49 ]; 50 51 buildInputs = 52 [ 53 rocprim 54 git 55 ] 56 ++ lib.optionals (buildTests || buildBenchmarks) [ 57 gtest 58 boost 59 python3Packages.python 60 python3Packages.pyyaml 61 ]; 62 63 cmakeFlags = 64 [ 65 "-DCMAKE_BUILD_TYPE=Release" 66 # Manually define CMAKE_INSTALL_<DIR> 67 # See: https://github.com/NixOS/nixpkgs/pull/197838 68 "-DCMAKE_INSTALL_BINDIR=bin" 69 "-DCMAKE_INSTALL_LIBDIR=lib" 70 "-DCMAKE_INSTALL_INCLUDEDIR=include" 71 ] 72 ++ lib.optionals (gpuTargets != [ ]) [ 73 "-DAMDGPU_TARGETS=${lib.concatStringsSep ";" gpuTargets}" 74 ] 75 ++ lib.optionals (buildTests || buildBenchmarks) [ 76 "-DBUILD_CLIENTS_TESTS=ON" 77 "-DCMAKE_MATRICES_DIR=/build/source/matrices" 78 "-Dpython=python3" 79 ] 80 ++ lib.optionals buildBenchmarks [ 81 "-DBUILD_CLIENTS_BENCHMARKS=ON" 82 ]; 83 84 # We have to manually generate the matrices 85 postPatch = lib.optionalString (buildTests || buildBenchmarks) '' 86 mkdir -p matrices 87 88 ln -s ${finalAttrs.passthru.matrices.matrix-01}/*.mtx matrices 89 ln -s ${finalAttrs.passthru.matrices.matrix-02}/*.mtx matrices 90 ln -s ${finalAttrs.passthru.matrices.matrix-03}/*.mtx matrices 91 ln -s ${finalAttrs.passthru.matrices.matrix-04}/*.mtx matrices 92 ln -s ${finalAttrs.passthru.matrices.matrix-05}/*.mtx matrices 93 ln -s ${finalAttrs.passthru.matrices.matrix-06}/*.mtx matrices 94 ln -s ${finalAttrs.passthru.matrices.matrix-07}/*.mtx matrices 95 ln -s ${finalAttrs.passthru.matrices.matrix-08}/*.mtx matrices 96 ln -s ${finalAttrs.passthru.matrices.matrix-09}/*.mtx matrices 97 ln -s ${finalAttrs.passthru.matrices.matrix-10}/*.mtx matrices 98 ln -s ${finalAttrs.passthru.matrices.matrix-11}/*.mtx matrices 99 ln -s ${finalAttrs.passthru.matrices.matrix-12}/*.mtx matrices 100 ln -s ${finalAttrs.passthru.matrices.matrix-13}/*.mtx matrices 101 ln -s ${finalAttrs.passthru.matrices.matrix-14}/*.mtx matrices 102 ln -s ${finalAttrs.passthru.matrices.matrix-15}/*.mtx matrices 103 ln -s ${finalAttrs.passthru.matrices.matrix-16}/*.mtx matrices 104 ln -s ${finalAttrs.passthru.matrices.matrix-17}/*.mtx matrices 105 ln -s ${finalAttrs.passthru.matrices.matrix-18}/*.mtx matrices 106 ln -s ${finalAttrs.passthru.matrices.matrix-19}/*.mtx matrices 107 ln -s ${finalAttrs.passthru.matrices.matrix-20}/*.mtx matrices 108 ln -s ${finalAttrs.passthru.matrices.matrix-21}/*.mtx matrices 109 ln -s ${finalAttrs.passthru.matrices.matrix-22}/*.mtx matrices 110 ln -s ${finalAttrs.passthru.matrices.matrix-23}/*.mtx matrices 111 ln -s ${finalAttrs.passthru.matrices.matrix-24}/*.mtx matrices 112 113 # Not used by the original cmake, causes an error 114 rm matrices/*_b.mtx 115 116 echo "deps/convert.cpp -> deps/mtx2csr" 117 hipcc deps/convert.cpp -O3 -o deps/mtx2csr 118 119 for mat in $(ls -1 matrices | cut -d "." -f 1); do 120 echo "mtx2csr: $mat.mtx -> $mat.csr" 121 deps/mtx2csr matrices/$mat.mtx matrices/$mat.csr 122 unlink matrices/$mat.mtx 123 done 124 ''; 125 126 postInstall = 127 lib.optionalString buildBenchmarks '' 128 mkdir -p $benchmark/bin 129 cp -a $out/bin/* $benchmark/bin 130 rm $benchmark/bin/rocsparse-test 131 '' 132 + lib.optionalString (buildTests || buildBenchmarks) '' 133 mkdir -p $test/bin 134 mv $out/bin/* $test/bin 135 rm $test/bin/rocsparse-bench || true 136 mv /build/source/matrices $test 137 rmdir $out/bin 138 ''; 139 140 passthru = { 141 matrices = import ./deps.nix { 142 inherit fetchzip; 143 mirror1 = "https://sparse.tamu.edu/MM"; 144 mirror2 = "https://www.cise.ufl.edu/research/sparse/MM"; 145 }; 146 147 updateScript = rocmUpdateScript { 148 name = finalAttrs.pname; 149 inherit (finalAttrs.src) owner; 150 inherit (finalAttrs.src) repo; 151 }; 152 }; 153 154 meta = with lib; { 155 description = "ROCm SPARSE implementation"; 156 homepage = "https://github.com/ROCm/rocSPARSE"; 157 license = with licenses; [ mit ]; 158 teams = [ teams.rocm ]; 159 platforms = platforms.linux; 160 }; 161})