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