Skip to content

taco: bug when including the same tensor in an expression with user defined algebra #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
rohany opened this issue Mar 24, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@rohany
Copy link
Collaborator

rohany commented Mar 24, 2021

Consider the following setup:

struct GeneralAdd {
  ir::Expr operator()(const std::vector<ir::Expr> &v) {
    taco_iassert(v.size() >= 1) << "Add operator needs at least one operand";
    if (v.size() == 1)
        return ir::Add::make(v[0], ir::Literal::zero(v[0].type()));
    ir::Expr add = ir::Add::make(v[0], v[1]);
    for (size_t idx = 2; idx < v.size(); ++idx) {
      add = ir::Add::make(add, v[idx]);
    }
    return add;
  }
};

struct xorAlgebra {
  IterationAlgebra operator()(const std::vector<IndexExpr>& regions) {
    IterationAlgebra noIntersect = Complement(Intersect(regions[0], regions[1]));
    return Intersect(noIntersect, Union(regions[0], regions[1]));
  }
};

Func xorOp("logical_xor", GeneralAdd(), xorAlgebra());

static void bench_test(benchmark::State& state) {
  int dim = 5000;
  auto sparsity = 0.01;
  auto f = CSR;
  Tensor<double> matrix = loadRandomTensor("A", {dim, dim}, sparsity, f);
  Tensor<double> result("B", {dim, dim}, f);
  IndexVar i("i"), j("j");
  result(i, j) = xorOp(matrix(i, j), matrix2(i, j));
  result.compile();
  std::cout << result.getSource() << std::endl;
}

Taco generates code like:

int compute(taco_tensor_t *B, taco_tensor_t *A) {
  int B1_dimension = (int)(B->dimensions[0]);
  double* restrict B_vals = (double*)(B->vals);
  int A1_dimension = (int)(A->dimensions[0]);
  int* restrict A2_pos = (int*)(A->indices[1][0]);
  int* restrict A2_crd = (int*)(A->indices[1][1]);
  double* restrict A_vals = (double*)(A->vals);
  int32_t jB = 0;
  for (int32_t i = 0; i < A1_dimension; i++) {
    for (int32_t jA = A2_pos[i]; jA < A2_pos[(i + 1)]; jA++) {
      B_vals[jB] = A_vals[jA] + A_vals[jA];
      jB++;
    }
  }
  return 0;
}

which isn't right, because for the xor, no data should be output if a tensor is xor'd with itself.

@weiya711
Copy link
Collaborator

weiya711 commented Apr 1, 2021

I think there's a typo in your initial issue and it should be
result(i, j) = xorOp(matrix(i, j), matrix(i, j));

@weiya711
Copy link
Collaborator

weiya711 commented Apr 7, 2021

I think that my new iteration lattice construction algorithm from #29 should fix this too... hmmmm Let me test this.

@weiya711 weiya711 added the bug Something isn't working label Apr 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants