This class arranges the cindex_ids of the computation into a sequence of lists called "steps", which will correspond roughly to the commands in the compiled computation. More...
#include <nnet-computation-graph.h>
Public Member Functions | |
ComputationStepsComputer (const Nnet &nnet, ComputationGraph *graph, std::vector< std::vector< int32 > > *steps, std::vector< std::pair< int32, int32 > > *locations) | |
Constructor. More... | |
void | ComputeForSegment (const ComputationRequest &request, const std::vector< std::vector< int32 > > &phases) |
You call this once for each segment, in order (note: for normal, non-online computations, there is only one segment). More... | |
void | Check () const |
This is only to be called after you have called ComputeForSegment for all the segments. More... | |
Private Member Functions | |
void | ProcessSubPhase (const ComputationRequest &request, const std::vector< Cindex > &sub_phase) |
void | ProcessDimRangeSubPhase (const std::vector< Cindex > &sub_phase) |
void | ProcessInputOrOutputStep (const ComputationRequest &request, bool is_output, const std::vector< Cindex > &sub_phase) |
void | ProcessComponentStep (const std::vector< Cindex > &step) |
void | SplitIntoSubPhases (const std::vector< int32 > &phase, std::vector< std::vector< Cindex > > *sub_phase) const |
int32 | AddStep (const std::vector< Cindex > &cindexes, bool add_if_absent=false) |
int32 | AddStep (std::vector< int32 > *cindex_ids) |
void | ConvertToCindexes (const std::vector< int32 > &cindex_ids, std::vector< Cindex > *cindexes) const |
void | ConvertToCindexIds (const std::vector< Cindex > &cindexes, std::vector< int32 > *cindex_ids) const |
void | ConvertToLocations (const std::vector< int32 > &cindex_ids, std::vector< std::pair< int32, int32 > > *locations) const |
Static Private Member Functions | |
static void | ConvertToIndexes (const std::vector< Cindex > &cindexes, std::vector< Index > *indexes) |
static void | ConvertToCindexes (const std::vector< Index > &indexes, int32 node_index, std::vector< Cindex > *cindexes) |
Private Attributes | |
const Nnet & | nnet_ |
ComputationGraph * | graph_ |
std::vector< std::vector< int32 > > * | steps_ |
steps_ is a pointer to an output that's passed in in the constructor. More... | |
std::vector< std::pair< int32, int32 > > * | locations_ |
locations_ is a map from cindex_id to the pair of indexes into steps_ where that cindex_id resides, so if (*locations_)[c] = (i,j), then (*steps_)[i][j] == c. More... | |
std::unordered_set< std::pair< int32, int32 >, PairHasher< int32 > > | dim_range_nodes_ |
dim_range_nodes_ is used when allocating steps for nodes of type kDimRangeNode. More... | |
This class arranges the cindex_ids of the computation into a sequence of lists called "steps", which will correspond roughly to the commands in the compiled computation.
The steps are finer than phases. (See Organizing the computation into steps for more info). To summarize the properties that these steps will satisfy:
There are also some extra, more obscure properties that the sequence of steps must satisfy:
The reason why computation_graph is not provided as a const argument is that in order to ensure the final property we may have to add a few new cindex_ids.
Definition at line 415 of file nnet-computation-graph.h.
ComputationStepsComputer | ( | const Nnet & | nnet, |
ComputationGraph * | graph, | ||
std::vector< std::vector< int32 > > * | steps, | ||
std::vector< std::pair< int32, int32 > > * | locations | ||
) |
Constructor.
[in] | nnet | The neural network that this computation is for. |
[in,out] | graph | The computation graph that we're computing the steps for. It's only non-const because there are couple of unusual situations in which we may need to add new cindexes: (1) For nodes of type kDimRange, we may add cindexes to enable the node to span a contiguous range of the input indexes. (2) For certain non-simple Components (principally CNN-related components), we may need to add 'blank' cindexes (defined as cindexes where the 't' indexes are replaced by kNoTime), for zero-padding and to turn irregularly structured computations into regularly structured ones as needed by the component's implementation. |
[out] | steps | The main output of this class, which is a sequence of steps, each step being an ordered list of cindex_ids. It just gets cleared in the constructor; it's set up when you call ComputeForSegment(). |
[out] | locations | The additional output of this class, which is a function of the information in 'steps'. The array 'locations' is indexed by cindex_id, and each one is a pair (step-index, index-into-step), so that for any cindex_id c, (*steps)[locations[c].first][locations[c].second] == c. It's possible in principle if there are non-simple Components, that for nodes corresponding to component-input descriptors, a cindex might be present in more than one step, so it doesn't follow that if (*steps)[i][j] == c, then locations[c] == (i,j). |
Definition at line 1515 of file nnet-computation-graph.cc.
References ComputationGraph::cindexes, ComputationStepsComputer::graph_, ComputationStepsComputer::locations_, and ComputationStepsComputer::steps_.
Definition at line 1583 of file nnet-computation-graph.cc.
References ComputationGraph::GetCindexId(), ComputationStepsComputer::graph_, KALDI_ASSERT, ComputationStepsComputer::locations_, and ComputationStepsComputer::steps_.
Referenced by ComputationStepsComputer::ProcessComponentStep(), ComputationStepsComputer::ProcessDimRangeSubPhase(), and ComputationStepsComputer::ProcessInputOrOutputStep().
Definition at line 1636 of file nnet-computation-graph.cc.
References ComputationGraph::cindexes, ComputationStepsComputer::graph_, KALDI_ASSERT, and ComputationStepsComputer::steps_.
void Check | ( | ) | const |
This is only to be called after you have called ComputeForSegment for all the segments.
Definition at line 1922 of file nnet-computation-graph.cc.
References ComputationGraph::cindexes, ComputationStepsComputer::graph_, KALDI_ASSERT, KALDI_ERR, kaldi::nnet3::kNoTime, ComputationStepsComputer::locations_, and ComputationStepsComputer::steps_.
Referenced by Compiler::CreateComputation().
void ComputeForSegment | ( | const ComputationRequest & | request, |
const std::vector< std::vector< int32 > > & | phases | ||
) |
You call this once for each segment, in order (note: for normal, non-online computations, there is only one segment).
Definition at line 1530 of file nnet-computation-graph.cc.
References rnnlm::i, rnnlm::j, ComputationStepsComputer::ProcessSubPhase(), and ComputationStepsComputer::SplitIntoSubPhases().
Referenced by Compiler::CreateComputation().
|
private |
Definition at line 1655 of file nnet-computation-graph.cc.
References ComputationGraph::cindexes, ComputationStepsComputer::graph_, and KALDI_ASSERT.
Referenced by ComputationStepsComputer::ProcessComponentStep(), ComputationStepsComputer::ProcessDimRangeSubPhase(), and ComputationStepsComputer::SplitIntoSubPhases().
|
staticprivate |
|
private |
Definition at line 1671 of file nnet-computation-graph.cc.
References ComputationGraph::GetCindexId(), ComputationStepsComputer::graph_, and KALDI_ASSERT.
Referenced by ComputationStepsComputer::ProcessComponentStep(), and ComputationStepsComputer::ProcessDimRangeSubPhase().
|
staticprivate |
Definition at line 1687 of file nnet-computation-graph.cc.
Referenced by ComputationStepsComputer::ProcessComponentStep().
|
private |
Definition at line 1806 of file nnet-computation-graph.cc.
References KALDI_ASSERT, and ComputationStepsComputer::locations_.
Referenced by ComputationStepsComputer::ProcessDimRangeSubPhase().
|
private |
Definition at line 1717 of file nnet-computation-graph.cc.
References ComputationStepsComputer::AddStep(), ComputationGraph::cindexes, NetworkNode::component_index, ComputationStepsComputer::ConvertToCindexes(), ComputationStepsComputer::ConvertToCindexIds(), ComputationStepsComputer::ConvertToIndexes(), rnnlm::d, ComputationGraph::dependencies, Nnet::GetComponent(), Nnet::GetNode(), ComputationStepsComputer::graph_, Nnet::IsComponentNode(), KALDI_ASSERT, kaldi::nnet3::kReordersIndexes, kaldi::nnet3::kSimpleComponent, ComputationStepsComputer::nnet_, Component::Properties(), Component::ReorderIndexes(), and NetworkNode::u.
Referenced by ComputationStepsComputer::ProcessSubPhase().
|
private |
Definition at line 1828 of file nnet-computation-graph.cc.
References ComputationStepsComputer::AddStep(), ComputationStepsComputer::ConvertToCindexes(), ComputationStepsComputer::ConvertToCindexIds(), ComputationStepsComputer::ConvertToLocations(), ComputationStepsComputer::dim_range_nodes_, Nnet::GetNode(), Nnet::IsDimRangeNode(), KALDI_ASSERT, ComputationStepsComputer::nnet_, NetworkNode::node_index, and NetworkNode::u.
Referenced by ComputationStepsComputer::ProcessSubPhase().
|
private |
Definition at line 1543 of file nnet-computation-graph.cc.
References ComputationStepsComputer::AddStep(), ComputationGraph::GetCindexId(), Nnet::GetNodeName(), ComputationStepsComputer::graph_, rnnlm::i, ComputationRequest::inputs, Nnet::IsInputNode(), Nnet::IsOutputNode(), KALDI_ASSERT, ComputationStepsComputer::locations_, ComputationStepsComputer::nnet_, and ComputationRequest::outputs.
Referenced by ComputationStepsComputer::ProcessSubPhase().
|
private |
Definition at line 1896 of file nnet-computation-graph.cc.
References Nnet::IsComponentInputNode(), Nnet::IsComponentNode(), Nnet::IsDimRangeNode(), Nnet::IsInputNode(), Nnet::IsOutputNode(), KALDI_ASSERT, KALDI_ERR, ComputationStepsComputer::nnet_, ComputationStepsComputer::ProcessComponentStep(), ComputationStepsComputer::ProcessDimRangeSubPhase(), and ComputationStepsComputer::ProcessInputOrOutputStep().
Referenced by ComputationStepsComputer::ComputeForSegment().
|
private |
Definition at line 1943 of file nnet-computation-graph.cc.
References ComputationStepsComputer::ConvertToCindexes(), rnnlm::i, and KALDI_ASSERT.
Referenced by ComputationStepsComputer::ComputeForSegment().
|
private |
dim_range_nodes_ is used when allocating steps for nodes of type kDimRangeNode.
This is a set of (source_step, dim_range_node_index), where source_step is the step in which we computed of the input of the dim-range node (this step will be for a node of type kComponentNode). This just tells us whether we've already added a particular dim-range node for this step, so we know whether we need to add it again.
Definition at line 559 of file nnet-computation-graph.h.
Referenced by ComputationStepsComputer::ProcessDimRangeSubPhase().
|
private |
Definition at line 543 of file nnet-computation-graph.h.
Referenced by ComputationStepsComputer::AddStep(), ComputationStepsComputer::Check(), ComputationStepsComputer::ComputationStepsComputer(), ComputationStepsComputer::ConvertToCindexes(), ComputationStepsComputer::ConvertToCindexIds(), ComputationStepsComputer::ProcessComponentStep(), and ComputationStepsComputer::ProcessInputOrOutputStep().
locations_ is a map from cindex_id to the pair of indexes into steps_ where that cindex_id resides, so if (*locations_)[c] = (i,j), then (*steps_)[i][j] == c.
This is also an output (we get the pointer in the constructor).
Definition at line 550 of file nnet-computation-graph.h.
Referenced by ComputationStepsComputer::AddStep(), ComputationStepsComputer::Check(), ComputationStepsComputer::ComputationStepsComputer(), ComputationStepsComputer::ConvertToLocations(), and ComputationStepsComputer::ProcessInputOrOutputStep().
|
private |
|
private |
steps_ is a pointer to an output that's passed in in the constructor.
Definition at line 545 of file nnet-computation-graph.h.
Referenced by ComputationStepsComputer::AddStep(), ComputationStepsComputer::Check(), and ComputationStepsComputer::ComputationStepsComputer().