Poplar and PopLibs
TopK.hpp
Go to the documentation of this file.
1// Copyright (c) 2020 Graphcore Ltd. All rights reserved.
6#ifndef _popops_TopK_hpp_
7#define _popops_TopK_hpp_
8
9#include <poplar/Graph.hpp>
10#include <poplar/Program.hpp>
11#include <poplar/Tensor.hpp>
12
13#include <popops/SortOrder.hpp>
14
15namespace popops {
16
19struct TopKParams {
23 unsigned k;
26 bool largest;
33
34 TopKParams(unsigned k, bool largest, SortOrder sortOrder,
35 bool stableSort = false) noexcept;
36};
37
38std::ostream &operator<<(std::ostream &os, const TopKParams &p);
39
52poplar::Tensor createTopKInput(poplar::Graph &graph, const poplar::Type &type,
53 const std::vector<std::size_t> &shape,
54 const TopKParams &params,
55 const poplar::DebugContext &debugContext = {});
56
70 const poplar::Tensor &t, const TopKParams &params,
71 const poplar::DebugContext &debugContext = {});
72
90std::pair<poplar::Tensor, poplar::Tensor>
92 const poplar::Tensor &keys, const poplar::Tensor &values,
93 const TopKParams &params,
94 const poplar::DebugContext &debugContext = {});
95
112std::pair<poplar::Tensor, poplar::Tensor>
114 const poplar::Tensor &t, const TopKParams &params,
115 const poplar::DebugContext &debugContext = {});
116
117} // end namespace popops
118
119#endif // _popops_TopK_hpp_
Defintions of sort ordering.
DebugContext gathers the common external parameters of the context of an operation.
Definition: DebugContext.hpp:221
This class represents a graph program to be executed on the IPU.
Definition: Graph.hpp:52
A reference to a subset of tensor elements.
Definition: Tensor.hpp:38
Program that executes a sequence of programs.
Definition: Program.hpp:77
Poplar classes and functions.
Definition: ArrayRef.hpp:14
Common functions, such as elementwise and reductions.
Definition: AllTrue.hpp:15
poplar::Tensor topK(poplar::Graph &graph, poplar::program::Sequence &prog, const poplar::Tensor &t, const TopKParams &params, const poplar::DebugContext &debugContext={})
Return the top k values in the innermost dimension of a tensor.
SortOrder
Defines a required order for sorting operations.
Definition: SortOrder.hpp:14
poplar::Tensor createTopKInput(poplar::Graph &graph, const poplar::Type &type, const std::vector< std::size_t > &shape, const TopKParams &params, const poplar::DebugContext &debugContext={})
Create an return a new tensor laid out optimally to be used as an input to a topK operation with the ...
std::pair< poplar::Tensor, poplar::Tensor > topKWithPermutation(poplar::Graph &graph, poplar::program::Sequence &prog, const poplar::Tensor &t, const TopKParams &params, const poplar::DebugContext &debugContext={})
Return the top k values in the innermost dimension of a tensor along with the indices of those values...
std::pair< poplar::Tensor, poplar::Tensor > topKKeyValue(poplar::Graph &graph, poplar::program::Sequence &prog, const poplar::Tensor &keys, const poplar::Tensor &values, const TopKParams &params, const poplar::DebugContext &debugContext={})
Return the top k values in the innermost dimension of a tensor along with the permutation of another ...
Parameters for topK* APIs.
Definition: TopK.hpp:19
unsigned k
The number of outputs from the top k operation.
Definition: TopK.hpp:23
SortOrder sortOrder
The required ordering of elements in the resulting tensor.
Definition: TopK.hpp:28
bool largest
If true, return the top k largest elements.
Definition: TopK.hpp:26
bool stableSort
When sortOrder != SortOrder::NONE and stableSort is true, the relative order of values that compare e...
Definition: TopK.hpp:32