Poplar and PopLibs
DynamicSlice.hpp File Reference

Support for dynamic slices. More...

#include <poplar/Graph.hpp>
#include <poplar/Program.hpp>
#include <poputil/DebugInfo.hpp>
#include <string>
#include <vector>

Go to the source code of this file.

Classes

class  popops::SlicePlan
 An object representing a plan that describes how to implement a slice or update. More...
 

Namespaces

namespace  poplar
 Poplar classes and functions.
 
namespace  popops
 Common functions, such as elementwise and reductions.
 

Functions

poplar::Tensor popops::createSliceableTensor (poplar::Graph &graph, const poplar::Type &type, const std::vector< size_t > &shape, const std::vector< size_t > &dims, const std::vector< size_t > &sizes, std::size_t minGrainSize=0, const poplar::DebugContext &debugContext={})
 Create and map a tensor to be sliced/updated efficiently. More...
 
poplar::Tensor popops::createSliceableTensor (poplar::Graph &graph, const poplar::Type &type, const std::vector< size_t > &shape, const std::vector< size_t > &dims, const std::vector< size_t > &sizes, const SlicePlan &plan, const poplar::OptionFlags &options, const poplar::DebugContext &debugContext={})
 Create and map a tensor to be sliced/updated efficiently. More...
 
poplar::Tensor popops::createGroupedSliceableTensor (poplar::Graph &graph, const poplar::Type &type, const std::size_t groupSize, const std::vector< std::size_t > &shape, const std::vector< std::size_t > &dims, const std::vector< std::size_t > &sizes, const SlicePlan &plan, const poplar::OptionFlags &options, const poplar::DebugContext &debugContext={})
 Create and map a tensor with a group dimension to be sliced/updated efficiently. More...
 
poplar::Tensor popops::createSliceTensor (poplar::Graph &graph, const poplar::Tensor &t, const std::vector< size_t > &dims, const std::vector< size_t > &sizes, std::size_t numIndices, const poplar::DebugContext &debugContext={})
 Create and map a tensor that is used as a result of slicing, or as an input to an update. More...
 
poplar::Tensor popops::createSliceTensor (poplar::Graph &graph, const poplar::Type &type, const std::vector< std::size_t > &shape, const std::vector< std::size_t > &dims, const std::vector< std::size_t > &sizes, std::size_t numIndices, const SlicePlan &plan, const poplar::OptionFlags &options, const poplar::DebugContext &debugContext={})
 Create and map a tensor that is used as a result of slicing, or as an input to an update. More...
 
poplar::Tensor popops::createGroupedSliceTensor (poplar::Graph &graph, const poplar::Type &type, const std::size_t groupSize, const std::vector< std::size_t > &shape, const std::vector< std::size_t > &dims, const std::vector< std::size_t > &sizes, const std::size_t numIndices, const SlicePlan &plan, const poplar::OptionFlags &options, const poplar::DebugContext &debugContext={})
 Create and map a tensor with a group dimension that is used as a result of slicing, or as an input to an update. More...
 
poplar::Tensor popops::createIndicesTensor (poplar::Graph &graph, const std::vector< std::size_t > &dims, std::size_t numIndices, const SlicePlan &plan, const poplar::OptionFlags &options, const poplar::DebugContext &debugContext={})
 Create and map a tensor to contain indices for slicing or updating a tensor efficiently. More...
 
poplar::Tensor popops::createGroupedIndicesTensor (poplar::Graph &graph, const std::size_t groupSize, const std::vector< std::size_t > &dims, const std::size_t numIndices, const SlicePlan &plan, const poplar::OptionFlags &, const poplar::DebugContext &debugContext={})
 Create and map a tensor with a group dimension to contain indices for slicing or updating a tensor efficiently. More...
 
poplar::Tensor popops::createSliceableTensorFromSlice (poplar::Graph &graph, const poplar::Tensor &s, const std::vector< std::size_t > &dims, const std::vector< std::size_t > &numSlices, const poplar::DebugContext &debugContext={})
 Create and map a tensor to be sliced/updated. More...
 
poplar::Tensor popops::dynamicSlice (poplar::Graph &graph, const poplar::Tensor &t, const poplar::Tensor &offset, const std::vector< std::size_t > &dims, const std::vector< std::size_t > &sizes, poplar::program::Sequence &prog, const poplar::DebugContext &debugContext={})
 Slice a tensor based on offsets specified by a tensor. More...
 
void popops::dynamicSliceWithOutput (poplar::Graph &graph, const poplar::Tensor &output, const poplar::Tensor &t, const poplar::Tensor &offset, const std::vector< std::size_t > &dims, const std::vector< std::size_t > &sizes, poplar::program::Sequence &prog, const poplar::DebugContext &debugContext={})
 Slice a tensor based on offsets specified by a tensor. More...
 
poplar::Graph::TileToTensorMapping popops::getSliceMapping (poplar::Graph &graph, const poplar::Tensor &t, const std::vector< std::size_t > &dims, const std::vector< std::size_t > &sizes)
 Get the tile mapping for a slice of a tensor. More...
 
void popops::dynamicUpdate (poplar::Graph &graph, const poplar::Tensor &t, const poplar::Tensor &s, const poplar::Tensor &offset, const std::vector< std::size_t > &dims, const std::vector< std::size_t > &sizes, poplar::program::Sequence &prog, const poplar::DebugContext &debugContext={})
 Update a subtensor at offsets read from a tensor. More...
 
poplar::Tensor popops::multiSlice (poplar::Graph &graph, const poplar::Tensor &t, const poplar::Tensor &offsets, const std::vector< std::size_t > &dims, const std::vector< std::size_t > &sizes, poplar::program::Sequence &prog, const SlicePlan &plan, const poplar::OptionFlags &options, const poplar::DebugContext &debugContext={})
 Take multiple slices from a base tensor. More...
 
poplar::Tensor popops::groupedMultiSlice (poplar::Graph &graph, const poplar::Tensor &t, const poplar::Tensor &offsets, const std::vector< std::size_t > &dims, const std::vector< std::size_t > &sizes, poplar::program::Sequence &prog, const SlicePlan &plan, const poplar::OptionFlags &options, const poplar::DebugContext &debugContext={})
 Take multiple slices from a base tensor where the base tensor and the offsets tensor have the group dimension as the first dimension. More...
 
poplar::Tensor popops::multiSlice (poplar::Graph &graph, const poplar::Tensor &t, poplar::ArrayRef< unsigned > offsets, std::size_t dim, poplar::program::Sequence &prog, const poplar::DebugContext &debugContext={})
 Take multiple slices from a base tensor. More...
 
void popops::multiUpdate (poplar::Graph &graph, const poplar::Tensor &t, const poplar::Tensor &s, const poplar::Tensor &offsets, const std::vector< std::size_t > &dims, const std::vector< std::size_t > &sizes, poplar::program::Sequence &prog, const SlicePlan &plan, const poplar::OptionFlags &options, const poplar::DebugContext &debugContext={})
 Update multiple slices in a tensor. More...
 
void popops::groupedMultiUpdate (poplar::Graph &graph, const poplar::Tensor &t, const poplar::Tensor &s, const poplar::Tensor &offsets, const std::vector< std::size_t > &dims, const std::vector< std::size_t > &sizes, poplar::program::Sequence &prog, const SlicePlan &plan, const poplar::OptionFlags &options, const poplar::DebugContext &debugContext={})
 Update multiple slices in a tensor with a group dimension. More...
 
void popops::multiUpdateAdd (poplar::Graph &graph, const poplar::Tensor &t, const poplar::Tensor &s, const poplar::Tensor &offsets, const poplar::Tensor &scale, const std::vector< std::size_t > &dims, const std::vector< std::size_t > &sizes, poplar::program::Sequence &prog, const SlicePlan &plan, const poplar::OptionFlags &options, const poplar::DebugContext &debugContext={})
 Accumulate multiple slices in a tensor. More...
 
void popops::groupedMultiUpdateAdd (poplar::Graph &graph, const poplar::Tensor &t, const poplar::Tensor &s, const poplar::Tensor &offsets, const poplar::Tensor &scale, const std::vector< std::size_t > &dims, const std::vector< std::size_t > &sizes, poplar::program::Sequence &prog, const SlicePlan &plan, const poplar::OptionFlags &options, const poplar::DebugContext &debugContext={})
 Accumulate multiple slices in a tensor where the first dimension of the tensors t, s and offsets is the group dimension. More...
 
void popops::multiUpdateAdd (poplar::Graph &graph, const poplar::Tensor &t, const poplar::Tensor &s, poplar::ArrayRef< unsigned > offsets, const poplar::Tensor &scale, std::size_t dim, poplar::program::Sequence &prog, const poplar::DebugContext &debugContext={})
 Accumulate multiple slices in a tensor. More...
 
void popops::multiUpdateMax (poplar::Graph &graph, const poplar::Tensor &t, const poplar::Tensor &s, const poplar::Tensor &offsets, const std::vector< std::size_t > &dims, const std::vector< std::size_t > &sizes, poplar::program::Sequence &prog, const SlicePlan &plan, const poplar::OptionFlags &options, const poplar::DebugContext &debugContext={})
 Find maximum over multiple slices in a tensor. More...
 
void popops::groupedMultiUpdateMax (poplar::Graph &graph, const poplar::Tensor &t, const poplar::Tensor &s, const poplar::Tensor &offsets, const std::vector< std::size_t > &dims, const std::vector< std::size_t > &sizes, poplar::program::Sequence &prog, const SlicePlan &plan, const poplar::OptionFlags &options, const poplar::DebugContext &debugContext={})
 Find maximum over multiple slices in a tensor with a group dimension. More...
 
SlicePlan popops::embedding::plan (const poplar::Graph &graph, const poplar::Type &dataType, const std::size_t numEntries, const std::size_t outputSize, const std::vector< std::size_t > &numLookups, const poplar::OptionFlags &options)
 Create a plan for implementing a set of operations on an embedding matrix. More...
 
SlicePlan popops::embedding::plan (const poplar::Graph &graph, const poplar::Type &dataType, const std::size_t groupSize, const std::size_t numEntries, const std::size_t outputSize, const std::vector< std::size_t > &numLookups, const poplar::OptionFlags &options)
 Overload of plan with group size.
 

Detailed Description

Support for dynamic slices.

Function Documentation

◆ plan()

SlicePlan popops::embedding::plan ( const poplar::Graph graph,
const poplar::Type dataType,
const std::size_t  numEntries,
const std::size_t  outputSize,
const std::vector< std::size_t > &  numLookups,
const poplar::OptionFlags options 
)

Create a plan for implementing a set of operations on an embedding matrix.

** Embedding plan options **

  • usedForSlice (true, false) [=true]

    If true, you intend to use this embedding plan for both a multiSlice operation. An error is thrown if set to false and usedForUpdate is set to false.

  • usedForUpdate (true, false) [=true]

    If true, you intend to use this embedding plan for both a multiUpdate operation. An error is thrown if set to false and usedForSlice is set to false.

  • operationForUpdate ("none", "add", "max") [="add"]

    Only applicable when usedForUpdate = true. Is the type of operation used in multi-update. Set to "none" for multiUpdate "add" for multiUpdateAdd "max" for multiUpdateMax

  • availableMemoryProportion Decimal between 0 and 1 (inclusive) [=0.6]

    If set, gives the proportion of tile memory made available for temporary variables (variables that become live and die during the operation) for this operation. If not set, the operation has the freedom to use unlimited temporary memory.

    See also
    createWeights()
    [Optimising Temporary Memory Usage for Convolutions and Matmuls on the IPU] (https://docs.graphcore.ai/projects/available-memory/) technical note for some practical examples of using availableMemoryProportion
  • indicesDistribution (uniform, onePoint) [=uniform]

    A description of the statistical distribution of the indices that will be sliced/updated over the input size (numEntries) of the operation. This is used to when estimating the runtime of the multiSlice and multiUpdate operation.

    • uniform Indices are assumed to be uniformly distributed over the input size of the embedding.
    • onePoint Indices are assumed to all be equal.
  • indicesAreSorted (true, false) [=false]

    Plan assuming indices used in MultiUpdate/MultiUpdateOp are sorted in increasing order. The same option must then be used along with the plan when calling MultiUpdate with and without an operation.

  • validateIndices (true, false) [=false]

    Check that all indices are valid at runtime. If any is invalid execution is aborted.

  • partialType (half, float) If not provided, defaults to using the same as the data type. Partials type should always be the same or higher precision than the data type of the embedding matrix. Is applicable only for the case where operationForUpdate is add. It is ignored for all other operations and multi-slice.
Parameters
graphThe graph the operation will be added to.
dataTypeThe data type of the entries in the embedding matrix and the resulting lookups from the matrix.
numEntriesInput size of embedding matrix.
outputSizeOutput size of embedding matrix lookup.
numLookupsVector of numbers of indices which will be looked up in the embedding matrix.
optionsSet of option flags controlling how the operation will be implemented.
Returns
A plan which describes how the embedding matrix lookup/update operations should be implemented.