Poplar and PopLibs
BlockSparse.hpp File Reference

Block sparse operations. More...

#include <array>
#include <string>
#include <vector>
#include <poplar/Graph.hpp>
#include <poplar/Program.hpp>
#include <poplar/Tensor.hpp>
#include <poplar/Type.hpp>

Go to the source code of this file.

Namespaces

namespace  popsparse
 Support for sparse matrices.
 

Enumerations

enum class  popsparse::experimental::SubBlockMask { None , ZeroUpperTriangle , ZeroLowerTriangle }
 Define the sparsity mask inside a block. More...
 

Functions

poplar::Tensor popsparse::experimental::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. More...
 
void popsparse::experimental::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. More...
 
poplar::Tensor popsparse::experimental::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. More...
 

Detailed Description

Block sparse operations.

Enumeration Type Documentation

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

Enumerator
None 

No elements are zeroed out.

ZeroUpperTriangle 

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

ZeroLowerTriangle 

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

Function Documentation

◆ bsSoftmax()

poplar::Tensor popsparse::experimental::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
graphThe Poplar graph.
sparseTensorThe 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.
sparsityThe 2D sparsity mask for the block-sparse tensor, in which '1' is a non zero block and '0' is a zero block.
subBlockMaskTypeSub-block mask type. Elements in upper (or lower) triangle are filled by zeroes in the result.
numGroupsThe 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.
progA reference to the program sequence to which the code to perform the softmax will be appended.

◆ bsSoftmaxGrad()

poplar::Tensor popsparse::experimental::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
graphThe Poplar graph
sparseOutThe outer (activation) sparse 2D tensor. It must be in block-sparse format.
sparseOutGradThe 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.
sparsityThe 2D sparsity mask for the block-sparse tensor, in which '1' is a non zero block and '0' is a zero block.
progA reference to a program sequence which will be appended with the code to perform the softmax.

◆ bsSoftmaxInPlace()

void popsparse::experimental::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
graphThe Poplar graph.
sparseTensorThe 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.
sparsityThe 2D sparsity mask for the block-sparse tensor, in which '1' is a non zero block and '0' is a zero block.
subBlockMaskTypeSub-block mask type. Elements in upper (or lower) triangle are filled by zeroes in the result.
numGroupsThe 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.
progA reference to a program sequence which will be appended with the code to perform the softmax.