20 #ifndef KALDI_NNET3_NNET_OPTIMIZE_UTILS_H_ 21 #define KALDI_NNET3_NNET_OPTIMIZE_UTILS_H_ 33 struct NnetOptimizeOptions;
229 int32 min_deriv_time,
230 int32 max_deriv_time,
233 void LimitDerivTimes();
238 void ComputeMatrixPruneInfo();
241 void ComputeSubmatrixMaps();
246 void ModifyCommands();
252 void PruneMatrices();
258 void RemoveUnusedMemos();
266 inline bool CanLimitMatrix(
const Analyzer &analyzer,
267 int32 matrix_index)
const;
272 inline void LimitMatrices(
const std::vector<bool> &will_limit);
302 void ResizeMatrices();
309 inline void GetPruneValues(
int32 initial_submatrix,
312 int32 *right_prune)
const;
317 bool RowIsKept(
int32 submatrix,
318 int32 row_index)
const;
381 int32 min_deriv_time,
382 int32 max_deriv_time,
404 int32 *num_n_values);
431 bool need_debug_info,
495 std::vector<int32*> *submatrix_args);
521 std::vector<int32*> *submatrix_args);
530 std::vector<int32*> *submatrix_args);
537 std::vector<int32*> *indexes_multi_args);
543 std::vector<int32*> *indexes_args);
549 std::vector<int32*> *indexes_args);
555 std::vector<int32*> *indexes_ranges_args);
571 std::vector<std::pair<int32, NnetComputation::Command> > *commands,
593 int32 memory_compression_level,
631 void Read(std::istream &is,
bool binary);
633 void Write(std::ostream &os,
bool binary)
const;
655 void Check(
const Nnet &nnet)
const;
668 typedef std::list<const ComputationRequest*>
AqType;
675 std::pair<std::shared_ptr<const NnetComputation>, AqType::iterator>,
bool MatrixIsUnused(const Analyzer &analyzer, const NnetComputation &computation, int32 m)
This function returns true if matrix 1 <= m < computation->matrices.size() is unused, defined as: it is not an input or an output, and is not accessed other than via commands of type kAllocMatrix, kDeallocMatrix, and kSetConst.
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
This class is responsible for merging matrices, although you probably want to access it via the the f...
std::vector< MatrixPruneInfo > prune_info_
bool SplitRowOps(NnetComputation *computation)
This function detects cases where commands of type kAddRowsMulti, kAddToRowsMulti, kCopyRowsMulti, kCopyToRowsMulti use indexes that correspond to at most two submatrices, in two distinct ranges without gaps filled by -1's, and could be converted to at most two commands of type kMatrixAdd, kMatrixCopy, kAddRows or kCopyRows.
void OptimizeLoopedComputation(const Nnet &nnet, NnetComputation *computation)
This function tries to optimize computation 'computation' for an 'looped' computation.
std::vector< bool > variable_dirty_
void IdentifySubmatrixArgs(NnetComputation::Command *c, std::vector< int32 *> *submatrix_args)
This function outputs to "submatrix_args" the addresses of a subset of arguments arg1 through arg6 in...
void RenumberComputation(NnetComputation *computation)
This function detects submatrices and matrices that are never used (e.g.
void InsertCommands(std::vector< std::pair< int32, NnetComputation::Command > > *new_commands, NnetComputation *computation)
Inserts commands into the computation at the requested places.
std::vector< int32 > submatrix_map_if_deriv_
std::vector< int32 > whole_submatrices_
void IdentifySubmatrixArgsInComputation(NnetComputation *computation, std::vector< int32 *> *submatrix_args)
This function outputs to "submatrix_args" the addresses of integers in 'computation' that correspond ...
This file contains utilities for analyzing and checking computations, which are used in the optimizat...
bool RequestIsDecomposable(const ComputationRequest &request, ComputationRequest *mini_request, int32 *num_n_values)
This function, used in 'shortcut' compilation where we first compile a smaller computation with the s...
NnetComputation * computation_
void ExtendMatrices(NnetComputation *computation)
This is not really an optimization in itself but it can make things easier for class VariableMergingO...
void LimitDerivativeTimes(const Nnet &nnet, int32 min_deriv_time, int32 max_deriv_time, NnetComputation *computation)
void OptimizeMemoryCompression(const Nnet &nnet, int32 memory_compression_level, NnetComputation *computation)
Performs optimization to reduce memory usage where possible, making use of the kCompressMatrix and kD...
void DoMerge(int32 command_index, int32 s_to_keep, int32 m_to_discard)
int32 MaxOutputTimeInRequest(const ComputationRequest &request)
std::vector< MatrixPruneInfo > matrix_prune_info_
const NnetOptimizeOptions & config_
std::vector< std::vector< int32 > > matrix_to_submatrix_
void IdentifyIndexesMultiArgs(std::vector< NnetComputation::Command > *commands, std::vector< int32 *> *indexes_multi_args)
Identifies in the vector of commands, arguments that correspond to indexes into the computation's ind...
std::unordered_set< int32 > memos_to_delete_
NnetComputation * computation_
bool ReplaceRowWithMatrixOps(NnetComputation *computation)
This function detects cases where commands of type kCopyRows, kAddRows or kAddToRows can be converted...
void FixGotoLabel(NnetComputation *computation)
This function ensures that the arg1 of a final command of type kGotoLabel is the same as the command ...
unordered_map< const ComputationRequest *, std::pair< std::shared_ptr< const NnetComputation >, AqType::iterator >, ComputationRequestHasher, ComputationRequestPtrEqual > CacheType
void ExpandComputation(const Nnet &nnet, const MiscComputationInfo &misc_info, const NnetComputation &computation, bool need_debug_info, int32 num_n_values, NnetComputation *expanded_computation)
This function is used in 'shortcut' compilation to expand a computation that has been compiled for ex...
void ConsolidateModelUpdate(const Nnet &nnet, NnetComputation *computation)
This optimization consolidates the model-update part of backprop commands, for components in (e...
CacheType computation_cache_
void MarkAsDirty(int32 s)
Marks the variables underlying submatrix 's' as dirty.
VariableMergingOptimizer(const NnetOptimizeOptions &config, const Nnet &nnet, NnetComputation *computation)
void RemoveNoOps(NnetComputation *computation)
Removes commands of type kNoOperation in the computation.
void IdentifyIndexesRangesArgs(std::vector< NnetComputation::Command > *commands, std::vector< int32 *> *indexes_ranges_args)
Identifies in the vector of commands, arguments that correspond to indexes into the computation's 'in...
void RemoveCommandsForUnusedMatrix(const Analyzer &analyzer, int32 m, NnetComputation *computation)
This function removes from 'computation' the commands accessing matrix 'm', which is assumed to be un...
std::vector< int32 > submatrix_map_
std::list< const ComputationRequest * > AqType
bool already_called_merge_variables_
bool SnipRowOps(NnetComputation *computation)
This function detects cases where commands of type kCopyRows, kAddRows, kAddRowsMulti, kAddToRowsMulti, kCopyRowsMulti, kCopyToRowsMulti or kAddRowRanges use indexes that start or end with -1's or equivalents, and replace them with similar commands that act on a sub-matrix of the matrices they are currently acting on.
Class ComputationCache is used inside class CachingOptimizingCompiler to cache previously computed co...
void IdentifyIndexesArgs(std::vector< NnetComputation::Command > *commands, std::vector< int32 *> *indexes_args)
Identifies in the vector of commands, arguments that correspond to indexes into the computation's 'in...
This struct exists to set up various pieces of analysis; it helps avoid the repetition of code where ...
std::pair< bool, bool > MayBeMerged(int32 command, int32 s1, int32 s2) const
This function returns a pair of bools saying whether we can do a (left and/or right) merge respective...