Encoding

#include <popops/Encoding.hpp>

Encoding and generating ranges of integers.

namespace popops

Common functions, such as elementwise and reductions.

Functions

void encodeOneHot(poplar::Graph &graph, const poplar::Tensor &indices, const poplar::Tensor &encoded, poplar::program::Sequence &prog, const poplar::DebugContext &debugContext = {})

Encode a given set of indices as a set of one-hot vectors per-index with a hot element at that index.

That is, given a one-dimensional indices tensor with length N and a two-dimensional encoded tensor with shape N * x, encoded is a tensor with a single element equal to 1, and all others equal 0. The single hot element in each row is given by the indices in indices.

Parameters
  • graph – The graph to add the tensor and any vertices needed for the encoding to.

  • encoded – Tensor to encode output to.

  • indices – 1-dimensional tensor containing indices to encode as one-hot vectors. A codepoint MASKED_LABEL_CODE is reserved to indicate that the encoding is not done for that index.

  • prog – Sequence which the programs that perform the encoding are added to.

  • debugContext – Optional debug information.

Throws
  • poputil::poplibs_error – If encoded is not two dimensional.

  • poputil::poplibs_error – If indices and encoded do not have the same number of rows.

  • poputil::poplibs_error – If elements of indices are not an integer type.

void encodeOneHot(poplar::Graph &graph, const poplar::Tensor &indices, const poplar::Tensor &encoded, poplar::program::Sequence &prog, const poplar::Tensor &on, const poplar::Tensor &off, const poplar::DebugContext &debugContext = {})

Encode a given set of indices as a set of one-hot vectors per-index with a hot element at that index.

That is, given a one-dimensional indices tensor with length N and a two-dimensional encoded tensor with shape N * x encoded is a tensor with a single element equal to on, and all others equal to off as given by the user. The single hot element in each row is given by the indices in indices.

Parameters
  • graph – The graph to add the tensor and any vertices needed for the encoding to.

  • encoded – Tensor to encode output to.

  • indices – 1-dimensional tensor containing indices to encode as one-hot vectors.

  • prog – Sequence which the programs that perform the encoding are added to.

  • debugContext – Optional debug information.

  • on – Value which represents the “On” state in the one hot encoded output.

  • off – Value which represents the “Off” state.

Throws
  • poputil::poplibs_error – If encoded is not two dimensional.

  • poputil::poplibs_error – If indices and encoded do not have the same number of rows.

  • poputil::poplibs_error – If elements of indices are not an integer type.

void iota(poplar::Graph &graph, const poplar::Tensor &t, unsigned startInteger, poplar::program::Sequence &prog, const poplar::DebugContext &debugContext = {})

Fill a tensor with a right-open range of unsigned integers: [startInteger, startInteger + length), where length is the number of elements in the mapped 1-D output tensor t.

The output tensor t must be of type UNSIGNED_INT.

Parameters
  • graph – The graph to add the tensor and any vertices needed for the operation.

  • t – 1-D tensor to write the encoded output to. The tensor must be mapped.

  • startInteger – The start value in the output range.

  • prog – Sequence which the programs that perform the encoding are added to.

  • debugContext – Optional debug information.

Throws
  • poputil::poplibs_error – If the rank of t is greater than 1.

  • poputil::poplibs_error – If the type of t is not UNSIGNED_INT.

void iota(poplar::Graph &graph, const poplar::Tensor &t, int startInteger, poplar::program::Sequence &prog, const poplar::DebugContext &debugContext = {})

Fill a tensor with a right-open range of signed integers: [startInteger, startInteger + length), where length is the number of elements in the mapped 1-D output tensor t.

The output tensor t must be of type INT.

Parameters
  • graph – The graph to add the tensor and any vertices needed for the operation.

  • t – 1-D tensor to write the encoded output to. The tensor must be mapped.

  • startInteger – The start value in the output range.

  • prog – Sequence which the programs that perform the encoding are added to.

  • debugContext – Optional debug information.

Throws
  • poputil::poplibs_error – If the rank of t is greater than 1.

  • poputil::poplibs_error – If the type of t is not INT.