Poplar and PopLibs
Reduce.hpp
Go to the documentation of this file.
1// Copyright (c) 2017 Graphcore Ltd. All rights reserved.
8#ifndef popops_Reduce_hpp
9#define popops_Reduce_hpp
10
11#include "popops/Operation.hpp"
13
14#include "poplar/Graph.hpp"
15#include "poplar/Program.hpp"
16#include <poplar/OptionFlags.hpp>
17#include <vector>
18
19namespace popops {
20
24 ReduceParams() = default;
25 // Allow implicit conversion from a popops::Operation.
26 ReduceParams(popops::Operation op, bool update = false)
27 : op(op), update(update) {
28 useScale = false;
29 }
30
42 : op(op), update(update), scale(scale) {
43 useScale = true;
44 }
45
46 // Explicitly disable the old API to avoid accidental type conversion
47 ReduceParams(popops::Operation op, float constantScale,
48 bool update = false) = delete;
49
51 bool update;
52 bool useScale;
53 poplar::Tensor scale;
54};
55
101 const poplar::Type &outType,
102 const std::vector<std::size_t> &dims, ReduceParams params,
104 const poplar::DebugContext &debugContext = {},
105 const poplar::OptionFlags &options = {});
106
113 const std::vector<std::size_t> &dims, ReduceParams params,
115 const poplar::DebugContext &debugContext = {},
116 const poplar::OptionFlags &options = {});
117
126 const poplar::Tensor &out,
127 const std::vector<std::size_t> &dims, ReduceParams params,
129 const poplar::DebugContext &debugContext = {},
130 const poplar::OptionFlags &options = {});
131
157 const poplar::Type &outType,
158 const std::vector<std::size_t> &dims, ReduceParams params,
159 std::vector<poplar::ComputeSet> &css,
160 const poplar::DebugContext &debugContext = {},
161 const poplar::OptionFlags &options = {});
162
164 const std::vector<std::size_t> &dims, ReduceParams params,
165 std::vector<poplar::ComputeSet> &css,
166 const poplar::DebugContext &debugContext = {},
167 const poplar::OptionFlags &options = {});
168
169void reduceWithOutput(poplar::Graph &graph, const poplar::Tensor &in,
170 const poplar::Tensor &out,
171 const std::vector<std::size_t> &dims, ReduceParams params,
172 std::vector<poplar::ComputeSet> &css,
173 const poplar::DebugContext &debugContext = {},
174 const poplar::OptionFlags &options = {});
176
184 std::vector<std::size_t> dims;
185 ReduceParams params;
190 poplar::Type outType;
191 std::string debugName;
192
193 SingleReduceOp(poplar::Tensor in, std::vector<std::size_t> dims,
194 ReduceParams params, poplar::Type outType,
195 std::string debugName = "")
196 : in(std::move(in)), dims(std::move(dims)), params(std::move(params)),
197 useOutType(true), outType(outType), debugName(std::move(debugName)) {}
198
199 SingleReduceOp(poplar::Tensor in, std::vector<std::size_t> dims,
200 ReduceParams params, std::string debugName = "")
201 : in(std::move(in)), dims(std::move(dims)), params(std::move(params)),
202 useOutType(false), outType(poplar::BOOL),
203 debugName(std::move(debugName)) {}
204};
205
226 const std::vector<SingleReduceOp> &reductions,
227 std::vector<poplar::Tensor> &outputs,
229 const poplar::DebugContext &debugContext = {},
230 const poplar::OptionFlags &options = {});
231
232} // namespace popops
233
234#endif // popops_Reduce_hpp
Read/write types of operations used in a reduce.
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 set of option/value string flags to be used in various APIs.
Definition: OptionFlags.hpp:24
A reference to a subset of tensor elements.
Definition: Tensor.hpp:38
Class representing device data types.
Definition: Type.hpp:42
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
Operation
Type of operation to use in a reduction.
Definition: OperationDef.hpp:15
void reduceMany(poplar::Graph &graph, const std::vector< SingleReduceOp > &reductions, std::vector< poplar::Tensor > &outputs, poplar::program::Sequence &prog, const poplar::DebugContext &debugContext={}, const poplar::OptionFlags &options={})
Perform many reductions (in parallel if possible).
void reduceWithOutput(poplar::Graph &graph, const poplar::Tensor &in, const poplar::Tensor &out, const std::vector< std::size_t > &dims, ReduceParams params, poplar::program::Sequence &prog, const poplar::DebugContext &debugContext={}, const poplar::OptionFlags &options={})
Apply a reduction operation to a tensor.
poplar::Tensor reduce(poplar::Graph &graph, const poplar::Tensor &in, const poplar::Type &outType, const std::vector< std::size_t > &dims, ReduceParams params, poplar::program::Sequence &prog, const poplar::DebugContext &debugContext={}, const poplar::OptionFlags &options={})
Apply a reduction operation to a tensor.
Define a PopLibs exception.
Stores parameters for the reduce operation, as well as the basic operation being performed (for examp...
Definition: Reduce.hpp:23
ReduceParams(popops::Operation op, bool update, poplar::Tensor scale)
Define the details of the reduce operation that will be performed by the reduce() and reduceWithOutpu...
Definition: Reduce.hpp:41
The parameterisation of the inputs to a single reduction for the reduceMany() function.
Definition: Reduce.hpp:182
bool useOutType
Note that if useOutType is false then the element type of in is used.
Definition: Reduce.hpp:189