6#ifndef popnn_Recurrent_hpp
7#define popnn_Recurrent_hpp
31#include <poplar/Graph.hpp>
32#include <poplar/Program.hpp>
49std::vector<std::pair<poplin::MatMulParams, poplar::OptionFlags>>
51 std::size_t inputSize, std::size_t outputSize,
54 bool inferenceOnly =
false,
55 bool hasFeedforwardWeights =
true);
60uint64_t
getFwdFlops(
unsigned sequenceSize,
unsigned batchSize,
61 unsigned inputSize,
unsigned outputSize,
62 bool weightInput =
true);
66uint64_t
getBwdFlops(
unsigned sequenceSize,
unsigned batchSize,
67 unsigned inputSize,
unsigned outputSize,
68 bool calcInputGrad =
true);
72uint64_t
getWuFlops(
unsigned sequenceSize,
unsigned batchSize,
73 unsigned inputSize,
unsigned outputSize);
97 unsigned batchSize,
unsigned inputSize,
100 bool inferenceOnly =
false,
102 poplin::PlanningCache *planningCache =
nullptr);
127 unsigned batchSize,
unsigned outputSize,
131 poplin::PlanningCache *planningCache =
nullptr);
159 poplar::Graph &graph,
unsigned sequenceSize,
unsigned batchSize,
160 unsigned inputSize,
unsigned outputSize,
const poplar::Type &dType,
163 poplin::PlanningCache *planningCache =
nullptr);
179 poplar::Graph &graph,
unsigned batchSize,
unsigned outputSize,
182 poplin::PlanningCache *planningCache =
nullptr);
219 poplin::PlanningCache *planningCache =
nullptr);
260 poplin::PlanningCache *planningCache =
nullptr);
275 unsigned batchSize,
unsigned outputSize,
278 poplin::PlanningCache *planningCache =
nullptr);
321 poplin::PlanningCache *planningCache =
nullptr);
335 poplin::PlanningCache *planningCache =
nullptr);
373 poplin::PlanningCache *planningCache =
nullptr);
416 poplin::PlanningCache *planningCache =
nullptr);
459std::tuple<poplar::Tensor, poplar::Tensor, poplar::Tensor, poplar::Tensor>
470 poplin::PlanningCache *planningCache =
nullptr);
Non-linearity 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 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
Type FLOAT
Device type: float
Linear algebra functions.
Definition: Cholesky.hpp:14
poplar::Tensor forwardWeightInput(poplar::Graph &graph, const poplar::Tensor &actIn, const poplar::Tensor &weights, poplar::program::Sequence &prog, const poplar::Type &partialsType=poplar::FLOAT, bool inferenceOnly=false, const poplar::DebugContext &debugContext={}, poplin::PlanningCache *planningCache=nullptr)
Perform the feedforward part of a RNN layer.
poplar::Tensor getOutputFromFwdState(const poplar::Tensor &fwdState)
Extract previous output tensor from the hidden state.
poplar::Tensor createWeightsInput(poplar::Graph &graph, unsigned sequenceSize, unsigned batchSize, unsigned inputSize, unsigned outputSize, const poplar::Type &dType, const poplar::Type &partialsType=poplar::FLOAT, bool inferenceOnly=false, const poplar::DebugContext &debugContext={}, poplin::PlanningCache *planningCache=nullptr)
Create the weights used to weight the input of a vanilla RNN layer.
std::vector< std::pair< poplin::MatMulParams, poplar::OptionFlags > > getMatMulPrePlanParameters(std::size_t numSteps, std::size_t batchSize, std::size_t inputSize, std::size_t outputSize, const poplar::Type &dType, const poplar::Type &partialsType=poplar::FLOAT, bool inferenceOnly=false, bool hasFeedforwardWeights=true)
Predict what matrix multiplications will be needed for the given parameters and return list of corres...
poplar::Tensor createWeightsFeedback(poplar::Graph &graph, unsigned batchSize, unsigned outputSize, const poplar::Type &dType, const poplar::Type &partialsType=poplar::FLOAT, bool inferenceOnly=false, const poplar::DebugContext &debugContext={}, poplin::PlanningCache *planningCache=nullptr)
Create the weights used in the recurrent part of a vanilla RNN layer.
poplar::Tensor rnnFwdSequence(poplar::Graph &graph, poplar::program::Sequence &prog, const poplar::Tensor &fwdStateInit, const poplar::Tensor *weightedIn, const poplar::Tensor &biases, const poplar::Tensor &feedFwdWeights, const poplar::Tensor &feedbackWeights, const poplar::Tensor &prevLayerActs, const popnn::NonLinearityType &nonLinearityType, const poplar::Type &partialsType, bool inferenceOnly, const poplar::DebugContext &debugContext={}, poplin::PlanningCache *planningCache=nullptr)
Perform the forward part of the RNN layer.
void paramDeltaUpdate(poplar::Graph &graph, const poplar::Tensor &bwdState, const poplar::Tensor &actIn, const poplar::Tensor &prevOut, poplar::Tensor &weightsInputDeltasAcc, poplar::Tensor &weightsFeedbackDeltasAcc, poplar::Tensor &biasDeltasAcc, poplar::program::Sequence &prog, const poplar::Type &partialsType=poplar::FLOAT, const poplar::DebugContext &debugContext={}, poplin::PlanningCache *planningCache=nullptr)
Update parameter deltas for a vanilla RNN step.
poplar::Tensor createBwdState(poplar::Graph &graph, const poplar::Type &dType, unsigned batchSize, unsigned outputSize, poplar::program::Sequence &prog, const poplar::DebugContext &debugContext={}, poplin::PlanningCache *planningCache=nullptr)
Create initial state for backward pass of a vanilla RNN.
uint64_t getBwdFlops(unsigned sequenceSize, unsigned batchSize, unsigned inputSize, unsigned outputSize, bool calcInputGrad=true)
Compute the total floating point operations for the backward pass of RNN.
poplar::Tensor createFwdState(poplar::Graph &graph, const poplar::Type &dType, unsigned batchSize, unsigned outputSize, poplar::program::Sequence &prog, bool initState, bool inferenceOnly, const poplar::DebugContext &debugContext={}, poplin::PlanningCache *planningCache=nullptr)
Create initial state for a vanilla RNN.
uint64_t getFwdFlops(unsigned sequenceSize, unsigned batchSize, unsigned inputSize, unsigned outputSize, bool weightInput=true)
Compute the total floating point operations for the forward pass of RNN.
std::pair< poplar::Tensor, poplar::Tensor > backwardGradientStep(poplar::Graph &graph, const poplar::Tensor &nextLayerGrad, const poplar::Tensor &bwdState, const poplar::Tensor &actOut, const poplar::Tensor &weightsInput, const poplar::Tensor &weightsFeedback, poplar::program::Sequence &prog, popnn::NonLinearityType nonLinearityType, const poplar::Type &partialsType=poplar::FLOAT, const poplar::DebugContext &debugContext={}, poplin::PlanningCache *planningCache=nullptr)
Compute a single step of the backward pass of a vanilla RNN layer.
uint64_t getWuFlops(unsigned sequenceSize, unsigned batchSize, unsigned inputSize, unsigned outputSize)
Compute the total floating point operations for the weight update pass of RNN.
std::tuple< poplar::Tensor, poplar::Tensor, poplar::Tensor, poplar::Tensor > rnnBwdSequence(poplar::Graph &graph, bool doWU, bool ignoreInputGradientCalc, poplar::program::Sequence &prog, const poplar::Tensor &fwdStateInit, const poplar::Tensor &fwdState, const poplar::Tensor &biases, const poplar::Tensor &feedFwdWeights, const poplar::Tensor &feedbackWeights, const poplar::Tensor &outGradient, const poplar::Tensor &actIn, const popnn::NonLinearityType &nonLinearityType, const poplar::Type &partialsType, const poplar::DebugContext &debugContext={}, poplin::PlanningCache *planningCache=nullptr)
Perform the feedback part of the RNN layer.
poplar::Tensor createInput(poplar::Graph &graph, unsigned numSteps, unsigned batchSize, unsigned inputSize, unsigned outputSize, const poplar::Type &dType, const poplar::Type &partialsType=poplar::FLOAT, bool inferenceOnly=false, const poplar::DebugContext &debugContext={}, poplin::PlanningCache *planningCache=nullptr)
Create a tensor which is input to a vanilla RNN.
poplar::Tensor forwardIterate(poplar::Graph &graph, const poplar::Tensor &feedFwdIn, const poplar::Tensor &initState, const poplar::Tensor &feedbackWeights, const poplar::Tensor &biases, poplar::program::Sequence &prog, popnn::NonLinearityType nonLinearityType, const poplar::Type &partialsType=poplar::FLOAT, bool inferenceOnly=false, const poplar::DebugContext &debugContext={}, poplin::PlanningCache *planningCache=nullptr)
Perform the feedback part of the RNN layer.
Functions used in neural networks.
Definition: BatchNorm.hpp:14
NonLinearityType
Definition: NonLinearityDef.hpp:11