|
| 1 | +#include "bench.h" |
| 2 | +#include "benchmark/benchmark.h" |
| 3 | + |
| 4 | +#include "taco/tensor.h" |
| 5 | +#include "taco/format.h" |
| 6 | +#include "taco/index_notation/index_notation.h" |
| 7 | +#include "taco/index_notation/tensor_operator.h" |
| 8 | + |
| 9 | +#include <vector> |
| 10 | +#include <limits> |
| 11 | + |
| 12 | +using namespace taco; |
| 13 | + |
| 14 | +struct AddImpl { |
| 15 | + ir::Expr operator()(const std::vector<ir::Expr>& v) { |
| 16 | + return ir::Add::make(v[0], v[1]); |
| 17 | + } |
| 18 | +}; |
| 19 | +Func AddOp("add", AddImpl(), {Annihilator(std::numeric_limits<double>::infinity()), Identity(0), Commutative(), Associative()}); |
| 20 | + |
| 21 | +struct MinImpl{ |
| 22 | + ir::Expr operator()(const std::vector<ir::Expr>& v) { |
| 23 | + return ir::Min::make(v[0], v[1]); |
| 24 | + } |
| 25 | +}; |
| 26 | +Func MinOp("min", MinImpl(), {Identity(std::numeric_limits<double>::infinity()), Commutative(), Associative()}); |
| 27 | + |
| 28 | +struct MaskImpl { |
| 29 | + ir::Expr operator()(const std::vector<ir::Expr>& v) { |
| 30 | + return v[0]; |
| 31 | + } |
| 32 | +}; |
| 33 | +struct MaskAlgebra { |
| 34 | + IterationAlgebra operator()(const std::vector<IndexExpr>& r) { |
| 35 | + return Intersect(r[0], Complement(r[1])); |
| 36 | + } |
| 37 | +}; |
| 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) = MinOp(Reduction(MinOp(), j, AddOp(A(i,j), x(j))), x(i)); |
| 64 | + //y(i) = MaskOp(Reduction(MinOp(), j, AddOp(A(i,j), x(j))), x(i)); |
| 65 | + //y(i) = MinOp(MaskOp(Reduction(MinOp(), j, AddOp(A(i,j), x(j))), x(i)), x(i)); |
| 66 | + //y(i) = MaskOp(MinOp(Reduction(MinOp(), j, AddOp(A(i,j), x(j))), x(i)), x(i)); |
| 67 | + //y(i) = MinOp(FilterOp(x(i)) * Reduction(MinOp(), j, AddOp(A(i,j), x(j))), x(i)); |
| 68 | + |
| 69 | + y.compile(); |
| 70 | + y.assemble(); |
| 71 | + |
| 72 | + state.ResumeTiming(); |
| 73 | + |
| 74 | + y.compute(); |
| 75 | + } |
| 76 | + taco_set_num_threads(1); |
| 77 | +} |
| 78 | + |
| 79 | +TACO_BENCH(bench_mxv_taco); |
0 commit comments