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