Skip to content
Cem Bassoy edited this page Mar 15, 2024 · 16 revisions

General

TLIB(TTM) is header-only library with C++ functions that compute the mode-q tensor-matrix product. It provides free C++ functions for parallel computing the mode-q tensor-times-matrix product of the general form

$$ \underline{\mathbf{C}} = \underline{\mathbf{A}} \bullet_q \mathbf{B} \quad :\Leftrightarrow \quad \underline{\mathbf{C}} (i_1, \dots, i_{q-1}, j, i_{q+1}, \dots, i_p) = \sum_{i_q=1}^{n_q} \underline{\mathbf{A}}({i_1, \dots, i_q, \dots, i_p}) \cdot \mathbf{B}({j,i_q}). $$

where $q$ is the contraction mode, $\underline{\mathbf{A}}$ and $\underline{\mathbf{C}}$ are tensors of order $p$ with shapes $\mathbf{n}_a= (n_1,\dots n_{q-1},n_q ,n_{q+1},\dots,n_p)$ and $\mathbf{n}_c = (n_1,\dots,n_{q-1},m,n_{q+1},\dots,n_p)$, respectively. The order $2$ tensor $\mathbf{B}$ is a matrix with shape $\mathbf{n}_b = (m,n_{q})$.

Flexibility

The number of dimensions (order) $p$ and the dimensions $n_r$ as well as the linear tensor layout of the tensors $\underline{\mathbf{A}}$, $\mathbf{B}$ and $\underline{\mathbf{C}}$ can be chosen at runtime, while $\underline{\mathbf{A}}$ and $\underline{\mathbf{C}}$ must have the same tensor layout. The tensor layout is defined with thelp of a permutation tuple $\mathbf{\pi}$ of length $p$. We have free C++ function which will help you to generate any $k$ order tensor layout, including the first-order (column-major) or the last-order (row-major) storage formats.

Implementation

All C++ functions are based on the Loops-Over-GEMM (LoG) approach and utilize high-performance gemv, gemm or gemm_batch routines of BLAS such as OpenBLAS or Intel MKL without transposing tensors. Depending on the combination of $q$ , $p$ and $\mathbf{\pi}$ , the matrix $\mathbf{B}$ might be transposed.

Interfaces

TLIB provides three C++ interfaces to compute the tensor-matrix product, see cpp-interfaces.

Using the the two low-level interfaces, you can specify different versions using tags. TLIB provides 8 different C++ function templates that compute the tensor-matrix product, see cpp-functions.

Usage & Installation

You don't need to install TLIB. However, it needs to be linked with either OpenBLAS or Intel MKL when it is used. Support of BLIS and "standalone" will follow, see installation for more info on usage and test installation.

Issues & Contribution

Users should feel free to report any bugs or problems in issues. For discussions, feel free to comment and discuss any related topics in discussions.

Clone this wiki locally