Poplar and PopLibs
|
This class supports block-sparse matrix multiplication. More...
#include <BlockSparseMatMul.hpp>
Public Member Functions | |
BSMatMulParams (const std::array< int, 3 > &dim, const std::array< int, 3 > &blockSize, const std::vector< unsigned char > &rhsSparsity, bool rhsNeedTranspose, poplar::Type inDataType, poplar::Type outDataType, poplar::Type partialDataType, unsigned numGroupsIn=1) | |
This constructor is for a dense matrix (left side) multiplying a sparse matrix (right side). More... | |
BSMatMulParams (const std::array< int, 3 > &dim, const std::array< int, 3 > &blockSize, const std::vector< unsigned char > &resSparsity, poplar::Type inDataType, poplar::Type outDataType, poplar::Type partialDataType, SubBlockMask subBlockMask=SubBlockMask::None, unsigned numGroupsIn=1) | |
This constructor is for a dense matrix multiplying a dense matrix. More... | |
This class supports block-sparse matrix multiplication.
The class only saves the sparsity mask, the matrix size, the block size, and the data type, which are used to generate the computation graph.
The matrix data is passed when bsMatMul() gets called.
The purpose of this design is to reuse the instance of this class when only the data of the matrix is changed, and the matrix sparsity does not change.
popsparse::experimental::BSMatMulParams::BSMatMulParams | ( | const std::array< int, 3 > & | dim, |
const std::array< int, 3 > & | blockSize, | ||
const std::vector< unsigned char > & | rhsSparsity, | ||
bool | rhsNeedTranspose, | ||
poplar::Type | inDataType, | ||
poplar::Type | outDataType, | ||
poplar::Type | partialDataType, | ||
unsigned | numGroupsIn = 1 |
||
) |
This constructor is for a dense matrix (left side) multiplying a sparse matrix (right side).
dim[0] | Number of rows in the left-hand matrix. |
dim[1] | Number of columns in the left-hand matrix. |
dim[2] | If the right matrix needs to be transposed, this is the number of rows in the right-hand matrix. Otherwise, it is number of columns in the right-hand matrix. |
blockSize[0] | Block size of the rows in the left-hand matrix. |
blockSize[1] | Block size of the columns in the left-hand matrix. |
blockSize[2] | Block size of the columns in the right-hand matrix. Block size must be divisible by 16 for FP16 and divisible by 8 for FP32. |
rhsSparsity | The 2D sparsity mask for right-hand block sparse matrix, in which '1' is a non-zero block and '0' is a zero block. For group operation this parameter is concatenated sparsity masks for all ops in a group. |
rhsNeedTranspose | Whether the right-hand matrix need be transposed. This is mostly to support backward pass. If this parameter is true:
|
inDataType | Input data type. |
outDataType | Output data type. |
partialDataType | Partial data type. |
numGroupsIn | The number of groups for group operation or 1 for non-group operation. |
popsparse::experimental::BSMatMulParams::BSMatMulParams | ( | const std::array< int, 3 > & | dim, |
const std::array< int, 3 > & | blockSize, | ||
const std::vector< unsigned char > & | resSparsity, | ||
poplar::Type | inDataType, | ||
poplar::Type | outDataType, | ||
poplar::Type | partialDataType, | ||
SubBlockMask | subBlockMask = SubBlockMask::None , |
||
unsigned | numGroupsIn = 1 |
||
) |
This constructor is for a dense matrix multiplying a dense matrix.
The multiply is performed as a sparse operation and the result stored as a sparse matrix.
dim[0] | Number of rows in the left-hand matrix. |
dim[1] | Number of columns in the left-hand matrix. |
dim[2] | Number of columns in the right-hand matrix. |
blockSize[0] | Block size of the rows in the left-hand matrix. |
blockSize[1] | Block size of the columns in the left-hand matrix. |
blockSize[2] | Block size of the columns in the right-hand matrix. The block size of the columns in the left-hand matrix equals the block size of the rows in the right-hand matrix. Block size must be divisible by 16 for FP16 and divisible by 8 for FP32. |
resSparsity | The 2D sparsity mask for the result block-sparse matrix, in which '1' is a non-zero block and '0' is a zero block. |
resSparsity | The 2D sparsity mask for the result block sparse matrix, in which '1' is a non-zero block and '0' is a zero block. For group operation this parameter is concatenated sparsity masks for all ops in a group. |
outDataType | Output data type. |
partialDataType | Partial data type. |
SubBlockMask | The mask inside a block. See SubBlockMask in BlockSparse.hpp for details. |
numGroupsIn | The number of groups for group operation or 1 for non-group operation. |