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