|
| 1 | +#include "bench.h" |
| 2 | +#include "benchmark/benchmark.h" |
| 3 | + |
| 4 | +#include "taco/tensor.h" |
| 5 | +#include "taco/index_notation/tensor_operator.h" |
| 6 | + |
| 7 | +using namespace taco; |
| 8 | + |
| 9 | +struct NoOp { |
| 10 | + ir::Expr operator()(const std::vector<ir::Expr>& v) { |
| 11 | + return 1; |
| 12 | + } |
| 13 | +}; |
| 14 | + |
| 15 | +struct UnionAlgebra { |
| 16 | + IterationAlgebra operator()(const std::vector<IndexExpr>& regions) { |
| 17 | + return Union(regions[0], regions[1]); |
| 18 | + } |
| 19 | +}; |
| 20 | + |
| 21 | +struct IntersectAlgebra { |
| 22 | + IterationAlgebra operator()(const std::vector<IndexExpr>& regions) { |
| 23 | + return Intersect(regions[0], regions[1]); |
| 24 | + } |
| 25 | +}; |
| 26 | + |
| 27 | +struct AMinusBAlgebra { |
| 28 | + IterationAlgebra operator()(const std::vector<IndexExpr>& regions) { |
| 29 | + auto nointersect = Complement(Intersect(regions[0], regions[1])); |
| 30 | + return Intersect(regions[0], nointersect); |
| 31 | + } |
| 32 | +}; |
| 33 | + |
| 34 | +struct AAlgebra { |
| 35 | + IterationAlgebra operator()(const std::vector<IndexExpr>& regions) { |
| 36 | + return Union(regions[0], Intersect(regions[0], regions[1])); |
| 37 | + } |
| 38 | +}; |
| 39 | + |
| 40 | +struct XorAlgebra { |
| 41 | + IterationAlgebra operator()(const std::vector<IndexExpr>& regions) { |
| 42 | + IterationAlgebra noIntersect = Complement(Intersect(regions[0], regions[1])); |
| 43 | + return Intersect(noIntersect, Union(regions[0], regions[1])); |
| 44 | + } |
| 45 | +}; |
| 46 | + |
| 47 | +Func unionOp("union", NoOp(), UnionAlgebra()); |
| 48 | +Func intersectOp("intersect", NoOp(), IntersectAlgebra()); |
| 49 | +Func aMinusB("aMinusB", NoOp(), AMinusBAlgebra()); |
| 50 | +Func aBIntersectOp("aBIntersect", NoOp(), AAlgebra()); |
| 51 | +Func aubminusanb("xor", NoOp(), XorAlgebra()); |
| 52 | +static void bench_iteration_spaces(benchmark::State& state, Func op) { |
| 53 | + int dim = state.range(0); |
| 54 | + auto sparsity = 0.01; |
| 55 | + auto f = CSR; |
| 56 | + Tensor<double> matrix = loadRandomTensor("A", {dim, dim}, sparsity, f); |
| 57 | + Tensor<double> matrix1 = loadRandomTensor("B", {dim, dim}, sparsity, f, 1 /* variant */); |
| 58 | + |
| 59 | + for (auto _ : state) { |
| 60 | + state.PauseTiming(); |
| 61 | + Tensor<double> result("result", {dim, dim}, f); |
| 62 | + IndexVar i("i"), j("j"); |
| 63 | + result(i, j) = op(matrix(i, j), matrix1(i, j)); |
| 64 | + // result.setAssembleWhileCompute(true); |
| 65 | + result.compile(); |
| 66 | + std::cout << result.getSource() << std::endl; |
| 67 | + state.ResumeTiming(); |
| 68 | + // result.compute(); |
| 69 | + } |
| 70 | +} |
| 71 | +std::vector<std::vector<int64_t>> sizes = {{1000, 2500, 5000, 10000, 20000, 40000}}; |
| 72 | +TACO_BENCH_ARGS(bench_iteration_spaces, aub, unionOp)->ArgsProduct(sizes); |
| 73 | +TACO_BENCH_ARGS(bench_iteration_spaces, anb, intersectOp)->ArgsProduct(sizes); |
| 74 | +TACO_BENCH_ARGS(bench_iteration_spaces, a-b, aMinusB)->ArgsProduct(sizes); |
| 75 | +TACO_BENCH_ARGS(bench_iteration_spaces, auanb, aBIntersectOp)->ArgsProduct(sizes); |
| 76 | +TACO_BENCH_ARGS(bench_iteration_spaces, aub-anb, aubminusanb)->ArgsProduct(sizes); |
0 commit comments