@@ -17,89 +17,207 @@ extern "C" {
17
17
18
18
using namespace taco ;
19
19
20
- struct AddImpl {
21
- ir::Expr operator ()(const std::vector<ir::Expr>& v) {
22
- return ir::Add::make (v[0 ], v[1 ]);
23
- }
24
- };
25
- Func AddOp (" add" , AddImpl(), {Annihilator (std::numeric_limits<double >::infinity ()), Identity (0 ), Commutative (), Associative ()});
20
+ ir::Expr addImpl (const std::vector<ir::Expr>& v) {
21
+ return ir::Add::make (v[0 ], v[1 ]);
22
+ }
23
+ Func AddOp (" add" , addImpl, {Annihilator (std::numeric_limits<double >::infinity ()), Identity (0 ), Commutative (), Associative ()});
26
24
27
- struct MinImpl {
28
- ir::Expr operator ()(const std::vector<ir::Expr>& v) {
29
- return ir::Min::make (v[0 ], v[1 ]);
30
- }
31
- };
32
- Func MinOp (" min" , MinImpl(), {Identity (std::numeric_limits<double >::infinity ()), Commutative (), Associative ()});
25
+ ir::Expr minImpl (const std::vector<ir::Expr>& v) {
26
+ return ir::Min::make (v[0 ], v[1 ]);
27
+ }
28
+ Func MinOp (" min" , minImpl, {Identity (std::numeric_limits<double >::infinity ()), Commutative (), Associative ()});
33
29
34
- struct MaskImpl {
35
- ir::Expr operator ()(const std::vector<ir::Expr>& v) {
36
- return v[0 ];
37
- }
38
- };
30
+ ir::Expr maskImpl (const std::vector<ir::Expr>& v) {
31
+ return v[0 ];
32
+ }
39
33
struct MaskAlgebra {
40
34
IterationAlgebra operator ()(const std::vector<IndexExpr>& r) {
41
35
return Intersect (r[0 ], Complement (r[1 ]));
42
36
}
43
37
};
44
- Func MaskOp (" mask" , MaskImpl(), MaskAlgebra());
38
+ Func MaskOp (" mask" , maskImpl, MaskAlgebra());
39
+
40
+ // static void bench_mxv_taco(benchmark::State& state) {
41
+ // Format dv({Dense});
42
+ //
43
+ // Tensor<double> T = read("/data/scratch/s3chou/formats-bench/data/webbase_1M.mtx", CSR);
44
+ // Tensor<double> A(T.getDimensions(), CSR, std::numeric_limits<double>::infinity());
45
+ // for (const auto& c : T) {
46
+ // A.insert(c.first.toVector(), c.second);
47
+ // }
48
+ // A.pack();
49
+ //
50
+ // // TODO: Only run for square matrices
51
+ //
52
+ // Tensor<double> x({A.getDimension(1)}, dv, std::numeric_limits<double>::infinity());
53
+ // x.insert({0}, 0.0);
54
+ // x.pack();
55
+ //
56
+ // IndexVar i, j;
57
+ //
58
+ // taco_set_num_threads(12);
59
+ // for (auto _ : state) {
60
+ // state.PauseTiming();
61
+ //
62
+ // Tensor<double> y({A.getDimension(0)}, dv, std::numeric_limits<double>::infinity());
63
+ // y(i) = Reduction(MinOp(), j, AddOp(A(i,j), x(j)));
64
+ // //y(i) = MinOp(Reduction(MinOp(), j, AddOp(A(i,j), x(j))), x(i));
65
+ // //y(i) = MaskOp(Reduction(MinOp(), j, AddOp(A(i,j), x(j))), x(i));
66
+ // //y(i) = MinOp(MaskOp(Reduction(MinOp(), j, AddOp(A(i,j), x(j))), x(i)), x(i));
67
+ // //y(i) = MaskOp(MinOp(Reduction(MinOp(), j, AddOp(A(i,j), x(j))), x(i)), x(i));
68
+ // //y(i) = MinOp(FilterOp(x(i)) * Reduction(MinOp(), j, AddOp(A(i,j), x(j))), x(i));
69
+ //
70
+ // y.compile();
71
+ // y.assemble();
72
+ //
73
+ // state.ResumeTiming();
74
+ //
75
+ // y.compute();
76
+ // }
77
+ // taco_set_num_threads(1);
78
+ // }
79
+ // TACO_BENCH(bench_mxv_taco);
80
+
81
+ // static void bench_mxv_suitesparse(benchmark::State& state) {
82
+ // GrB_init(GrB_BLOCKING);
83
+ // GxB_Global_Option_set(GxB_HYPER_SWITCH, GxB_NEVER_HYPER);
84
+ // GxB_Global_Option_set(GxB_FORMAT, GxB_BY_ROW);
85
+ //
86
+ // int nthreads_max = 12;
87
+ // GxB_Global_Option_set(GxB_NTHREADS, nthreads_max);
88
+ //
89
+ // Tensor<double> T = read("/data/scratch/s3chou/formats-bench/data/webbase_1M.mtx", CSR);
90
+ // GrB_Index M = T.getDimension(0);
91
+ // GrB_Index N = T.getDimension(1);
92
+ // GrB_Matrix A;
93
+ // GrB_Matrix_new(&A, GrB_FP64, M, N);
94
+ // std::vector<GrB_Index> I, J;
95
+ // std::vector<double> V;
96
+ // for (const auto& c : T) {
97
+ // I.push_back(c.first[0]);
98
+ // J.push_back(c.first[1]);
99
+ // V.push_back(c.second);
100
+ // }
101
+ // GrB_Matrix_build_FP64(A, I.data(), J.data(), V.data(), V.size(), GrB_PLUS_FP64);
102
+ // //GrB_Index nnz;
103
+ // //GrB_Matrix_nvals(&nnz, A);
104
+ //
105
+ // GrB_Vector x;
106
+ // GrB_Vector_new(&x, GrB_FP64, N);
107
+ // GrB_Vector_assign_FP64(x, NULL, NULL, 1, GrB_ALL, N, NULL);
108
+ // //GrB_Vector_setElement_FP64(
109
+ //
110
+ // GrB_Vector y;
111
+ // GrB_Vector_new(&y, GrB_FP64, M);
112
+ // //GrB_Vector_assign_FP64(y, NULL, NULL, 0, GrB_ALL, M, NULL);
113
+ //
114
+ // GrB_Descriptor desc;
115
+ // GrB_Descriptor_set (desc, GrB_OUTP, GrB_REPLACE);
116
+ //
117
+ // for (auto _ : state) {
118
+ // GrB_mxv(y, NULL, NULL, GrB_MIN_PLUS_SEMIRING_FP64, A, x, desc);
119
+ // //GrB_vxm(x, NULL, NULL, GrB_MIN_PLUS_SEMIRING_FP64, x, A, desc);
120
+ // }
121
+ // }
122
+
123
+ Format dv ({Dense});
124
+ int nthreads = 4 ;
125
+
126
+ struct GraphBLASFixture {
127
+ GraphBLASFixture () {
128
+ const auto path = " /data/scratch/s3chou/formats-bench/data/webbase_1M.mtx" ;
129
+ Tensor<double > T = read (path, CSR);
130
+
131
+ // TODO: Only run for square matrices
132
+
133
+ A_trop_taco = Tensor<double >(T.getDimensions (), CSR, std::numeric_limits<double >::infinity ());
134
+
135
+ GrB_init (GrB_BLOCKING);
136
+ GxB_Global_Option_set (GxB_HYPER_SWITCH, GxB_NEVER_HYPER);
137
+ GxB_Global_Option_set (GxB_FORMAT, GxB_BY_ROW);
138
+ GxB_Global_Option_set (GxB_NTHREADS, nthreads);
139
+
140
+ GrB_Index M = T.getDimension (0 );
141
+ GrB_Index N = T.getDimension (1 );
142
+ GrB_Matrix_new (&A_trop_gb, GrB_FP64, M, N);
143
+
144
+ std::vector<GrB_Index> I, J;
145
+ std::vector<double > V;
146
+ for (const auto & c : T) {
147
+ I.push_back (c.first [0 ]);
148
+ J.push_back (c.first [1 ]);
149
+ V.push_back (c.second );
150
+ A_trop_taco.insert (c.first .toVector (), c.second );
151
+ }
152
+ GrB_Matrix_build_FP64 (A_trop_gb, I.data (), J.data (), V.data (), V.size (), GrB_PLUS_FP64);
153
+ A_trop_taco.pack ();
154
+
155
+ GrB_Vector_new (&x_trop_gb, GrB_FP64, N);
156
+ GrB_Vector_assign_FP64 (x_trop_gb, NULL , NULL , 1 , GrB_ALL, N, NULL );
157
+
158
+ x_trop_taco = Tensor<double >({T.getDimension (1 )}, dv, std::numeric_limits<double >::infinity ());
159
+ x_trop_taco.insert ({0 }, 0.0 );
160
+ x_trop_taco.pack ();
161
+ }
45
162
46
- static void bench_mxv_taco (benchmark::State& state) {
47
- Format dv ({Dense});
163
+ GrB_Matrix A_trop_gb;
164
+ GrB_Vector x_trop_gb;
165
+ Tensor<double > A_trop_taco;
166
+ Tensor<double > x_trop_taco;
167
+ };
48
168
49
- Tensor<double > T = read (" /data/scratch/s3chou/formats-bench/data/webbase_1M.mtx" , CSR);
50
- Tensor<double > A (T.getDimensions (), CSR, std::numeric_limits<double >::infinity ());
51
- for (const auto & c : T) {
52
- A.insert (c.first .toVector (), c.second );
53
- }
54
- A.pack ();
169
+ GraphBLASFixture fixture;
55
170
56
- // TODO: Only run for square matrices
171
+ static void bench_mxv_suitesparse (benchmark::State& state) {
172
+ GrB_init (GrB_BLOCKING);
173
+ GxB_Global_Option_set (GxB_HYPER_SWITCH, GxB_NEVER_HYPER);
174
+ GxB_Global_Option_set (GxB_FORMAT, GxB_BY_ROW);
175
+ GxB_Global_Option_set (GxB_NTHREADS, nthreads);
176
+
177
+ GrB_Descriptor desc;
178
+ GrB_Descriptor_set (desc, GrB_OUTP, GrB_REPLACE);
179
+
180
+ GrB_Vector y = NULL ;;
181
+ for (auto _ : state) {
182
+ state.PauseTiming ();
57
183
58
- Tensor<double > x ({A.getDimension (1 )}, dv, std::numeric_limits<double >::infinity ());
59
- x.insert ({0 }, 0.0 );
60
- x.pack ();
184
+ GrB_Vector_free (&y);
61
185
62
- IndexVar i, j ;
186
+ state. ResumeTiming () ;
63
187
64
- taco_set_num_threads (12 );
188
+ GrB_Vector_new (&y, GrB_FP64, fixture.A_trop_taco .getDimension (0 ));
189
+ GrB_mxv (y, NULL , NULL , GrB_MIN_PLUS_SEMIRING_FP64, fixture.A_trop_gb , fixture.x_trop_gb , desc);
190
+ // GrB_vxm(x, NULL, NULL, GrB_MIN_PLUS_SEMIRING_FP64, x, A, desc);
191
+ }
192
+ GrB_Vector_free (&y);
193
+ }
194
+
195
+ static void bench_mxv_taco (benchmark::State& state) {
196
+ taco_set_num_threads (nthreads);
65
197
for (auto _ : state) {
66
198
state.PauseTiming ();
67
199
68
- Tensor<double > y ({A.getDimension (0 )}, dv, std::numeric_limits<double >::infinity ());
69
- y (i) = MinOp (Reduction (MinOp (), j, AddOp (A (i,j), x (j))), x (i));
200
+ IndexVar i, j;
201
+ Tensor<double > y ({fixture.A_trop_taco .getDimension (0 )}, dv, std::numeric_limits<double >::infinity ());
202
+ // y(i) = Reduction(MinOp(), j, AddOp(fixture.A_trop_taco(i,j), fixture.x_trop_taco(j)));
203
+ y (i) = MaskOp (Reduction (MinOp (), j, AddOp (fixture.A_trop_taco (i,j), fixture.x_trop_taco (j))), fixture.x_trop_taco (i));
204
+ // y(i) = MinOp(Reduction(MinOp(), j, AddOp(A(i,j), x(j))), x(i));
70
205
// y(i) = MaskOp(Reduction(MinOp(), j, AddOp(A(i,j), x(j))), x(i));
71
206
// y(i) = MinOp(MaskOp(Reduction(MinOp(), j, AddOp(A(i,j), x(j))), x(i)), x(i));
72
207
// y(i) = MaskOp(MinOp(Reduction(MinOp(), j, AddOp(A(i,j), x(j))), x(i)), x(i));
73
208
// y(i) = MinOp(FilterOp(x(i)) * Reduction(MinOp(), j, AddOp(A(i,j), x(j))), x(i));
74
209
75
210
y.compile ();
76
- y.assemble ();
77
211
78
212
state.ResumeTiming ();
79
213
214
+ y.assemble ();
80
215
y.compute ();
81
216
}
82
217
taco_set_num_threads (1 );
83
218
}
84
219
85
- static void bench_mxv_suitesparse (benchmark::State& state) {
86
- GrB_init (GrB_BLOCKING);
87
-
88
- Tensor<double > T = read (" /data/scratch/s3chou/formats-bench/data/webbase_1M.mtx" , CSR);
89
-
90
- for (const auto & c : T) {
91
- // A.insert(c.first.toVector(), c.second);
92
- }
93
-
94
- GrB_Vector x = nullptr ;
95
- GrB_Index n;
96
- GrB_Vector_new (&x, GrB_FP64, n);
97
-
98
- for (auto _ : state) {
99
- }
100
- }
101
-
102
- TACO_BENCH (bench_mxv_taco);
103
- TACO_BENCH (bench_mxv_suitesparse);
220
+ GRAPHBLAS_BENCH (bench_mxv_suitesparse, 1000 );
221
+ GRAPHBLAS_BENCH (bench_mxv_taco, 1000 );
104
222
105
223
#endif
0 commit comments