Poplar and PopLibs
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BlockSparseMatMul.hpp File Reference

Block sparse matrix multiply. More...

#include "BlockSparse.hpp"
#include <array>
#include <poplar/Graph.hpp>

Go to the source code of this file.

Classes

class  popsparse::experimental::BSMatMulParams
 This class supports block-sparse matrix multiplication. More...
 

Namespaces

namespace  popsparse
 Support for sparse matrices.
 

Functions

poplar::Tensor popsparse::experimental::createBSMatMulInputLHS (poplar::Graph &graph, const BSMatMulParams &bsMatMul, const poplar::DebugContext &debugContext, const poplar::OptionFlags &options={})
 Create a tensor for use as the left operand of block-sparse matrix multiplication. More...
 
poplar::Tensor popsparse::experimental::createBSMatMulInputRHS (poplar::Graph &graph, const BSMatMulParams &bsMatMul, const poplar::DebugContext &debugContext, const poplar::OptionFlags &options={})
 Create a tensor for use as the right operand of block-sparse matrix multiplication. More...
 
poplar::Tensor popsparse::experimental::bsMatMul (poplar::Graph &graph, const BSMatMulParams &bsMatMulParams, poplar::program::Sequence &prog, const poplar::Tensor &lhsMatrix, const poplar::Tensor &rhsMatrix, const poplar::OptionFlags &options={}, const poplar::DebugContext &debugContext={})
 This function multiplies the left-hand matrix by the right-hand matrix. More...
 

Detailed Description

Block sparse matrix multiply.

Function Documentation

◆ bsMatMul()

poplar::Tensor popsparse::experimental::bsMatMul ( poplar::Graph graph,
const BSMatMulParams bsMatMulParams,
poplar::program::Sequence prog,
const poplar::Tensor lhsMatrix,
const poplar::Tensor rhsMatrix,
const poplar::OptionFlags options = {},
const poplar::DebugContext debugContext = {} 
)

This function multiplies the left-hand matrix by the right-hand matrix.

Matrix multiply options

  • numberOfPass Integer [=1]

    The number of passes used to serialise the matrix multiply.

    If this is greater than 1, the leading dimension (if the matmul shape is [MxN] x [NxK], it is M) will be divided by numberOfPass, and each sub matmul will be run in serial to reduce the temporary memory usage.

Parameters
graphThe Poplar graph.
bsMatMulParamsThe object for block sparse information, includes the sparsity mask, the matrix size, the block size, and the data type.
progA reference to a program sequence which will be appended with the code to perform the multiplication.
lhsMatrixIf BSMatMulParams is for dense x sparse, this is the left-hand dense matrix. If BSMatMulParams is for sparse x sparse, this is the non-zero blocks of the left sparse matrix. For a group BSMatMulParams object, it should be concatenated along 0 dimension for all tensors in a group.
rhsMatrixA tensor for an array of non-zero blocks in the right-hand sparse matrix. For a group BSMatMulParams object, it should be concatenated along 0 dimension for all tensors in a group.
optionsThe structure describing options for how the multiplication should be implemented.
debugContextOptional debug information.
Returns
The tensor holding the result of the multiplication. This tensor will be created, added to the graph and mapped to tiles. For a group BSMatMulParams object, the return tensor is concatenated along 0 dimension for all ops in a group.

◆ createBSMatMulInputLHS()

poplar::Tensor popsparse::experimental::createBSMatMulInputLHS ( poplar::Graph graph,
const BSMatMulParams bsMatMul,
const poplar::DebugContext debugContext,
const poplar::OptionFlags options = {} 
)

Create a tensor for use as the left operand of block-sparse matrix multiplication.

Parameters
graphThe Poplar graph.
bsMatMulThe object for block-sparse information, includes the sparsity mask, the matrix size, the block size, and the data type.
debugContextOptional debug information.
optionsMatrix multiple options, see bsMatMul() for details.
Returns
For non-grouped BSMatMulParams object, if the left matrix is a dense matrix, the return tensor is just a regular 2D matrix. If it is a sparse matrix, the return tensor is an array of non-zero blocks. For group BSMatMulParams object, the return tensor is concatenated along 0 dimension for all matrices in a group.

◆ createBSMatMulInputRHS()

poplar::Tensor popsparse::experimental::createBSMatMulInputRHS ( poplar::Graph graph,
const BSMatMulParams bsMatMul,
const poplar::DebugContext debugContext,
const poplar::OptionFlags options = {} 
)

Create a tensor for use as the right operand of block-sparse matrix multiplication.

Parameters
graphThe Poplar graph.
bsMatMulThe object for block-sparse information, includes the sparsity mask, the matrix size, the block size, and the data type.
debugContextOptional debug information.
optionsMatrix multiple options, see bsMatMul() for details.
Returns
For non-grouped BSMatMulParams object, if the right matrix is a dense matrix, the return tensor is just a regular 2D matrix. If it is a sparse matrix, the return tensor is an array of non-zero blocks. For group BSMatMulParams object, the return tensor is concatenated along 0 dimension for all matrices in a group.