Poplar and PopLibs
NonLinearity.hpp
Go to the documentation of this file.
1
// Copyright (c) 2016 Graphcore Ltd. All rights reserved.
6
#ifndef popnn_NonLinearity_hpp
7
#define popnn_NonLinearity_hpp
8
9
#include <
popnn/NonLinearityDef.hpp
>
10
11
#ifndef __POPC__
12
#include <poplar/Graph.hpp>
13
#include <poplar/Program.hpp>
14
15
namespace
popnn
{
16
17
#define DEF_NONLINEARITY_INPLACE(fn, nlType) \
18
inline void fn##InPlace(poplar::Graph &graph, poplar::Tensor t, \
19
poplar::program::Sequence &prog, \
20
const poplar::DebugContext &debugContext = {}) { \
21
nonLinearityInPlace(graph, nlType, t, prog, debugContext); \
22
} \
23
inline void fn##InPlace(poplar::Graph &graph, poplar::Tensor t, \
24
float &nonLinearityScaling, \
25
poplar::program::Sequence &prog, \
26
const poplar::DebugContext &debugContext = {}) { \
27
nonLinearityInPlace(graph, nlType, t, nonLinearityScaling, prog, \
28
debugContext); \
29
}
30
31
#define DEF_NONLINEARITY_(fn, nlType) \
32
inline poplar::Tensor fn(poplar::Graph &graph, poplar::Tensor t, \
33
poplar::program::Sequence &prog, \
34
const poplar::DebugContext &debugContext = {}) { \
35
return nonLinearity(graph, nlType, t, prog, debugContext); \
36
} \
37
inline poplar::Tensor fn(poplar::Graph &graph, poplar::Tensor t, \
38
float &nonLinearityScaling, \
39
poplar::program::Sequence &prog, \
40
const poplar::DebugContext &debugContext = {}) { \
41
return nonLinearity(graph, nlType, t, nonLinearityScaling, prog, \
42
debugContext); \
43
}
44
45
#define DEF_NONLINEARITY(fn, nlType) \
46
DEF_NONLINEARITY_INPLACE(fn, nlType) \
47
DEF_NONLINEARITY_(fn, nlType)
48
57
void
nonLinearityInPlace(
poplar::Graph
&graph,
58
NonLinearityType
nonLinearityType,
poplar::Tensor
t,
59
poplar::program::Sequence
&prog,
60
const
poplar::DebugContext
&debugContext = {});
61
70
void
nonLinearityInPlace(
poplar::Graph
&graph,
71
NonLinearityType
nonLinearityType,
poplar::Tensor
t,
72
poplar::ComputeSet
&cs,
73
const
poplar::DebugContext
&debugContext = {});
74
91
void
nonLinearityInPlace(
poplar::Graph
&graph,
92
NonLinearityType
nonLinearityType,
poplar::Tensor
t,
93
float
&nonLinearityScaling,
94
poplar::program::Sequence
&prog,
95
const
poplar::DebugContext
&debugContext = {});
96
113
void
nonLinearityInPlace(
poplar::Graph
&graph,
114
NonLinearityType
nonLinearityType,
poplar::Tensor
t,
115
float
&nonLinearityScaling,
poplar::ComputeSet
&cs,
116
const
poplar::DebugContext
&debugContext = {});
117
129
poplar::Tensor
nonLinearity(
poplar::Graph
&graph,
130
NonLinearityType
nonLinearityType,
poplar::Tensor
t,
131
poplar::program::Sequence
&prog,
132
const
poplar::DebugContext
&debugContext = {});
133
153
poplar::Tensor
nonLinearity(
poplar::Graph
&graph,
154
NonLinearityType
nonLinearityType,
poplar::Tensor
t,
155
float
&nonLinearityScaling,
156
poplar::program::Sequence
&prog,
157
const
poplar::DebugContext
&debugContext = {});
158
159
DEF_NONLINEARITY(
sigmoid
,
NonLinearityType::SIGMOID
)
160
DEF_NONLINEARITY(relu,
NonLinearityType::RELU
)
161
DEF_NONLINEARITY(
tanh
,
NonLinearityType::TANH
)
162
DEF_NONLINEARITY(gelu,
NonLinearityType::GELU
)
163
DEF_NONLINEARITY(swish, NonLinearityType::SWISH)
164
DEF_NONLINEARITY(softmax,
NonLinearityType::SOFTMAX
)
165
DEF_NONLINEARITY(softmaxStable,
NonLinearityType::SOFTMAX_STABLE
)
166
DEF_NONLINEARITY(scaledSoftmaxStable,
NonLinearityType::SOFTMAX_SCALED
)
167
168
184
poplar::Tensor
185
nonLinearityInputGradient(
poplar::Graph
&graph,
186
NonLinearityType
nonLinearityType,
poplar::Tensor
act,
187
poplar::Tensor
outGradient,
poplar::ComputeSet
&cs,
188
const
poplar::DebugContext
&debugContext = {});
189
206
poplar::Tensor
nonLinearityInputGradient(
207
poplar::Graph
&graph,
NonLinearityType
nonLinearityType,
poplar::Tensor
act,
208
poplar::Tensor
outGradient,
poplar::program::Sequence
&prog,
209
const
poplar::DebugContext
&debugContext = {});
210
211
}
// end namespace popnn
212
213
#endif
// !__POPC__
214
215
#endif
// popnn_NonLinearity_hpp
NonLinearityDef.hpp
Definitions for non-linearity operations.
poplar::ComputeSet
A reference to a compute set within a graph.
Definition:
GraphElements.hpp:131
poplar::DebugContext
DebugContext gathers the common external parameters of the context of an operation.
Definition:
DebugContext.hpp:221
poplar::Graph
This class represents a graph program to be executed on the IPU.
Definition:
Graph.hpp:52
poplar::Tensor
A reference to a subset of tensor elements.
Definition:
Tensor.hpp:38
poplar::program::Sequence
Program that executes a sequence of programs.
Definition:
Program.hpp:77
ipu::sigmoid
float sigmoid(float x)
The sigmoid function, ie 1/(1 + exp(- x )).
Definition:
ipu_vector_math:1427
ipu::tanh
half2 tanh(half2 src)
Targets the f16v2tanh instruction.
Definition:
ipu_intrinsics:546
popnn
Functions used in neural networks.
Definition:
BatchNorm.hpp:14
popnn::NonLinearityType
NonLinearityType
Definition:
NonLinearityDef.hpp:11
popnn::NonLinearityType::TANH
@ TANH
Hyperbolic tangent:
popnn::NonLinearityType::SOFTMAX
@ SOFTMAX
Softmax:
popnn::NonLinearityType::SOFTMAX_STABLE
@ SOFTMAX_STABLE
Same as SOFTMAX, but slower more numerically stable algorithm used.
popnn::NonLinearityType::GELU
@ GELU
Gaussian Error Linear Unit:
popnn::NonLinearityType::SOFTMAX_SCALED
@ SOFTMAX_SCALED
Same as SOFTMAX, but slower more numerically stable algorithm used.
popnn::NonLinearityType::SIGMOID
@ SIGMOID
Sigmoid:
popnn::NonLinearityType::RELU
@ RELU
Rectified Linear Unit:
include
popnn
NonLinearity.hpp
Generated by
1.9.3