Sort
#include <popops/Sort.hpp>
Functions for sorting tensors.
-
namespace popops
Common functions, such as elementwise and reductions.
Functions
-
poplar::Tensor sort(poplar::Graph &graph, const poplar::Tensor &t, unsigned dim, poplar::program::Sequence &prog, const poplar::DebugContext &debugContext = {})
- Deprecated:
deprecated Use popops::topK() instead.
Sort a tensor along the given dimension.
This will return a tensor that is a permutation of the input tensor
vwith all the elements of the 1D slices in the chosen dimension in ascending order.This aims to match TensorFlow’s XLA sort: https://www.tensorflow.org/xla/operation_semantics#sort
- Parameters
graph – The Poplar graph.
t – The source tensor.
dim – The dimension to sort on.
prog – The program to be extended.
debugContext – Optional debug information.
- Throws
poputil::poplibs_error – If
dimis not a valid dimension ofv.- Returns
A tensor which is a permutation of
tsuch that all elements in the given dimension are in order.
-
void sortInPlace(poplar::Graph &graph, const poplar::Tensor &t, unsigned dim, poplar::program::Sequence &prog, const poplar::DebugContext &debugContext = {})
- Deprecated:
deprecated Use popops::topK() instead.
In-place sort a tensor along the given dimension.
This will permute the input tensor so that all the elements of 1D slices in the chosen dimension are in ascending order.
- Parameters
graph – The Poplar graph.
t – The source tensor to be sorted.
dim – The dimension to sort on.
prog – The program to be extended.
debugContext – Optional debug information.
- Throws
poputil::poplibs_error – If
dimis not a valid dimension ofv.
-
poplar::Tensor sortKeyValue(poplar::Graph &graph, const poplar::Tensor &k, const poplar::Tensor &v, unsigned dim, poplar::program::Sequence &prog, const poplar::DebugContext &debugContext = {})
- Deprecated:
deprecated Use popops::topKKeyValue() instead.
Sort a tensor by a key tensor along the given dimension.
This will return a tensor that is a permutation of the input tensor
vwith the property that all 1D slices in the chosen dimensions are in ascending order with respect to the key tensork.This aims to match TensorFlow’s XLA sort: https://www.tensorflow.org/xla/operation_semantics#sort
Note
If
kandvalias, the result is undefined.- Parameters
graph – The Poplar graph.
k – The key tensor to sort on.
v – The value tensor to be sorted.
dim – The dimension to sort on.
prog – The program to be extended.
debugContext – Optional debug information.
- Throws
- Returns
A tensor which is a permutation of
vsuch that it is in order with respect to the tensorkin the given dimension.
-
void sortKeyValueInPlace(poplar::Graph &graph, const poplar::Tensor &k, const poplar::Tensor &v, unsigned dim, poplar::program::Sequence &prog, const poplar::DebugContext &debugContext = {})
- Deprecated:
deprecated Use popops::topKKeyValue() instead.
In-place sort a given tensor by a key tensor along the given dimension.
This will permute the key and value tensors so that all the elements of the 1D slices in the chosen dimension are in ascending order with respect to the key tensor.
Note
The
ktensor is also sorted by this in-place operation.Note
If the
ktensor and thevtensor alias, the result is undefined.- Parameters
graph – The Poplar graph.
k – The key tensor to sort on.
v – The value tensor to be sorted.
dim – The dimension to sort on.
prog – The program to be extended.
debugContext – Optional debug information.
- Throws
-
poplar::Tensor sort(poplar::Graph &graph, const poplar::Tensor &t, unsigned dim, poplar::program::Sequence &prog, const poplar::DebugContext &debugContext = {})