Embedding

#include <popsparse/Embedding.hpp>

Functions for slicing and mapping sparse tensors.

namespace popsparse

Support for sparse matrices.

namespace dynamic

Support for dynamic sparse matrices.

Functions

poplar::Tensor createIndicesTensor(poplar::Graph &graph, const FullyConnectedParams &params, std::size_t numIndices, const poplar::OptionFlags &options = {}, const poplar::DebugContext &debugContext = {})

Create and map a tensor to contain indices for slicing/updating a tensor efficiently.

Parameters
  • graph – The Poplar graph.

  • params – Parameters for the fully connected layer which defines the embedding operation. Used to decide on layout for the indices.

  • options – Implementation options for the fully connected layer.

  • numIndices – The number of indices this tensor should contain

  • debugContext – Optional debug information.

Returns

A 1D tensor of shape [numIndices]. Element type is always UNSIGNED_INT.

poplar::Tensor createSliceTensor(poplar::Graph &graph, const poplar::Type &dataType, const FullyConnectedParams &params, std::size_t numIndices, const poplar::DebugContext &debugContext = {}, const poplar::OptionFlags &options = {}, PlanningCache *cache = nullptr)

Create and map a tensor to be updated from efficiently.

Memory layout is based on the planned split of the sparse tensor.

Parameters
  • graph – The Poplar graph.

  • dataType – The data type of the returned tensor.

  • params – Parameters for the fully connected layer which will provide the planned memory layout for the sparse tensor being updated

  • numIndices – The number of slices this tensor should contain.

  • debugContext – Optional debug information.

  • options – Implementation options for the fully connected layer.

  • cache – Optional pointer to planning cache to use.

Returns

A 2D tensor with shape [numIndices, params.getInputChannels()] with layout optimised for slicing into/updating from.

poplar::Tensor embeddingSlice(poplar::Graph &graph, const SparseTensor &t, const poplar::Tensor &indices, poplar::program::Sequence &prog, const FullyConnectedParams &params, const poplar::DebugContext &debugContext = {}, const poplar::OptionFlags &options = {}, PlanningCache *cache = nullptr)

Take multiple slices from a base tensor.

The returned tensor will have dimensions [offsets, k (from params)]

Parameters
  • graph – The Poplar graph.

  • t – The sparse tensor being sliced.

  • indices – The indices of rows of t to be sliced.

  • prog – The program to be extended.

  • params – Parameters for the fully connected layer which will provide the planned memory layout for the sparse tensor being sliced.

  • debugContext – Optional debug information.

  • options – Implementation options for the fully connected layer.

  • cache – Optional pointer to planning cache to use.

void embeddingUpdateAdd(poplar::Graph &graph, const SparseTensor &t, const poplar::Tensor &slices, const poplar::Tensor &indices, const poplar::Tensor &scale, poplar::program::Sequence &prog, const FullyConnectedParams &params, const poplar::DebugContext &debugContext = {}, const poplar::OptionFlags &options = {}, PlanningCache *cache = nullptr)

Update a sparse tensor with a set of slices at the given row indices.

Parameters
  • graph – The Poplar graph.

  • t – The sparse tensor being updated.

  • slices – The slices to accumulate.

  • indices – The indices of rows of t to accumulate each slice in slices into.

  • scale – The scaling to apply to the update.

  • prog – The program to be extended.

  • params – Parameters for the fully connected layer which will provide the planned memory layout for the sparse tensor being updated

  • debugContext – Optional debug information.

  • options – Implementation options for the fully connected layer.

  • cache – Optional pointer to planning cache to use.