|
1 | 1 | #include <fstream>
|
| 2 | +// We're using c++14, so wer're stuck with experimental filesystem. |
| 3 | +#include <experimental/filesystem> |
| 4 | + |
2 | 5 | #include "bench.h"
|
3 | 6 | #include "benchmark/benchmark.h"
|
4 | 7 |
|
@@ -206,3 +209,61 @@ Func xorOp("xor", GeneralAdd(), xorAlgebra());
|
206 | 209 | TACO_BENCH_ARGS(bench_frostt_ufunc, name/rightShift, path, rightShift); \
|
207 | 210 |
|
208 | 211 | 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