Skip to content

Uncaught exception when fusing sparse dimensions #527

New issue

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

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

Already on GitHub? # to your account

Open
remysucre opened this issue May 18, 2022 · 4 comments
Open

Uncaught exception when fusing sparse dimensions #527

remysucre opened this issue May 18, 2022 · 4 comments

Comments

@remysucre
Copy link
Contributor

remysucre commented May 18, 2022

Got an uncheck exception when fusing sparse dimensions. Does fuse only work for dense dimensions?

remywang@m16 build % ./bin/taco "q = r(i,j) * s(i,j)" -f=r:ss -s="fuse(i,j,f)" 
libc++abi: terminating with uncaught exception of type taco::TacoException: Compiler bug at /Users/remywang/projects/taco/src/lower/lowerer_impl_imperative.cpp:873 in lowerForall
Please report it to developers
 Condition failed: underivedAncestors.size() == 1
 
zsh: abort      ./bin/taco "q = r(i,j) * s(i,j)" -f=r:ss -s="fuse(i,j,f)"
@remysucre remysucre changed the title Uncaught exception when fusing sparse and dense dimensions Uncaught exception when fusing sparse dimensions May 18, 2022
@rohany
Copy link
Contributor

rohany commented May 20, 2022

Yes, I believe fusing without iterating over the position space is supported for only dense dimensions currently. I'm not sure what the best way of fusing co-iteration loops looks like.

@remysucre
Copy link
Contributor Author

Hmm, if I add some pos commands, taco generates code successfully but the code uses an undefined variable iposr:

remywang@m16 build % ./bin/taco "q = r(i,j) * s(i,j)" -f=r:ss -s="pos(i,ipos,r)" -s="pos(j,jpos,r)" -s="fuse(ipos,jpos,f)"           
// Generated by the Tensor Algebra Compiler (tensor-compiler.org)

int compute(taco_tensor_t *q, taco_tensor_t *r, taco_tensor_t *s) {
  double* restrict q_vals = (double*)(q->vals);
  int* restrict r1_pos = (int*)(r->indices[0][0]);
  int* restrict r1_crd = (int*)(r->indices[0][1]);
  int* restrict r2_pos = (int*)(r->indices[1][0]);
  int* restrict r2_crd = (int*)(r->indices[1][1]);
  double* restrict r_vals = (double*)(r->vals);
  int s1_dimension = (int)(s->dimensions[0]);
  int s2_dimension = (int)(s->dimensions[1]);
  double* restrict s_vals = (double*)(s->vals);

  double q_val = 0.0;

  for (int32_t f = r1_pos[0] * (r2_pos[(iposr + 1)] - r2_pos[iposr]) + r2_pos[iposr]; f < (r1_pos[1] * (r2_pos[(iposr + 1)] - r2_pos[iposr]) + r2_pos[iposr]); f++) {
    int32_t iposr = f / (r2_pos[(iposr + 1)] - r2_pos[iposr]);
    if (iposr < r1_pos[0] || iposr >= r1_pos[1])
      continue;

    int32_t i = r1_crd[iposr];
    int32_t jposr = f % (r2_pos[(iposr + 1)] - r2_pos[iposr]);
    if (jposr < r2_pos[iposr] || jposr >= r2_pos[(iposr + 1)])
      continue;

    int32_t j = r2_crd[jposr];
    int32_t js = i * s2_dimension + j;
    q_val += r_vals[jposr] * s_vals[js];
  }

  q_vals[0] = q_val;
  return 0;
}

In general I'm pretty confused by what pos is supposed to do.

@rohany
Copy link
Contributor

rohany commented May 20, 2022

Take a look at http://tensor-compiler.org/senanayake-oopsla20-taco-scheduling.pdf, section 2 (and later in the paper) for some details on pos. The key idea of pos is to enable iteration over the non-zero values of a tensor only, and apply further transformations such as strip-mining to this space of non-zeros.

The scheduling system doesn't seem to throw an error (it doesn't do the best pre-condition checking), but your schedule is invalid. Here's a valid schedule doing maybe what you intended:

bin/taco "q = r(i,j) * s(i,j)" -f=r:ss -s="fuse(i, j, f)", -s="pos(f, fpos, r)"

which first fuses i and j into f, and then declares f to range over the position space of r -- over the non-zeros of r. This is useful then to strip-mine fpos, which generates statically load-balanced iterations over the non-zeros of r.

@remysucre
Copy link
Contributor Author

I see, thanks! I'll leave this open for the uncaught errors, but feel free to close if those are not of high priority.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants