Skip to content

Commit 14c6e85

Browse files
committed
taco: add a suitesparse ufunc benchmark for taco
1 parent c681e36 commit 14c6e85

File tree

2 files changed

+74
-2
lines changed

2 files changed

+74
-2
lines changed

taco/bench.h

+13-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ taco::Tensor<T> shiftLastMode(std::string name, taco::Tensor<T2> original) {
5959
}
6060

6161
template<typename T>
62-
taco::Tensor<T> readIntoType(std::string name, std::string path, taco::ModeFormat format) {
63-
auto tensor = taco::read(path, format);
62+
taco::Tensor<T> castToType(std::string name, taco::Tensor<double> tensor) {
6463
taco::Tensor<T> result(name, tensor.getDimensions(), tensor.getFormat());
6564
std::vector<int> coords(tensor.getOrder());
6665
for (auto& value : taco::iterate<double>(tensor)) {
@@ -73,4 +72,16 @@ taco::Tensor<T> readIntoType(std::string name, std::string path, taco::ModeForma
7372
return result;
7473
}
7574

75+
template<typename T>
76+
taco::Tensor<T> readIntoType(std::string name, std::string path, taco::ModeFormat format) {
77+
auto tensor = taco::read(path, format);
78+
return castToType<T>(name, tensor);
79+
}
80+
81+
template<typename T>
82+
taco::Tensor<T> readIntoType(std::string name, std::string path, taco::Format format) {
83+
auto tensor = taco::read(path, format);
84+
return castToType<T>(name, tensor);
85+
}
86+
7687
#endif //TACO_BENCH_BENCH_H

taco/ufuncs.cpp

+61
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#include <fstream>
2+
// We're using c++14, so wer're stuck with experimental filesystem.
3+
#include <experimental/filesystem>
4+
25
#include "bench.h"
36
#include "benchmark/benchmark.h"
47

@@ -206,3 +209,61 @@ Func xorOp("xor", GeneralAdd(), xorAlgebra());
206209
TACO_BENCH_ARGS(bench_frostt_ufunc, name/rightShift, path, rightShift); \
207210

208211
FOREACH_FROSTT_TENSOR(DECLARE_FROSTT_UFUNC_BENCH)
212+
213+
struct SuiteSparseTensors {
214+
SuiteSparseTensors() {
215+
auto path = getTacoTensorPath();
216+
auto ssTensorPath = path;
217+
if (ssTensorPath[ssTensorPath.size() - 1] != '/') {
218+
ssTensorPath += "/";
219+
}
220+
ssTensorPath += "suitesparse/";
221+
for (auto& entry : std::experimental::filesystem::directory_iterator(ssTensorPath)) {
222+
std::string f(entry.path());
223+
// Check that the filename ends with .mtx.
224+
if (f.compare(f.size() - 4, 4, ".mtx") == 0) {
225+
this->tensors.push_back(entry.path());
226+
}
227+
}
228+
std::cout << util::join(this->tensors) << std::endl;
229+
}
230+
231+
std::vector<std::string> tensors;
232+
};
233+
SuiteSparseTensors ssTensors;
234+
235+
static void bench_suitesparse_ufunc(benchmark::State& state, Func op) {
236+
int tensorIdx = state.range(0);
237+
auto tensorPath = ssTensors.tensors[tensorIdx];
238+
auto pathSplit = taco::util::split(tensorPath, "/");
239+
auto filename = pathSplit[pathSplit.size() - 1];
240+
auto tensorName = taco::util::split(filename, ".")[0];
241+
state.SetLabel(tensorName);
242+
243+
auto ssTensor = readIntoType<int64_t>("ssTensor", tensorPath, CSR);
244+
auto other = shiftLastMode<int64_t, int64_t>("other", ssTensor);
245+
246+
for (auto _ : state) {
247+
state.PauseTiming();
248+
Tensor<int64_t> result("result", ssTensor.getDimensions(), ssTensor.getFormat());
249+
result.setAssembleWhileCompute(true);
250+
IndexVar i, j;
251+
result(i, j) = op(ssTensor(i, j), other(i, j));
252+
result.compile();
253+
state.ResumeTiming();
254+
255+
result.compute();
256+
}
257+
}
258+
259+
static void applySuiteSparse(benchmark::internal::Benchmark* b) {
260+
std::vector<int64_t> args(ssTensors.tensors.size());
261+
for (int i = 0; i < ssTensors.tensors.size(); i++) {
262+
args[i] = i;
263+
}
264+
b->ArgsProduct({args});
265+
}
266+
267+
TACO_BENCH_ARGS(bench_suitesparse_ufunc, xor, xorOp)->Apply(applySuiteSparse);
268+
TACO_BENCH_ARGS(bench_suitesparse_ufunc, ldExp, ldExp)->Apply(applySuiteSparse);
269+
TACO_BENCH_ARGS(bench_suitesparse_ufunc, rightShift, rightShift)->Apply(applySuiteSparse);

0 commit comments

Comments
 (0)