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-dimensionalencoded
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 inindices
.- 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
-
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-dimensionalencoded
tensor with shape N * xencoded
is a tensor with a single element equal toon
, and all others equal tooff
as given by the user. The single hot element in each row is given by the indices inindices
.- 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
-
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
-
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
-
void encodeOneHot(poplar::Graph &graph, const poplar::Tensor &indices, const poplar::Tensor &encoded, poplar::program::Sequence &prog, const poplar::DebugContext &debugContext = {})