Poplar and PopLibs
TileMapping.hpp
Go to the documentation of this file.
1// Copyright (c) 2017 Graphcore Ltd. All rights reserved.
8#ifndef poputil_TileMapping_hpp
9#define poputil_TileMapping_hpp
10#include "poplar/DebugContext.hpp"
11#include "poplar/Graph.hpp"
12#include "poplar/Tensor.hpp"
13#include <vector>
14
15namespace poputil {
16
41std::vector<std::vector<poplar::Interval>>
43 std::vector<std::size_t> shape,
44 unsigned minElementsPerTile, unsigned grainSize,
45 unsigned offset = 0, bool ascendingOrder = true);
46
78std::vector<std::vector<poplar::Interval>>
80 unsigned offset = 0, bool ascendingOrder = true);
81
99std::pair<poplar::Graph::TileToTensorMapping, unsigned>
101 const poplar::Tensor &t, unsigned offset = 0);
102
118 unsigned minElementsPerTile, unsigned grainSize);
119
142 unsigned minElementsPerTile,
143 unsigned grainSize, unsigned offset,
144 bool ascendingOrder = true);
145
169
199 unsigned offset = 0,
200 bool ascendingOrder = true);
201
210std::size_t chooseMappingOffset(std::size_t numTiles,
211 const std::vector<std::size_t> &shape);
212
222std::size_t chooseMappingOffset(std::size_t numTiles,
223 const std::vector<std::size_t> &shape,
224 std::size_t seed);
225
239unsigned getTileImbalance(const poplar::Graph::TileToTensorMapping &mapping,
240 unsigned minElementsPerTile = 0,
241 unsigned grainSize = 1);
242
257unsigned getTileImbalance(const poplar::Graph &graph, const poplar::Tensor &t,
258 unsigned minElementsPerTile = 0,
259 unsigned grainSize = 1);
260
261class TensorUseTrackerState;
262
272 std::unique_ptr<TensorUseTrackerState> st;
273
274public:
286 TensorUseTracker(unsigned numTiles, unsigned startTile = 0,
287 bool ascendingMappingOrder = true);
288
292
296
300
304
305 enum class MappingMethod {
309 OptimizeHaloRegions,
310
314 ConstrainMappingToUsedTiles,
315
317 None
318 };
319
323
330 void add(const poplar::Graph &graph, unsigned tile, const poplar::Tensor &t);
331
337
353 void resolve(const poplar::Graph &graph, unsigned grainSize,
354 unsigned minElementsPerTile, bool extendPartialUsage = false,
355 TensorUseTracker::MappingMethod mappingMethod =
357
375 void mapTensorsByUse(poplar::Graph &graph, unsigned grainSize,
376 unsigned minElementsPerTile,
377 bool extendPartialUsage = false,
378 TensorUseTracker::MappingMethod mappingMethod =
380
386 bool empty() const;
387};
388
408cloneToIpu(poplar::Graph &graph, const poplar::Tensor &t, unsigned dstIPU,
409 const poplar::DebugContext &debugContext = {},
412
432 const poplar::Tensor &t,
433 const poplar::DebugContext &debugContext = {},
436
460std::pair<poplar::Tensor, unsigned>
462 unsigned offset = 0,
463 const poplar::DebugContext &debugContext = {});
464
487 poplar::program::Sequence &prog, unsigned dstIPU,
488 const poplar::DebugContext &debugContext = {},
491
516createIpuCopy(poplar::Graph &graph, const poplar::Tensor &t, unsigned dstIpu,
517 poplar::Tensor &copySrc, poplar::Tensor &copyDst,
518 const poplar::DebugContext &debugContext = {},
521
535 unsigned dimension);
536
550 unsigned dimension);
551
578 const poplar::Type &type, unsigned dim,
579 bool ditherMapping = false,
580 const poplar::DebugContext &debugContext = {});
581
599unsigned transformTileIndex(unsigned tile, unsigned numTiles, unsigned offset,
600 bool ascending);
601
619unsigned invTransformTileIndex(unsigned tile, unsigned numTiles,
620 unsigned offset, bool ascending);
621
622} // namespace poputil
623
624#endif // poputil_TileMapping_hpp
DebugContext gathers the common external parameters of the context of an operation.
Definition: DebugContext.hpp:221
This class represents a graph program to be executed on the IPU.
Definition: Graph.hpp:52
A reference to a subset of tensor elements.
Definition: Tensor.hpp:38
Class representing device data types.
Definition: Type.hpp:42
Program that executes a sequence of programs.
Definition: Program.hpp:77
Class that tracks the usage of data on different tiles.
Definition: TileMapping.hpp:271
TensorUseTracker(TensorUseTracker &&other)
Default constructor for the TensorUseTracker class.
~TensorUseTracker()
Destructor for the TensorUserTracker class.
TensorUseTracker & operator=(const TensorUseTracker &other)
Assignment operator for the TensorUseTracker class.
TensorUseTracker(const TensorUseTracker &other)
Constructor for the TensorUseTracker class.
void add(const poplar::Graph &graph, unsigned tile, const poplar::Tensor &t)
Add a case of data usage.
void resolve(const poplar::Graph &graph, unsigned grainSize, unsigned minElementsPerTile, bool extendPartialUsage=false, TensorUseTracker::MappingMethod mappingMethod=TensorUseTracker::MappingMethod::None)
Resolve data usage for mapping.
TensorUseTracker(unsigned numTiles, unsigned startTile=0, bool ascendingMappingOrder=true)
Constructor for the TensorUseTracker class.
void mapTensorsByUse(poplar::Graph &graph, unsigned grainSize, unsigned minElementsPerTile, bool extendPartialUsage=false, TensorUseTracker::MappingMethod mappingMethod=TensorUseTracker::MappingMethod::None)
Map data according to use.
bool empty() const
Check if any cases of data usage have been registered.
MappingMethod
Definition: TileMapping.hpp:305
TensorUseTracker & operator=(TensorUseTracker &&other)
Default assignment operator for the TensorUseTracker class.
void add(TensorUseTracker other)
Add cases of data usage from another tracker.
TensorCloneMethod
Define behaviour when a Tensor is cloned.
Definition: TensorCloneMethod.hpp:13
@ PRESERVE_ORDER_UNLESS_ALIASES
Preserve the ordering of the original tensor unless it contains aliases.
@ PRESERVE_ORDER_AND_ALIASES
Preserve the ordering and aliasing within the original tensor reference.
General utility functions for building graphs.
Definition: GfloatExprUtil.hpp:23
poplar::Tensor copyToIpu(poplar::Graph &masterGraph, const poplar::Tensor &t, poplar::program::Sequence &prog, unsigned dstIPU, const poplar::DebugContext &debugContext={}, poplar::TensorCloneMethod method=poplar::TensorCloneMethod::PRESERVE_ORDER_UNLESS_ALIASES)
Move a tensor from one IPU to another.
std::pair< poplar::Tensor, unsigned > cloneAndExpandAliasing(poplar::Graph &graph, const poplar::Tensor &t, unsigned offset=0, const poplar::DebugContext &debugContext={})
Create a clone of the specified tensor on the specified graph.
poplar::Tensor cloneToGraph(poplar::Graph &srcGraph, poplar::Graph &dstGraph, const poplar::Tensor &t, const poplar::DebugContext &debugContext={}, poplar::TensorCloneMethod method=poplar::TensorCloneMethod::PRESERVE_ORDER_UNLESS_ALIASES)
Create a clone of the specified tensor on the specified graph.
unsigned invTransformTileIndex(unsigned tile, unsigned numTiles, unsigned offset, bool ascending)
Transform a tile index such that the result begins at an offset and increments or decrements.
poplar::Tensor createIpuCopy(poplar::Graph &graph, const poplar::Tensor &t, unsigned dstIpu, poplar::Tensor &copySrc, poplar::Tensor &copyDst, const poplar::DebugContext &debugContext={}, poplar::TensorCloneMethod method=poplar::TensorCloneMethod::PRESERVE_ORDER_AND_ALIASES)
Prepare to move a tensor from one IPU to another.
poplar::Tensor createBroadcastOperand(poplar::Graph &graph, const poplar::Tensor &fullTensor, const poplar::Type &type, unsigned dim, bool ditherMapping=false, const poplar::DebugContext &debugContext={})
Create a simpler tensor that is mapped in the same way as another, full, tensor.
bool dimIsSplitOverIPUs(const poplar::Graph &graph, const poplar::Tensor &t, unsigned dimension)
Check if a dimension of a tensor is split over more than one IPU.
std::size_t chooseMappingOffset(std::size_t numTiles, const std::vector< std::size_t > &shape)
Choose an offset for use with tensor mapping functions using a hash of the shape provided.
void mapTensorLinearly(poplar::Graph &graph, const poplar::Tensor &t, unsigned minElementsPerTile, unsigned grainSize)
Map the specified tensor, spreading the tensor evenly over the tiles in a graph.
std::vector< std::vector< poplar::Interval > > calcLinearTileMapping(const poplar::Graph &graph, std::vector< std::size_t > shape, unsigned minElementsPerTile, unsigned grainSize, unsigned offset=0, bool ascendingOrder=true)
Calculate a tile mapping that spreads the tensor evenly over the tiles in a graph.
void mapTensorLinearlyWithOffset(poplar::Graph &graph, const poplar::Tensor &t, unsigned minElementsPerTile, unsigned grainSize, unsigned offset, bool ascendingOrder=true)
Map the specified tensor, spreading the tensor evenly over the tiles in a graph.
unsigned getTileImbalance(const poplar::Graph::TileToTensorMapping &mapping, unsigned minElementsPerTile=0, unsigned grainSize=1)
Determine how unbalanced a tensor is when mapped over tiles in a graph.
unsigned transformTileIndex(unsigned tile, unsigned numTiles, unsigned offset, bool ascending)
Transform a tile index such that the result begins at zero and increments.
bool dimIsSplitOverTiles(const poplar::Graph &graph, const poplar::Tensor &t, unsigned dimension)
Check if a dimension of a tensor is split over more than one tile.
std::pair< poplar::Graph::TileToTensorMapping, unsigned > calcLinearTileMappingAndNewOffset(const poplar::Graph &graph, const poplar::Tensor &t, unsigned offset=0)
Calculate a tile mapping that spreads the tensor evenly over the tiles in a graph.
poplar::Tensor cloneToIpu(poplar::Graph &graph, const poplar::Tensor &t, unsigned dstIPU, const poplar::DebugContext &debugContext={}, poplar::TensorCloneMethod method=poplar::TensorCloneMethod::PRESERVE_ORDER_UNLESS_ALIASES)
Create a clone of the specified tensor on the specified IPU.