项目作者: tensor-compiler

项目描述 :
The Tensor Algebra Compiler (taco) computes sparse tensor expressions on CPUs and GPUs
高级语言: C++
项目地址: git://github.com/tensor-compiler/taco.git
创建时间: 2016-09-25T23:35:22Z
项目社区:https://github.com/tensor-compiler/taco

开源协议:Other

下载


The Tensor Algebra Compiler (taco) is a C++ library that computes
tensor algebra expressions on sparse and dense tensors. It uses novel
compiler techniques to get performance competitive with hand-optimized
kernels in widely used libraries for both sparse tensor algebra and
sparse linear algebra.

You can use taco as a C++ library that lets you load tensors, read
tensors from files, and compute tensor expressions. You can also use
taco as a code generator that generates C functions that compute
tensor expressions.

Learn more about taco at
tensor-compiler.org, in the paper
The Tensor Algebra Compiler,
or in this talk. To learn more about
where taco is going in the near-term, see the technical reports on
optimization and
formats.

You can also subscribe to the
taco-announcements
email list where we post announcements, RFCs, and notifications of API
changes, or the taco-discuss
email list for open discussions and questions.

TL;DR build taco using CMake. Run make test.

Build and test

Build and Test

Build taco using CMake 3.4.0 or greater:

  1. cd <taco-directory>
  2. mkdir build
  3. cd build
  4. cmake -DCMAKE_BUILD_TYPE=Release ..
  5. make -j8

Building taco requires gcc 5.0 or newer, or clang 3.9 or newer. You can
use a specific compiler or version by setting the CC and CXX environment
variables before running cmake.

Building Python API

To build taco with the Python API (pytaco), add -DPYTHON=ON to the cmake line above. For example:

  1. cmake -DCMAKE_BUILD_TYPE=Release -DPYTHON=ON ..

You will then need to add the pytaco module to PYTHONPATH:

  1. export PYTHONPATH=<taco-directory>/build/lib:$PYTHONPATH

This requires Python 3.x and some development libraries. It also requires
NumPy and SciPy to be installed. For Debian/Ubuntu, the following packages
are needed: python3 libpython3-dev python3-distutils python3-numpy python3-scipy.

Building for OpenMP

To build taco with support for parallel execution (using OpenMP), add -DOPENMP=ON to the cmake line above. For example:

  1. cmake -DCMAKE_BUILD_TYPE=Release -DOPENMP=ON ..

If you are building with the clang compiler, you may need to ensure that
the libomp development headers are installed. For Debian/Ubuntu, this is
provided by libomp-dev, One of the more specific versions like
libomp-13-dev may also work.

Building for CUDA

To build taco for NVIDIA CUDA, add -DCUDA=ON to the cmake line above. For example:

  1. cmake -DCMAKE_BUILD_TYPE=Release -DCUDA=ON ..

Please also make sure that you have CUDA installed properly and that the following environment variables are set correctly:

  1. export PATH=/usr/local/cuda/bin:$PATH
  2. export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
  3. export LIBRARY_PATH=/usr/local/cuda/lib64:$LIBRARY_PATH

If you do not have CUDA installed, you can still use the taco cli to generate CUDA code with the -cuda flag.

The generated CUDA code will require compute capability 6.1 or higher to run.

Generating documentation

To generate documentation for the Python API:

  1. cd <taco-directory>/python_bindings
  2. make html

Before generating the documentation, you must have built the Python API (by
following the instructions above) as well as installed
the following dependencies:

  1. pip install sphinx
  2. pip install numpydoc
  3. pip install sphinx-rtd-theme

Running tests

To run all tests:

  1. cd <taco-directory>/build
  2. make test

Tests can be run in parallel by setting CTEST_PARALLEL_LEVEL=<n> in the environment (which runs <n> tests in parallel).

To run the C++ test suite individually:

  1. cd <taco-directory>
  2. ./build/bin/taco-test

To run the Python test suite individually:

  1. cd <taco-directory>
  2. python3 build/python_bindings/unit_tests.py

Code coverage analysis

To enable code coverage analysis, configure with -DCOVERAGE=ON. This requires
the gcovr tool to be installed in your PATH.

For best results, the build type should be set to Debug. For example:

  1. cmake -DCMAKE_BUILD_TYPE=Debug -DCOVERAGE=ON ..

Then to run code coverage analysis:

  1. make gcovr

This will run the test suite and produce some coverage analysis. This process
requires that the tests pass, so any failures must be fixed first.
If all goes well, coverage results will be output to the coverage/ folder.
See coverage/index.html for a high level report, and click individual files
to see the line-by-line results.

Library example

The following sparse tensor-times-vector multiplication example in C++
shows how to use the taco library.

  1. // Create formats
  2. Format csr({Dense,Sparse});
  3. Format csf({Sparse,Sparse,Sparse});
  4. Format sv({Sparse});
  5. // Create tensors
  6. Tensor<double> A({2,3}, csr);
  7. Tensor<double> B({2,3,4}, csf);
  8. Tensor<double> c({4}, sv);
  9. // Insert data into B and c
  10. B.insert({0,0,0}, 1.0);
  11. B.insert({1,2,0}, 2.0);
  12. B.insert({1,2,1}, 3.0);
  13. c.insert({0}, 4.0);
  14. c.insert({1}, 5.0);
  15. // Pack inserted data as described by the formats
  16. B.pack();
  17. c.pack();
  18. // Form a tensor-vector multiplication expression
  19. IndexVar i, j, k;
  20. A(i,j) = B(i,j,k) * c(k);
  21. // Compile the expression
  22. A.compile();
  23. // Assemble A's indices and numerically compute the result
  24. A.assemble();
  25. A.compute();
  26. std::cout << A << std::endl;

Code generation tools

If you just need to compute a single tensor kernel you can use the
taco online tool to generate
a custom C library. You can also use the taco command-line tool to
the same effect:

  1. cd <taco-directory>
  2. ./build/bin/taco
  3. Usage: taco [options] <index expression>
  4. Examples:
  5. taco "a(i) = b(i) + c(i)" # Dense vector add
  6. taco "a(i) = b(i) + c(i)" -f=b:s -f=c:s -f=a:s # Sparse vector add
  7. taco "a(i) = B(i,j) * c(j)" -f=B:ds # SpMV
  8. taco "A(i,l) = B(i,j,k) * C(j,l) * D(k,l)" -f=B:sss # MTTKRP
  9. Options:
  10. ...

For more information, see our paper on the taco tools
taco: A Tool to Generate Tensor Algebra Kernels.