Skip to content
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

Can every index be sparse? #537

Open
Llauset opened this issue Oct 25, 2022 · 8 comments
Open

Can every index be sparse? #537

Llauset opened this issue Oct 25, 2022 · 8 comments

Comments

@Llauset
Copy link

Llauset commented Oct 25, 2022

I tried to generate in the online generation the simple example having every index sparse and it fails.

imagen

Am I misunderstanding something?

It seems that some index in the outcome tensor should be Dense, is it true?

@rohany
Copy link
Contributor

rohany commented Oct 27, 2022

What schedule did you try and use with this expression and format pair? If you tried to parallelize the i loop, then the scheduling primitives available on the website will not work (such a thing is supported through the use of Assemble in the C++ API).

@Llauset
Copy link
Author

Llauset commented Oct 28, 2022

Thank you for your answer Rohany.
I am new using TACO so for sure I am doing something wrong.
I presented the example on my first post trying to understand what it is happening if I set all the dimensions of the tensors to be sparse.
I do not understand what you mean by "shedule" or "format pair". I show you here the code I would like to run. Please, tell me if you have any sugestion about why it is not working.


  #include "taco.h"
  #include <iostream>
  
  using namespace taco;
  using namespace std;
  
  int main(int argc, char* argv[])
  {
      Format b_and_t_format({ Sparse, Sparse, Sparse });
      Format A_format({ Sparse, Sparse, Sparse, Sparse, Sparse, Sparse, Sparse });
 
      Tensor<double> B({ 3, 3, 3 }, b_and_t_format);
      Tensor<double> T({ 3, 3, 3 }, b_and_t_format);
      Tensor<double> A({ 3, 3, 3, 3, 3, 3, 3 }, A_format);
  
      B.insert({ 0, 1, 0 }, 0.5);
      B.insert({ 1, 0, 0 }, 0.5);
      B.insert({ 2, 0, 1 }, 0.5);
      B.insert({ 0, 2, 1 }, 0.5);
  
      T.insert({ 0, 0, 0 }, 1.0);
      T.insert({ 2, 1, 0 }, 1.0 / sqrt(6));
      T.insert({ 2, 1, 0 }, -1.0 / sqrt(6));
      T.insert({ 2, 0, 1 }, -1.0 / sqrt(6));
      T.insert({ 0, 2, 1 }, 1.0 / sqrt(6));
      T.insert({ 1, 0, 2 }, 1.0 / sqrt(6));
      T.insert({ 0, 1, 2 }, -1.0 / sqrt(6));
  
      // Pack data as described by the formats
      B.pack();
      T.pack();
      // Form a tensor contraction expresion
      IndexVar a, b, c, d, e, f, g, h, i, j, k;
      A(a, b, c, d, e, f, g) = B(a, h, e) * B(k, j, f) * B(d, i, g) * T(h, j, i) * T(k, b, c);
      // Compile the expression
      A.compile();
      // Assemble A's indices and numerically compute the result
      A.assemble();
      A.compute();
  }

@rohany
Copy link
Contributor

rohany commented Oct 28, 2022

If you do not attempt to parallelize your code, then every index can indeed be sparse. What error do you get when running that program?

@Llauset
Copy link
Author

Llauset commented Oct 28, 2022

Segmentation fault.
Running it with gdb I get this information about the error:
Program received signal SIGSEGV, Segmentation fault.
0x00002aaaaaf1ecbf in std::vector<taco::IndexVar, std::allocatortaco::IndexVar >::_M_erase(__gnu_cxx::__normal_iterator<taco::IndexVar*, std::vector<taco::IndexVar, std::allocatortaco::IndexVar > >) () from /tmpdir/sparse_tensors_3D/taco/build/lib/libtaco.so
Missing separate debuginfos, use: debuginfo-install glibc-2.17-326.el7_9.x86_64

Have you tried to run the code ? Are you suggesting that it has to be a problem with my environment ?
Thank you !

@rohany
Copy link
Contributor

rohany commented Oct 28, 2022

Can you get a backtrace with gdb? It will be more fruitful if you compile TACO in debug mode (-DCMAKE_BUILD_TYPE=Debug) and get a backtrace.

@Llauset
Copy link
Author

Llauset commented Oct 28, 2022

Here it is:

terminate called after throwing an instance of 'taco::TacoException'
what(): Compiler bug at /tmpdir/sparse_tensors_3D/taco/src/index_notation/transformations.cpp:1678 in topologicallySort
Please report it to developers
Condition failed: freeVarPos != std::numeric_limits<size_t>::max()
Cycles in iteration graphs must be resolved, through transpose, before the expression is passed to the topological sorting routine.

Backtrace:
#0 0x00002aaaac15a387 in raise () from /lib64/libc.so.6
#1 0x00002aaaac15ba78 in abort () from /lib64/libc.so.6
#2 0x00002aaaab8c9677 in __gnu_cxx::__verbose_terminate_handler () at ../../.././libstdc++-v3/libsupc++/vterminate.cc:95
#3 0x00002aaaab8d5116 in __cxxabiv1::__terminate(void (*)()) () at ../../.././libstdc++-v3/libsupc++/eh_terminate.cc:47
#4 0x00002aaaab8d5161 in std::terminate () at ../../.././libstdc++-v3/libsupc++/eh_terminate.cc:57
#5 0x00002aaaab8d5395 in __cxxabiv1::__cxa_throw (obj=, tinfo=0x2aaaab7f19c0 ,
dest=0x2aaaab1b66e6 taco::TacoException::~TacoException()) at ../../.././libstdc++-v3/libsupc++/eh_throw.cc:95
#6 0x00002aaaab1b65bf in taco::ErrorReport::explodeWithException (this=0x7fffffffbe30) at /tmpdir/sparse_tensors_3D/taco/src/error.cpp:65
#7 0x00002aaaab1b60b7 in taco::ErrorReport::~ErrorReport (this=0x7fffffffbe30, __in_chrg=)
at /tmpdir/sparse_tensors_3D/taco/include/taco/error.h:60
#8 0x00002aaaab336338 in taco::topologicallySort (hardDeps=..., softDeps=..., originalOrder=...)
at /tmpdir/sparse_tensors_3D/taco/src/index_notation/transformations.cpp:1678
#9 0x00002aaaab337a43 in taco::reorderLoopsTopologically (stmt=...) at /tmpdir/sparse_tensors_3D/taco/src/index_notation/transformations.cpp:1799
#10 0x00002aaaab1cfed5 in taco::TensorBase::compile (this=0x7fffffffc500) at /tmpdir/sparse_tensors_3D/taco/src/tensor.cpp:638
#11 0x0000000000404d9a in main ()

@rohany
Copy link
Contributor

rohany commented Oct 28, 2022

So the first part of the problem is that TACO is getting confused by you using the same variable in multiple places in the expression (which is a bug).

Changing this

      Tensor<double> B({ 3, 3, 3 }, b_and_t_format);
      Tensor<double> T({ 3, 3, 3 }, b_and_t_format);
      Tensor<double> A({ 3, 3, 3, 3, 3, 3, 3 }, A_format);

to

      Tensor<double> B1({ 3, 3, 3 }, b_and_t_format);
      Tensor<double> B2({ 3, 3, 3 }, b_and_t_format);
      Tensor<double> B3({ 3, 3, 3 }, b_and_t_format);
      Tensor<double> T1({ 3, 3, 3 }, b_and_t_format);
      Tensor<double> T2({ 3, 3, 3 }, b_and_t_format);
      Tensor<double> A({ 3, 3, 3, 3, 3, 3, 3 }, A_format);

and this

      A(a, b, c, d, e, f, g) = B(a, h, e) * B(k, j, f) * B(d, i, g) * T(h, j, i) * T(k, b, c);

to

      A(a, b, c, d, e, f, g) = B1(a, h, e) * B2(k, j, f) * B3(d, i, g) * T1(h, j, i) * T2(k, b, c);

makes that crash go away. However, the resulting problem is more serious -- TACO spits out some invalid code:

/var/folders/b9/rl15b0d13_d4j4h9qg4tx4rr0000gn/T/taco_tmp_IcsYuV/12ef400tr7dt.c:327:31: error: use of undeclared identifier 'pA7_begin'
                          if (pA7_begin < gA) {
                              ^
/var/folders/b9/rl15b0d13_d4j4h9qg4tx4rr0000gn/T/taco_tmp_IcsYuV/12ef400tr7dt.c:342:25: error: use of undeclared identifier 'pA6_begin'
                    if (pA6_begin < fA) {
                        ^
/var/folders/b9/rl15b0d13_d4j4h9qg4tx4rr0000gn/T/taco_tmp_IcsYuV/12ef400tr7dt.c:394:9: error: use of undeclared identifier 'pA2_begin'
    if (pA2_begin < bA) {
        ^
3 errors generated.
Error at /Users/rohany/Documents/research/taco-master/src/codegen/module.cpp:156 in compile:
 Compilation command failed:

This is a harder bug to fix, and unfortunately I don't have much time to track down and fix this (maintaining TACO is not my primary obligation right now). If there's anyone else who has time cc @tensor-compiler/core-developers they could take it. Theoretically, TACO should be able to generate code for this kernel.

@Llauset
Copy link
Author

Llauset commented Oct 28, 2022

Ok, thank you very much for your help.
I will stay tuned and if the problems are being solved I will give a try to TACO again.

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

No branches or pull requests

2 participants