Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at fix-function-merge 149 lines 4.7 kB view raw
1{ lib 2, stdenv 3, fetchFromGitHub 4, fetchzip 5, rocmUpdateScript 6, cmake 7, rocm-cmake 8, rocprim 9, clr 10, gfortran 11, git 12, gtest 13, boost 14, python3Packages 15, buildTests ? false 16, buildBenchmarks ? false # Seems to depend on tests 17, gpuTargets ? [ ] 18}: 19 20stdenv.mkDerivation (finalAttrs: { 21 pname = "rocsparse"; 22 version = "5.7.1"; 23 24 outputs = [ 25 "out" 26 ] ++ lib.optionals (buildTests || buildBenchmarks) [ 27 "test" 28 ] ++ lib.optionals buildBenchmarks [ 29 "benchmark" 30 ]; 31 32 src = fetchFromGitHub { 33 owner = "ROCm"; 34 repo = "rocSPARSE"; 35 rev = "rocm-${finalAttrs.version}"; 36 hash = "sha256-30q9bqgZJUaNrkMXTAG+Z34yjsQ5DpJP+WBcCiEmF58="; 37 }; 38 39 nativeBuildInputs = [ 40 cmake 41 rocm-cmake 42 clr 43 gfortran 44 ]; 45 46 buildInputs = [ 47 rocprim 48 git 49 ] ++ lib.optionals (buildTests || buildBenchmarks) [ 50 gtest 51 boost 52 python3Packages.python 53 python3Packages.pyyaml 54 ]; 55 56 cmakeFlags = [ 57 "-DCMAKE_CXX_COMPILER=hipcc" 58 # Manually define CMAKE_INSTALL_<DIR> 59 # See: https://github.com/NixOS/nixpkgs/pull/197838 60 "-DCMAKE_INSTALL_BINDIR=bin" 61 "-DCMAKE_INSTALL_LIBDIR=lib" 62 "-DCMAKE_INSTALL_INCLUDEDIR=include" 63 ] ++ lib.optionals (gpuTargets != [ ]) [ 64 "-DAMDGPU_TARGETS=${lib.concatStringsSep ";" gpuTargets}" 65 ] ++ lib.optionals (buildTests || buildBenchmarks) [ 66 "-DBUILD_CLIENTS_TESTS=ON" 67 "-DCMAKE_MATRICES_DIR=/build/source/matrices" 68 "-Dpython=python3" 69 ] ++ lib.optionals buildBenchmarks [ 70 "-DBUILD_CLIENTS_BENCHMARKS=ON" 71 ]; 72 73 # We have to manually generate the matrices 74 postPatch = lib.optionalString (buildTests || buildBenchmarks) '' 75 mkdir -p matrices 76 77 ln -s ${finalAttrs.passthru.matrices.matrix-01}/*.mtx matrices 78 ln -s ${finalAttrs.passthru.matrices.matrix-02}/*.mtx matrices 79 ln -s ${finalAttrs.passthru.matrices.matrix-03}/*.mtx matrices 80 ln -s ${finalAttrs.passthru.matrices.matrix-04}/*.mtx matrices 81 ln -s ${finalAttrs.passthru.matrices.matrix-05}/*.mtx matrices 82 ln -s ${finalAttrs.passthru.matrices.matrix-06}/*.mtx matrices 83 ln -s ${finalAttrs.passthru.matrices.matrix-07}/*.mtx matrices 84 ln -s ${finalAttrs.passthru.matrices.matrix-08}/*.mtx matrices 85 ln -s ${finalAttrs.passthru.matrices.matrix-09}/*.mtx matrices 86 ln -s ${finalAttrs.passthru.matrices.matrix-10}/*.mtx matrices 87 ln -s ${finalAttrs.passthru.matrices.matrix-11}/*.mtx matrices 88 ln -s ${finalAttrs.passthru.matrices.matrix-12}/*.mtx matrices 89 ln -s ${finalAttrs.passthru.matrices.matrix-13}/*.mtx matrices 90 ln -s ${finalAttrs.passthru.matrices.matrix-14}/*.mtx matrices 91 ln -s ${finalAttrs.passthru.matrices.matrix-15}/*.mtx matrices 92 ln -s ${finalAttrs.passthru.matrices.matrix-16}/*.mtx matrices 93 ln -s ${finalAttrs.passthru.matrices.matrix-17}/*.mtx matrices 94 ln -s ${finalAttrs.passthru.matrices.matrix-18}/*.mtx matrices 95 ln -s ${finalAttrs.passthru.matrices.matrix-19}/*.mtx matrices 96 ln -s ${finalAttrs.passthru.matrices.matrix-20}/*.mtx matrices 97 ln -s ${finalAttrs.passthru.matrices.matrix-21}/*.mtx matrices 98 ln -s ${finalAttrs.passthru.matrices.matrix-22}/*.mtx matrices 99 ln -s ${finalAttrs.passthru.matrices.matrix-23}/*.mtx matrices 100 ln -s ${finalAttrs.passthru.matrices.matrix-24}/*.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.csr" 110 deps/mtx2csr matrices/$mat.mtx matrices/$mat.csr 111 unlink matrices/$mat.mtx 112 done 113 ''; 114 115 postInstall = lib.optionalString buildBenchmarks '' 116 mkdir -p $benchmark/bin 117 cp -a $out/bin/* $benchmark/bin 118 rm $benchmark/bin/rocsparse-test 119 '' + lib.optionalString (buildTests || buildBenchmarks) '' 120 mkdir -p $test/bin 121 mv $out/bin/* $test/bin 122 rm $test/bin/rocsparse-bench || true 123 mv /build/source/matrices $test 124 rmdir $out/bin 125 ''; 126 127 passthru = { 128 matrices = import ./deps.nix { 129 inherit fetchzip; 130 mirror1 = "https://sparse.tamu.edu/MM"; 131 mirror2 = "https://www.cise.ufl.edu/research/sparse/MM"; 132 }; 133 134 updateScript = rocmUpdateScript { 135 name = finalAttrs.pname; 136 owner = finalAttrs.src.owner; 137 repo = finalAttrs.src.repo; 138 }; 139 }; 140 141 meta = with lib; { 142 description = "ROCm SPARSE implementation"; 143 homepage = "https://github.com/ROCm/rocSPARSE"; 144 license = with licenses; [ mit ]; 145 maintainers = teams.rocm.members; 146 platforms = platforms.linux; 147 broken = versions.minor finalAttrs.version != versions.minor stdenv.cc.version || versionAtLeast finalAttrs.version "6.0.0"; 148 }; 149})