Poplar and PopLibs
Util.hpp File Reference

General operations on tensors. More...

#include <algorithm>
#include <cassert>
#include <climits>
#include <poplar/Device.hpp>
#include <poplar/Graph.hpp>
#include <poplar/Interval.hpp>
#include <poplar/Program.hpp>
#include <poplar/Quarter.hpp>
#include <poplar/Target.hpp>
#include <poplar/Tensor.hpp>
#include <string>
#include <vector>

Go to the source code of this file.

Namespaces

namespace  poputil
 General utility functions for building graphs.
 

Functions

std::vector< poplar::Intervalpoputil::flattenIntervals (const std::vector< std::vector< poplar::Interval > > &intervals)
 Flatten a vector of vectors of intervals to a vector, maintaining ordering.
 
std::vector< std::vector< poplar::Interval > > poputil::splitRegions (const std::vector< poplar::Interval > &regions, unsigned grainSize, unsigned maxPartitions, unsigned minElementsPerPartition=0, unsigned maxElementsPerPartition=UINT_MAX, unsigned maxElementsPerRegion=UINT_MAX)
 Given a set of contiguous regions, partition these regions while trying to balance the number of elements in each partition and respecting the specified grain size. More...
 
std::vector< std::vector< poplar::Interval > > poputil::splitRegionsBetweenWorkers (const poplar::Target &target, const std::vector< poplar::Interval > &regions, unsigned grainSize, unsigned minElementsPerPartition=0, unsigned maxElementsPerPartition=UINT_MAX, unsigned maxElementsPerRegion=UINT_MAX)
 Given a set of contiguous regions per tile, partition these regions between workers on that tile while respecting the specified grain size. More...
 
std::vector< std::vector< std::vector< poplar::Interval > > > poputil::splitRegions (const std::vector< std::vector< poplar::Interval > > &regions, unsigned grainSize, unsigned maxPartitions, unsigned minElementsPerPartition=0, unsigned maxElementsPerPartition=UINT_MAX, unsigned maxElementsPerRegion=UINT_MAX)
 Given a set of sequences of regions, partition these sequences while trying to balance the number of elements in each partition and respecting the specified grain size. More...
 
std::vector< std::vector< std::vector< poplar::Interval > > > poputil::splitRegionsBetweenWorkers (const poplar::Target &target, const std::vector< std::vector< poplar::Interval > > &regions, unsigned grainSize, unsigned minElementsPerPartition=0, unsigned maxElementsPerPartition=UINT_MAX, unsigned maxElementsPerRegion=UINT_MAX)
 Given a set of sequences of regions per tile, partition these sequences between workers on that tile while respecting the specified grain size. More...
 
template<class T >
std::vector< T > poputil::unflattenIndex (const std::vector< T > &shape, std::size_t index)
 Given an index into a flattened tensor, returns the indices into the dimensions of the original tensor.
 
template<class T >
std::size_t poputil::flattenIndex (const std::vector< T > &shape, const std::vector< T > &indices)
 Given a list of indices into a tensor, return the corresponding index in a flattened version of the tensor.
 
std::size_t poputil::intervalSequenceNumElements (const std::vector< std::vector< poplar::Interval > > &seq)
 Return the total number of elements in the interval sequence.
 
poplar::Tensor poputil::duplicate (poplar::Graph &graph, const poplar::Tensor &in, poplar::program::Sequence &p, const poplar::DebugContext &debugContext={}, poplar::TensorCloneMethod method=poplar::TensorCloneMethod::PRESERVE_ORDER_UNLESS_ALIASES)
 Copy a tensor's data to a new tensor. More...
 
poplar::Tensor poputil::cloneN (poplar::Graph &graph, const poplar::Tensor &t, unsigned N, const poplar::DebugContext &debugContext={}, poplar::TensorCloneMethod method=poplar::TensorCloneMethod::PRESERVE_ORDER_UNLESS_ALIASES)
 Clone a tensor N times. More...
 
std::vector< int > poputil::balancedPartition (int rangeUpperBound, int splitCount)
 Split a range. More...
 
double poputil::castToDeviceHalfValue (const poplar::Target &target, double input)
 Cast a double precision value to a value exactly representable in device HALF type. More...
 
bool poputil::checkAccuracyWhenCast (const poplar::Target &target, double input, poplar::Type inputType, poplar::Type outputType, double tolerance)
 Check accuracy of a cast operation. More...
 
poplar::Tensor poputil::factorDims (const poplar::Tensor &t, const std::vector< std::size_t > &factors, unsigned startDim=0)
 Factors the outermost dimensions of tensor t by the values given in factors. More...
 
poplar::Tensor poputil::unfactorDims (const poplar::Tensor &t, unsigned numDims, unsigned startDim=0)
 The opposite of factorDims(). More...
 
std::vector< poplar::Intervalpoputil::calculateUnshufflingIntervals (const std::vector< poplar::Interval > &intervals)
 Calculate the un-shuffling intervals based on the given intervals. More...
 

Detailed Description

General operations on tensors.