VarStructure
#include <poputil/VarStructure.hpp>
Manage partitioning and grouping in tensors.
-
namespace poputil
General utility functions for building graphs.
Typedefs
Functions
-
unsigned detectInnermostGrouping(const poplar::Graph &graph, const poplar::Tensor &t)
Detect if the tensor
t
has a grouping in its innermost dimension.- Parameters
graph – The graph to add the function to.
t – The tensor to check for grouping.
- Throws
poputil::poplibs_error – If the rank of
t
is zero.- Returns
The size of the group. 1 if there is no grouping.
-
std::vector<GroupingInfo> detectDimGroupings(const poplar::Graph &graph, const poplar::Tensor &t)
Find all grouped dimensions from the innermost grouped dimension moving outwards, returning groupings for each.
The same dimension may appear more than once. This uses detectInnermostGrouping() iteratively.
- Parameters
graph – The graph to add the function to.
t – The tensor to check for grouping.
- Throws
poputil::poplibs_error – If the rank of
t
is zero.- Returns
A list of the grouped dimensions starting with the innermost.
-
poplar::Tensor createPartitionableTensor(poplar::Graph &graph, const poplar::Type &type, const std::vector<std::size_t> &shape, const std::vector<std::size_t> &nPartitions, const poplar::DebugContext &debugContext = {})
Create a tensor with the given shape, so that when it is partitioned into slices according to the given number of partitions in each dimension, each slice is a single contiguous region.
This partitions the tensor so that the maximum number of elements in each partition of a dimension is minimised as well as the number of partitions. That is, if a dimension has
n
elements, and the number of partitions in that dimension isd
then:a * ceil(n/d) + 1 * (n%d) = n
There will be
a
partitions withceil
(n/d) elements followed byb
partitions withfloor
(n/d) elements and possibly some number of partitions with 0 elements.The returned tensor has no tile mapping set.
- Parameters
graph – The graph to add the variable to.
type – The type of the elements in the returned tensor.
shape – The shape of the returned tensor.
nPartitions – The number of partitions the shape will be partitioned into in each dimension.
debugContext – Optional debug information.
- Throws
poputil::poplibs_error – If the size of
shape
andnPartitions
are not equal.- Returns
A tensor with the given shape where each partition is contiguous.
-
void iterateTensorPartitions(const poplar::Tensor &t, const std::vector<std::size_t> &nPartitions, const std::function<void(const std::vector<std::size_t> &i, const poplar::Tensor &s)> &f)
Iterate a function over the partitions of a tensor.
Partitioning follows the same definition as described for createPartitionableTensor().
- Parameters
t – The tensor to iterate over.
nPartitions – The number of partitions the tensor is partitioned into in each dimension.
i –
f – A function taking the indices of the partition in the range [0, splits[d]) in each dimension of the tensor as well as the slice of the tensor corresponding to that partition.
- Throws
poputil::poplibs_error – If the rank of
t
and the size ofnPartitions
are not equal.
-
unsigned detectInnermostGrouping(const poplar::Graph &graph, const poplar::Tensor &t)