Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

The Tensor Algebra Compiler (taco) computes sparse tensor expressions on CPUs and GPUs

License

NotificationsYou must be signed in to change notification settings

tensor-compiler/taco

Repository files navigation

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

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

Learn more about taco attensor-compiler.org, in the paperThe Tensor Algebra Compiler,or inthis talk. To learn more aboutwhere taco is going in the near-term, see the technical reports onoptimization andformats.

You can also subscribe to thetaco-announcementsemail list where we post announcements, RFCs, and notifications of APIchanges, or thetaco-discussemail list for open discussions and questions.

TL;DR build taco using CMake. Runmake test.

Build and test

Build and Test

Build taco using CMake 3.4.0 or greater:

cd <taco-directory>mkdir buildcd buildcmake -DCMAKE_BUILD_TYPE=Release ..make -j8

Building taco requiresgcc 5.0 or newer, orclang 3.9 or newer. You canuse a specific compiler or version by setting theCC andCXX environmentvariables before runningcmake.

Building Python API

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

cmake -DCMAKE_BUILD_TYPE=Release -DPYTHON=ON ..

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

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

This requires Python 3.x and some development libraries. It also requiresNumPy and SciPy to be installed. For Debian/Ubuntu, the following packagesare 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:

cmake -DCMAKE_BUILD_TYPE=Release -DOPENMP=ON ..

If you are building with theclang compiler, you may need to ensure thatthelibomp development headers are installed. For Debian/Ubuntu, this isprovided bylibomp-dev, One of the more specific versions likelibomp-13-dev may also work.

Building for CUDA

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

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:

export PATH=/usr/local/cuda/bin:$PATHexport LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATHexport 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:

cd <taco-directory>/python_bindingsmake html

Before generating the documentation, you must have built the Python API (byfollowing theinstructions above) as well as installedthe following dependencies:

pip install sphinxpip install numpydocpip install sphinx-rtd-theme

Running tests

To run all tests:

cd <taco-directory>/buildmake test

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

To run the C++ test suite individually:

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

To run the Python test suite individually:

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

Code coverage analysis

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

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

cmake -DCMAKE_BUILD_TYPE=Debug -DCOVERAGE=ON ..

Then to run code coverage analysis:

make gcovr

This will run the test suite and produce some coverage analysis. This processrequires that the tests pass, so any failures must be fixed first.If all goes well, coverage results will be output to thecoverage/ folder.Seecoverage/index.html for a high level report, and click individual filesto 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.

// Create formatsFormatcsr({Dense,Sparse});Formatcsf({Sparse,Sparse,Sparse});Formatsv({Sparse});// Create tensorsTensor<double>A({2,3},   csr);Tensor<double>B({2,3,4}, csf);Tensor<double>c({4},     sv);// Insert data into B and cB.insert({0,0,0},1.0);B.insert({1,2,0},2.0);B.insert({1,2,1},3.0);c.insert({0},4.0);c.insert({1},5.0);// Pack inserted data as described by the formatsB.pack();c.pack();// Form a tensor-vector multiplication expressionIndexVar i, j, k;A(i,j) = B(i,j,k) * c(k);// Compile the expressionA.compile();// Assemble A's indices and numerically compute the resultA.assemble();A.compute();std::cout << A << std::endl;

Code generation tools

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

cd <taco-directory>./build/bin/tacoUsage: taco [options] <index expression>Examples:  taco "a(i) = b(i) + c(i)"                            # Dense vector add  taco "a(i) = b(i) + c(i)" -f=b:s -f=c:s -f=a:s       # Sparse vector add  taco "a(i) = B(i,j) * c(j)" -f=B:ds                  # SpMV  taco "A(i,l) = B(i,j,k) * C(j,l) * D(k,l)" -f=B:sss  # MTTKRPOptions:  ...

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


[8]ページ先頭

©2009-2025 Movatter.jp