Pad

#include <popops/Pad.hpp>

Functions for padding a tensor.

namespace popops

Common functions, such as elementwise and reductions.

Unnamed Group

poplar::Tensor pad(poplar::Graph &graph, const poplar::Tensor &t, const std::vector<std::ptrdiff_t> &paddingLower, const std::vector<std::ptrdiff_t> &paddingUpper, float val = 0.0f, padding::MappingMethod mappingMethod = padding::MappingMethod::ZERO)

Return a tensor with constant padding added.

Parameters
  • graph – The graph containing the tensor.

  • t – The tensor to pad.

  • paddingLower – A vector specifying the amount of padding to add at the start of each dimension. Negative padding truncates.

  • paddingUpper – A vector specifying the amount of padding to add at the end of each dimension. Negative padding truncates.

  • val – The input tensor will be padded with this value.

  • mappingMethod – The method that should be used to map added padding elements.

Returns

The tensor with padding added.

poplar::Tensor pad(poplar::Graph &graph, const poplar::Tensor &t, const std::vector<std::ptrdiff_t> &paddingLower, const std::vector<std::ptrdiff_t> &paddingUpper, int val, padding::MappingMethod mappingMethod = padding::MappingMethod::ZERO)
poplar::Tensor pad(poplar::Graph &graph, const poplar::Tensor &t, const std::vector<std::ptrdiff_t> &paddingLower, const std::vector<std::ptrdiff_t> &paddingUpper, const poplar::Tensor &val, padding::MappingMethod mappingMethod = padding::MappingMethod::ZERO)

Unnamed Group

poplar::Tensor pad(poplar::Graph &graph, const poplar::Tensor &t, std::ptrdiff_t paddingLower, std::ptrdiff_t paddingUpper, unsigned dim, float val = 0.0f, padding::MappingMethod mappingMethod = padding::MappingMethod::ZERO)

Return a tensor with constant padding added to one dimension.

Parameters
  • t – The tensor to pad.

  • paddingLower – The amount of padding to add at the start of the dimension. Negative padding truncates.

  • paddingUpper – The amount of padding to add at the end of the dimension. Negative padding truncates.

  • dim – The dimension to pad.

  • val – The input tensor will be padded with this value.

  • mappingMethod – The method that should be used to map added padding elements.

Returns

The tensor with padding added.

poplar::Tensor pad(poplar::Graph &graph, const poplar::Tensor &t, std::ptrdiff_t paddingLower, std::ptrdiff_t paddingUpper, unsigned dim, int val, padding::MappingMethod mappingMethod = padding::MappingMethod::ZERO)
poplar::Tensor pad(poplar::Graph &graph, const poplar::Tensor &t, std::ptrdiff_t paddingLower, std::ptrdiff_t paddingUpper, unsigned dim, const poplar::Tensor &val, padding::MappingMethod mappingMethod = padding::MappingMethod::ZERO)

Functions

poplar::Tensor pad(const poplar::Tensor &t, const std::vector<std::ptrdiff_t> &paddingLower, const std::vector<std::ptrdiff_t> &paddingUpper, padding::Type type)

Return a tensor with numpy-style padding added.

Parameters
  • t – The tensor to pad.

  • paddingLower – A vector specifying the amount of padding to add at the start of each dimension. Negative padding truncates.

  • paddingUpper – A vector specifying the amount of padding to add at the end of each dimension. Negative padding truncates.

  • type – The type of padding.

Returns

The tensor with padding added.

poplar::Tensor pad(const poplar::Tensor &t, std::ptrdiff_t paddingLower, std::ptrdiff_t paddingUpper, unsigned dim, padding::Type type)

Return a tensor with numpy-style padding added to one dimension.

Parameters
  • t – The tensor to pad.

  • paddingLower – The amount of padding to add at the start of the dimension. Negative padding truncates.

  • paddingUpper – The amount of padding to add at the end of the dimension. Negative padding truncates.

  • dim – The dimension to pad.

Returns

The tensor with padding added.

namespace padding

Enums

enum class Type

Padding types as per numpy.pad.

Values:

enumerator EDGE

Also known as nearest-neighbour padding, each new pad element has its value set to that of the pre-padded element nearest to it.

Any such nearest neighbour lies on the edge of the pre-padded tensor, hence the name.

enumerator REFLECT

The tensor is reflected outwards.

Specifically, a new pad element has its value set to that of the element which is an equal distance to the pad element’s nearest neighbour as the pad element, but in the opposite direction.

enum class MappingMethod

Methods to map added padding elements to tiles.

Values:

enumerator NONE

Padding won’t be mapped.

enumerator ZERO

Set tile mapping of padding element to tile 0 for the graph.

enumerator EDGE

Set tile mapping of padding elements to match the nearest-neighbour element which lies on the edge of the tensor prior to padding.

Requires a non-empty tensor to be padded with a complete tile mapping.