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