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 v with 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 dim is not a valid dimension of v.

Returns

A tensor which is a permutation of t such 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 dim is not a valid dimension of v.

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 v with the property that all 1D slices in the chosen dimensions are in ascending order with respect to the key tensor k.

This aims to match TensorFlow’s XLA sort: https://www.tensorflow.org/xla/operation_semantics#sort

Note

If k and v 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
  • poputil::poplibs_error – If dim is not a valid dimension of v.

  • poputil::poplibs_error – If v and k are not the same shape.

Returns

A tensor which is a permutation of v such that it is in order with respect to the tensor k in 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 k tensor is also sorted by this in-place operation.

Note

If the k tensor and the v tensor 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
  • poputil::poplibs_error – If dim is not a valid dimension of v.

  • poputil::poplibs_error – If v and k are not the same shape.