20 #ifndef KALDI_NNET3_NNET_ANALYZE_H_ 21 #define KALDI_NNET3_NNET_ANALYZE_H_ 72 const std::vector<CommandAttributes> &attributes);
136 void RecordAccessForSubmatrix(
137 int32 submatrix_index,
143 void AppendVariablesForMatrix(
145 std::vector<int32> *variable_indexes)
const;
150 void AppendVariablesForSubmatrix(
151 int32 submatrix_index,
152 std::vector<int32> *variable_indexes)
const;
157 int32 GetMatrixForVariable(
int32 variable)
const;
161 std::string DescribeVariable(
int32 variable)
const;
172 void ComputeVariableToMatrix();
177 static int32 FindIndexOf(
const std::vector<int32> &sorted_vec,
int32 i);
225 command_index(command_index), access_type(access_type) { }
245 const std::vector<CommandAttributes> &command_attributes,
246 std::vector<std::vector<Access> > *variable_accesses);
272 is_input(false), is_output(false) { }
285 const std::vector<CommandAttributes> &command_attributes,
286 std::vector<MatrixAccesses> *matrix_accesses);
290 const std::vector<MatrixAccesses> &matrix_accesses);
314 const Analyzer &analyzer): computation_(computation),
315 analyzer_(analyzer) { }
355 int32 FirstNontrivialMatrixAccess(
int32 m)
const;
373 std::vector<std::vector<int32> > *mat_to_submat);
388 std::vector<CommandAttributes> *attributes);
403 check_rewrite(false), check_unused_variables(true) { }
419 void CheckComputationIndexes()
const;
421 void CheckComputationUndefined()
const;
423 void CheckComputationRewrite()
const;
425 void CheckComputationMatrixAccesses()
const;
427 void CheckComputationCompression()
const;
429 void CheckComputationDebugInfo()
const;
442 std::vector<int32> *command_indexes);
450 bool check_rewrite =
false);
CommandType
CommandType is an enum that describes the category of the command used in the NnetComputation.
This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
void GetCommandsOfType(const NnetComputation &computation, CommandType t, std::vector< int32 > *command_indexes)
This utility function works out from a computation, the command-indexes of the commands of the given ...
int32 MaxMemoryUsage(const NnetComputation &computation)
Returns the total memory, in bytes, used by the computation (just the temporary memory, not counting the memory used by the nnet itself).
void PrintMatrixAccesses(std::ostream &os, const std::vector< MatrixAccesses > &matrix_accesses)
This function is to be used in debugging; it produces human-readable output.
ComputationAnalysis(const NnetComputation &computation, const Analyzer &analyzer)
This class stores the const references provided to its constructor -> be careful about changing them ...
const Analyzer & analyzer_
bool is_output
true if this matrix is an output of the computation (i.e.
void PrintCommandAttributes(std::ostream &os, const std::vector< CommandAttributes > &attributes)
This function is to be used in debugging; it produces human-readable output.
std::vector< int32 > submatrix_to_matrix_
void ComputeCommandAttributes(const Nnet &nnet, const NnetComputation &computation, const ComputationVariables &vars, std::vector< CommandAttributes > *attributes)
std::vector< CommandAttributes > command_attributes
const NnetComputation & computation_
std::vector< int32 > submatrices_written
std::vector< Access > accesses
Records the indexes of commands that access the matrix, and the type (read, read/write, write).
std::vector< int32 > matrices_read
std::vector< std::vector< int32 > > row_split_points_
std::vector< int32 > variables_written
std::vector< std::vector< int32 > > variables_for_submatrix_
int64 GetMaxMemoryUse(const NnetComputation &computation)
This class relates the matrices and sub-matrices in the computation to imaginary "variables", such that we can think of the operations as operating on sets of individual variables, and we can then do analysis that lets us do optimization.
std::vector< int32 > variable_to_matrix_
std::vector< int32 > matrix_to_variable_index_
int32 NumVariables() const
void ComputeVariableAccesses(const ComputationVariables &variables, const std::vector< CommandAttributes > &command_attributes, std::vector< std::vector< Access > > *variable_accesses)
After the command-level attributes have been computed, this function organizes them per variable (see...
const CheckComputationOptions & config_
Access(int32 command_index, AccessType access_type)
std::vector< std::vector< Access > > variable_accesses
std::vector< std::vector< int32 > > column_split_points_
int32 deallocate_command
Index of the command that deallocates the matrix (which will be of type kDeallocMatrix or kSwapMatrix...
std::vector< int32 > submatrices_read
bool check_unused_variables
std::vector< int32 > matrices_written
bool operator<(const Int32Pair &a, const Int32Pair &b)
CheckComputationOptions()
const NnetComputation & computation_
void ComputeMatrixToSubmatrix(const NnetComputation &computation, std::vector< std::vector< int32 > > *mat_to_submat)
This function computes a vector 'mat_to_submat', indexed by matrix index, such that (*mat_to_submat)[...
void ComputeMatrixAccesses(const Nnet &nnet, const NnetComputation &computation, const ComputationVariables &variables, const std::vector< CommandAttributes > &command_attributes, std::vector< MatrixAccesses > *matrix_accesses)
This function organizes information in the CommandAttributes in a way that is convenient to access pe...
std::vector< MatrixAccesses > matrix_accesses
void CheckComputation(const Nnet &nnet, const NnetComputation &computation, bool check_rewrite)
This is a convenience interface for class ComputationChecker.
int32 allocate_command
Index of the command that allocates the matrix (which will be of type kAllocMatrix or kSwapMatrix)...
bool is_input
true if this matrix is an input to the computation (i.e.
std::vector< int32 > variables_read
ComputationVariables variables
std::vector< bool > submatrix_is_whole_matrix_
This struct exists to set up various pieces of analysis; it helps avoid the repetition of code where ...
This class performs various kinds of specific analysis on top of what class Analyzer gives you immedi...