Poplar and PopLibs
gcl::CollectiveBalancedReorder Class Reference

Helper class to reorder a tensor in a per-tile-balanced fashion such that each replica obtains (for inputs to AllGather or outputs of ReduceScatter) an equally sized 1D tensor with equally sized regions. More...

#include <CollectiveBalancedReorder.hpp>

Public Member Functions

 CollectiveBalancedReorder (poplar::Graph &graph_, poplar::Tensor tensor_, unsigned replicationFactor_, const poplar::DebugNameAndId &dnai_, bool allowElementMap=false, unsigned grainSize=1)
 Constructor. More...
 
poplar::Tensor createReplicaSlice (const poplar::Type &type)
 Create a tensor mapped efficiently over the same tiles as the reference tensor. More...
 
poplar::Tensor createCollectivesTensor (const poplar::Type &type, const std::string &debugPrefix)
 Create a tensor mapped efficiently over the same tiles as the reference tensor. More...
 
poplar::Tensor undoRearrangeForCollective (const poplar::Tensor &tensor) const
 Reorder tensor back into the expected IR tensor shape and order. More...
 
std::vector< std::size_t > getReferenceShape () const
 Get the shape of the reference tensor. More...
 
const CollectiveBalancedHostRearrangementgetHostRearrangement () const
 Get a helper class that implements allows to apply the rearrangement on the host. More...
 
void zeroPaddingInCollectiveTensor (poplar::Tensor &collectiveTensor, poplar::program::Sequence &prog) const
 Zero the padding of a collective friendly tensor. More...
 

Detailed Description

Helper class to reorder a tensor in a per-tile-balanced fashion such that each replica obtains (for inputs to AllGather or outputs of ReduceScatter) an equally sized 1D tensor with equally sized regions.

This helper class reduces the memory used by the syncful collective. The reordering process:

  • Flattens the input tensor
  • Analyses the tile mapping
  • Determines reordering strategy and required internal padding
  • Can rearrange and undo the rearrangement on any tensor that has the same tile mapping
  • Can rearrange and undo the rearrangement on host tensors that are to be copied into CBR-rearranged RemoteBuffers

Constructor & Destructor Documentation

◆ CollectiveBalancedReorder()

gcl::CollectiveBalancedReorder::CollectiveBalancedReorder ( poplar::Graph graph_,
poplar::Tensor  tensor_,
unsigned  replicationFactor_,
const poplar::DebugNameAndId dnai_,
bool  allowElementMap = false,
unsigned  grainSize = 1 
)

Constructor.

Parameters
graph_The poplar graph.
tensor_The reference tensor to rearrange.
replicationFactor_The replication factor of the graph.
dnai_Debug name and id.
allowElementMapAllow alternative representation of the host rearrangements. Sometimes it is beneficial to collapse all intervals into simple 1-to-1 element map. This flag should be set true in all new code and deprecated when all frameworks implement serialisation of newly added elementMap field.
grainSizeThe grain size to use when padding the tensor.

Member Function Documentation

◆ createCollectivesTensor()

poplar::Tensor gcl::CollectiveBalancedReorder::createCollectivesTensor ( const poplar::Type type,
const std::string &  debugPrefix 
)

Create a tensor mapped efficiently over the same tiles as the reference tensor.

The returned tensor has the size of the input of the reduce scatter and of the result of the all gather.

Parameters
typeThe type to use when creating the tensor.
debugPrefixThe debug prefix.
Returns
The efficient tensor created from the reference.

◆ createReplicaSlice()

poplar::Tensor gcl::CollectiveBalancedReorder::createReplicaSlice ( const poplar::Type type)

Create a tensor mapped efficiently over the same tiles as the reference tensor.

The returned tensor has the size of the result of the reduce scatter and of the input of the all gather.

Parameters
typeThe type to use when creating the tensor.
Returns
The efficient tensor created from the reference.

◆ getHostRearrangement()

const CollectiveBalancedHostRearrangement & gcl::CollectiveBalancedReorder::getHostRearrangement ( ) const
inline

Get a helper class that implements allows to apply the rearrangement on the host.

Returns
The helper class for host rearrangement.

◆ getReferenceShape()

std::vector< std::size_t > gcl::CollectiveBalancedReorder::getReferenceShape ( ) const
inline

Get the shape of the reference tensor.

Returns
The shape of the reference tensor.

◆ undoRearrangeForCollective()

poplar::Tensor gcl::CollectiveBalancedReorder::undoRearrangeForCollective ( const poplar::Tensor tensor) const

Reorder tensor back into the expected IR tensor shape and order.

Parameters
tensorThe tensor to rearrange.
Returns
The tensor with the rearrangement undone.

◆ zeroPaddingInCollectiveTensor()

void gcl::CollectiveBalancedReorder::zeroPaddingInCollectiveTensor ( poplar::Tensor collectiveTensor,
poplar::program::Sequence prog 
) const

Zero the padding of a collective friendly tensor.

Parameters
collectiveTensorThe collective tensor to zero the padding of.
progThe sequence to add the zeroing program to.

The documentation for this class was generated from the following file: