Poplar and PopLibs
popsparse::experimental::BSMatMulParams Class Reference

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...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ BSMatMulParams() [1/2]

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).

Parameters
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.
rhsSparsityThe 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.
rhsNeedTransposeWhether the right-hand matrix need be transposed. This is mostly to support backward pass. If this parameter is true:
  • dim and blockSize must conform to the transposed shape.
  • rhsSparsity must be in the original, non-transposed order.
  • rhsMatrix in bsMatMul() must contain data within blocks in original, non-transposed order.
inDataTypeInput data type.
outDataTypeOutput data type.
partialDataTypePartial data type.
numGroupsInThe number of groups for group operation or 1 for non-group operation.

◆ BSMatMulParams() [2/2]

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.

Parameters
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.
resSparsityThe 2D sparsity mask for the result block-sparse matrix, in which '1' is a non-zero block and '0' is a zero block.
resSparsityThe 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.
outDataTypeOutput data type.
partialDataTypePartial data type.
SubBlockMaskThe mask inside a block. See SubBlockMask in BlockSparse.hpp for details.
numGroupsInThe number of groups for group operation or 1 for non-group operation.

The documentation for this class was generated from the following file: