Poplar and PopLibs
Pooling.hpp
Go to the documentation of this file.
1// Copyright (c) 2016 Graphcore Ltd. All rights reserved.
6#ifndef popnn_Pooling_hpp
7#define popnn_Pooling_hpp
8#include <cstdint>
9#include <poplar/Graph.hpp>
10#include <poplar/OptionFlags.hpp>
11#include <poplar/Program.hpp>
12#include <popnn/PoolingDef.hpp>
13#include <tuple>
14
15namespace popnn {
17namespace pooling {
18
19struct PoolParams {
22 PoolingType poolingType;
25 std::vector<std::size_t> inputFieldShape;
27 std::vector<std::size_t> kernelShape;
29 std::vector<unsigned> stride;
33 std::vector<int> inputTruncationOrPaddingLower;
37 std::vector<int> inputTruncationOrPaddingUpper;
39 std::size_t numChannels;
41 std::size_t batchSize;
43 poplar::Type dType;
44
45 PoolParams(PoolingType poolingType, std::vector<std::size_t> inputFieldShape,
46 std::vector<std::size_t> kernelShape, std::vector<unsigned> stride,
47 std::vector<int> inputTruncationOrPaddingLower,
48 std::vector<int> inputTruncationOrPaddingUpper,
49 std::size_t numChannels, std::size_t batchSize, poplar::Type dType)
50 : poolingType(poolingType), inputFieldShape(std::move(inputFieldShape)),
51 kernelShape(std::move(kernelShape)), stride(std::move(stride)),
52 inputTruncationOrPaddingLower(std::move(inputTruncationOrPaddingLower)),
53 inputTruncationOrPaddingUpper(std::move(inputTruncationOrPaddingUpper)),
54 numChannels(numChannels), batchSize(batchSize), dType(dType) {}
55
56 std::size_t getNumFieldDims() const { return inputFieldShape.size(); }
57 std::vector<std::size_t> getOutputFieldShape() const;
58};
59
60std::ostream &operator<<(std::ostream &o, const PoolParams &params);
61
62const char *asString(const PoolingType &method);
63
64std::vector<std::size_t> getOutputFieldShape(const PoolParams &params);
65
66uint64_t getFwdFlops(const PoolParams &params);
67
68uint64_t getBwdFlops(const PoolParams &params);
69
70double getFwdPerfectCycleCount(const poplar::Graph &graph,
71 const PoolParams &params);
72
73double getBwdPerfectCycleCount(const poplar::Graph &graph,
74 const PoolParams &params);
75
89/*[INTERNAL]
90 * **Pooling options**
91 *
92 * * `poolUseIntrospectiveMapping` (true, false) [=true]
93 *
94 * If true, take into account the tile mapping of the output tensor (where
95 * it is provided as an argument) or the input tensor when deciding how
96 * to map the pooling operation across tiles.
97 */
98poplar::Tensor pool(poplar::Graph &graph, const PoolParams &params,
100 const poplar::DebugContext &debugContext = {},
101 const poplar::OptionFlags &options = {});
102
103// clang-format off
104// Need long lines for Doxygen
126// clang-format on
127poplar::Tensor poolInputGradient(poplar::Graph &graph, const PoolParams &params,
128 const poplar::Tensor &in,
129 const poplar::Tensor &pooled,
130 const poplar::Tensor &pooledGradient,
131 bool useScaledGradient,
133 const poplar::DebugContext &debugContext = {},
134 const poplar::OptionFlags &options = {});
135
153poplar::Tensor poolInputGradient(poplar::Graph &graph, const PoolParams &params,
154 const unsigned fwdChansPerGroup,
155 const poplar::Tensor &pooledGradient,
157 const poplar::DebugContext &debugContext = {},
158 const poplar::OptionFlags &options = {});
159
160} // namespace pooling
161} // namespace popnn
162
163#endif // popnn_Pooling_hpp
Definitions for pooling operations.
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::Tensor pool(poplar::Graph &graph, const PoolParams &params, const poplar::Tensor &in, poplar::program::Sequence &prog, const poplar::DebugContext &debugContext={}, const poplar::OptionFlags &options={})
Add a pooling operation to the graph.
poplar::Tensor poolInputGradient(poplar::Graph &graph, const PoolParams &params, const poplar::Tensor &in, const poplar::Tensor &pooled, const poplar::Tensor &pooledGradient, bool useScaledGradient, poplar::program::Sequence &prog, const poplar::DebugContext &debugContext={}, const poplar::OptionFlags &options={})
Calculate the gradient with respect to the input of a pooling operation given the gradient of the out...
Functions used in neural networks.
Definition: BatchNorm.hpp:14
PoolingType
Pooling types.
Definition: PoolingDef.hpp:12