tensor-compiler / taco

The Tensor Algebra Compiler (taco) computes sparse tensor expressions on CPUs and GPUs
http://tensor-compiler.org
Other
1.24k stars 186 forks source link

Evaluate function does not set vals_size #208

Open drhagen opened 5 years ago

drhagen commented 5 years ago

Is the evaluate function supposed to emit code for assigning vals_size on the output tensor? See below where assemble does it , but evaluate does not.

$ ./taco 'a(i) = b(i) * c(i)' -print-assembly -print-evaluate
// Generated by the Tensor Algebra Compiler (tensor-compiler.org)

int assemble(taco_tensor_t *a, taco_tensor_t *b, taco_tensor_t *c) {
  int a1_dimension = (int)(a->dimensions[a->mode_ordering[0]]);
  double* restrict a_vals = (double*)(a->vals);
  int a_vals_size = a->vals_size;
  int b1_dimension = (int)(b->dimensions[b->mode_ordering[0]]);

  for (int32_t ib = 0; ib < b1_dimension; ib++) {
  }

  a_vals = (double*)malloc(sizeof(double) * a1_dimension);
  a_vals_size = a1_dimension;

  a->vals = (uint8_t*)a_vals;
  a->vals_size = a_vals_size;
  return 0;
}

int evaluate(taco_tensor_t *a, taco_tensor_t *b, taco_tensor_t *c) {
  int a1_dimension = (int)(a->dimensions[a->mode_ordering[0]]);
  double* restrict a_vals = (double*)(a->vals);
  int b1_dimension = (int)(b->dimensions[b->mode_ordering[0]]);
  double* restrict b_vals = (double*)(b->vals);
  double* restrict c_vals = (double*)(c->vals);

  a_vals = (double*)malloc(sizeof(double) * a1_dimension);

  for (int32_t ib = 0; ib < b1_dimension; ib++) {
    a_vals[ib] = b_vals[ib] * c_vals[ib];
  }

  a->vals = (uint8_t*)a_vals;
  return 0;
}
stephenchouca commented 5 years ago

That's the intended behavior since vals_size (i.e., the size of the values array) is only currently needed when assembly and compute are done separately, in the event that the compute function needs to zero-initialize the result values array before performing the actual computation. That said, the assembly function probably doesn't really ever need to explicitly store the size of the values array either (since the compute function should always be able to infer that from the data structures storing the result indices), so the current plan is actually to deprecate vals_size as part of #201.

drhagen commented 5 years ago

I agree that vals_size is redundant. I will update my code to avoid it in anticipation of its removal.