BlockSparse

#include <popsparse/experimental/BlockSparse.hpp>

Block sparse operations.

namespace popsparse

Support for sparse matrices.

namespace experimental

Enums

enum class SubBlockMask

Define the sparsity mask inside a block.

The diagonal is defined across sll the non-sparse matrix dimensions, where the row index is equal to the column index.

Values:

enumerator None

No elements are zeroed out.

enumerator ZeroUpperTriangle

Elements in the upper triangle, above the diagonal, are zeroed out.

enumerator ZeroLowerTriangle

Elements in the lower triangle, below the diagonal, are zeroed out.

Functions

poplar::Tensor bsSoftmax(poplar::Graph &graph, poplar::Tensor sparseTensor, const std::array<int, 2> &dim, const std::array<int, 2> &blockSize, const std::vector<unsigned char> &sparsity, SubBlockMask subBlockMaskType, unsigned numGroups, poplar::program::Sequence &prog, const poplar::DebugContext &debugContext = {})

This function computes softmax on a sparse tensor.

Parameters
  • graph – The Poplar graph.

  • sparseTensor – The input sparse 2D tensor. It must be in a block-sparse format.

  • dim[0] – Number of rows of the original dense tensor.

  • dim[1] – Number of columns of the original dense tensor.

  • blockSize[0] – Block size of the rows.

  • blockSize[1] – Block size of the columns.

  • sparsity – The 2D sparsity mask for the block-sparse tensor, in which ‘1’ is a non zero block and ‘0’ is a zero block.

  • subBlockMaskType – Sub-block mask type. Elements in upper (or lower) triangle are filled by zeroes in the result.

  • numGroups – The umber of groups for group operation or 1 for non-group operation. This parameter affects sub-block mask application only. The 0 dimension of the dense representation is logically divided into groups and sub-block mask applies individually for each group.

  • prog – A reference to the program sequence to which the code to perform the softmax will be appended.

void bsSoftmaxInPlace(poplar::Graph &graph, poplar::Tensor sparseTensor, const std::array<int, 2> &dim, const std::array<int, 2> &blockSize, const std::vector<unsigned char> &sparsity, SubBlockMask subBlockMaskType, unsigned numGroups, poplar::program::Sequence &prog, const poplar::DebugContext &debugContext = {})

This function computes softmax on a sparse tensor, in place.

Parameters
  • graph – The Poplar graph.

  • sparseTensor – The input sparse 2D tensor. It must be in a block-sparse format.

  • dim[0] – Number of rows of the original dense tensor.

  • dim[1] – Number of columns of the original dense tensor.

  • blockSize[0] – Block size of the rows.

  • blockSize[1] – Block size of the columns.

  • sparsity – The 2D sparsity mask for the block-sparse tensor, in which ‘1’ is a non zero block and ‘0’ is a zero block.

  • subBlockMaskType – Sub-block mask type. Elements in upper (or lower) triangle are filled by zeroes in the result.

  • numGroups – The umber of groups for group operation or 1 for non-group operation. This parameter affects sub-block mask application only. The 0 dimension of the dense representation is logically divided into groups and sub-block mask applies individually for each group.

  • prog – A reference to a program sequence which will be appended with the code to perform the softmax.

poplar::Tensor bsSoftmaxGrad(poplar::Graph &graph, poplar::Tensor sparseOut, poplar::Tensor sparseOutGrad, const std::array<int, 2> &dim, const std::array<int, 2> &blockSize, const std::vector<unsigned char> &sparsity, poplar::program::Sequence &prog, const poplar::DebugContext &debugContext = {})

This function computes softmax gradient on a sparse tensor.

Parameters
  • graph – The Poplar graph

  • sparseOut – The outer (activation) sparse 2D tensor. It must be in block-sparse format.

  • sparseOutGrad – The outer gradient sparse 2D tensor. It must be in a block-sparse format.

  • dim[0] – Number of rows of the original dense tensor.

  • dim[1] – Number of columns of the original dense tensor.

  • blockSize[0] – Block size of the rows.

  • blockSize[1] – Block size of the columns.

  • sparsity – The 2D sparsity mask for the block-sparse tensor, in which ‘1’ is a non zero block and ‘0’ is a zero block.

  • prog – A reference to a program sequence which will be appended with the code to perform the softmax.