NnetComputation::Command Struct Reference

#include <nnet-computation.h>

Collaboration diagram for NnetComputation::Command:

Public Member Functions

 Command (CommandType command_type=kNoOperationMarker, int32 arg1=-1, int32 arg2=-1, int32 arg3=-1, int32 arg4=-1, int32 arg5=-1, int32 arg6=-1, int32 arg7=-1)
 
 Command (BaseFloat alpha, CommandType command_type=kNoOperationMarker, int32 arg1=-1, int32 arg2=-1, int32 arg3=-1, int32 arg4=-1, int32 arg5=-1, int32 arg6=-1, int32 arg7=-1)
 
void Read (std::istream &istream, bool binary)
 
void Write (std::ostream &ostream, bool binary) const
 

Public Attributes

CommandType command_type
 
BaseFloat alpha
 
int32 arg1
 
int32 arg2
 
int32 arg3
 
int32 arg4
 
int32 arg5
 
int32 arg6
 
int32 arg7
 

Detailed Description

Definition at line 338 of file nnet-computation.h.

Constructor & Destructor Documentation

◆ Command() [1/2]

◆ Command() [2/2]

Member Function Documentation

◆ Read()

void Read ( std::istream &  istream,
bool  binary 
)

Definition at line 236 of file nnet-computation.cc.

References kaldi::nnet3::ExpectToken(), kaldi::nnet3::kAcceptInput, kaldi::nnet3::kAddRowRanges, kaldi::nnet3::kAddRows, kaldi::nnet3::kAddRowsMulti, kaldi::nnet3::kAddToRowsMulti, KALDI_ERR, kaldi::nnet3::kAllocMatrix, kaldi::nnet3::kBackprop, kaldi::nnet3::kBackpropNoModelUpdate, kaldi::nnet3::kCompressMatrix, kaldi::nnet3::kCopyRows, kaldi::nnet3::kCopyRowsMulti, kaldi::nnet3::kCopyToRowsMulti, kaldi::nnet3::kDeallocMatrix, kaldi::nnet3::kDecompressMatrix, kaldi::nnet3::kGotoLabel, kaldi::nnet3::kMatrixAdd, kaldi::nnet3::kMatrixCopy, kaldi::nnet3::kNoOperation, kaldi::nnet3::kNoOperationLabel, kaldi::nnet3::kNoOperationMarker, kaldi::nnet3::kNoOperationPermanent, kaldi::nnet3::kPropagate, kaldi::nnet3::kProvideOutput, kaldi::nnet3::kSetConst, kaldi::nnet3::kSwapMatrix, kaldi::ReadBasicType(), and kaldi::ReadIntegerVector().

236  {
237  ExpectToken(is, binary, "<Cmd>");
238  if (binary) {
239  int32 command_type_int;
240  ReadBasicType(is, binary, &command_type_int);
241  command_type = static_cast<CommandType>(command_type_int);
242  ReadBasicType(is, binary, &alpha);
243  std::vector<int32> args;
244  ReadIntegerVector(is, binary, &args);
245  args.resize(7, -1); // extend with -1's.
246  int32 *dest = &arg1;
247  std::copy(args.begin(), args.end(), dest);
248  } else {
249  // this branch is slow but we don't care much, as we'd normally write in
250  // binary format.
251  std::string command_type_str;
252  getline(is, command_type_str);
253  if (command_type_str == "kAllocMatrix") {
255  } else if (command_type_str == "kDeallocMatrix") {
257  } else if (command_type_str == "kSwapMatrix") {
259  } else if (command_type_str == "kSetConst") {
261  } else if (command_type_str == "kPropagate") {
263  } else if (command_type_str == "kBackprop") {
265  } else if (command_type_str == "kBackpropNoModelUpdate") {
267  } else if (command_type_str == "kMatrixCopy") {
269  } else if (command_type_str == "kMatrixAdd") {
271  } else if (command_type_str == "kCopyRows") {
273  } else if (command_type_str == "kAddRows") {
275  } else if (command_type_str == "kCopyRowsMulti") {
277  } else if (command_type_str == "kCopyToRowsMulti") {
279  } else if (command_type_str == "kAddRowsMulti") {
281  } else if (command_type_str == "kAddToRowsMulti") {
283  } else if (command_type_str == "kAddRowRanges") {
285  } else if (command_type_str == "kCompressMatrix") {
287  } else if (command_type_str == "kDecompressMatrix") {
289  } else if (command_type_str == "kAcceptInput") {
291  } else if (command_type_str == "kProvideOutput") {
293  } else if (command_type_str == "kNoOperation") {
295  } else if (command_type_str == "kNoOperationPermanent") {
297  } else if (command_type_str == "kNoOperationMarker") {
299  } else if (command_type_str == "kNoOperationLabel") {
301  } else if (command_type_str == "kGotoLabel") {
303  } else {
304  KALDI_ERR << "Un-handled command type.";
305  }
306  ExpectToken(is, binary, "<Alpha>");
307  ReadBasicType(is, binary, &alpha);
308  ExpectToken(is, binary, "<Args>");
309  ReadBasicType(is, binary, &arg1);
310  ReadBasicType(is, binary, &arg2);
311  ReadBasicType(is, binary, &arg3);
312  ReadBasicType(is, binary, &arg4);
313  ReadBasicType(is, binary, &arg5);
314  ReadBasicType(is, binary, &arg6);
315  ReadBasicType(is, binary, &arg7);
316  }
317  ExpectToken(is, binary, "</Cmd>");
318 }
CommandType
CommandType is an enum that describes the category of the command used in the NnetComputation.
void ReadBasicType(std::istream &is, bool binary, T *t)
ReadBasicType is the name of the read function for bool, integer types, and floating-point types...
Definition: io-funcs-inl.h:55
kaldi::int32 int32
void ReadIntegerVector(std::istream &is, bool binary, std::vector< T > *v)
Function for reading STL vector of integer types.
Definition: io-funcs-inl.h:232
static void ExpectToken(const std::string &token, const std::string &what_we_are_parsing, const std::string **next_token)
#define KALDI_ERR
Definition: kaldi-error.h:147

◆ Write()

void Write ( std::ostream &  ostream,
bool  binary 
) const

Definition at line 320 of file nnet-computation.cc.

References kaldi::nnet3::kAcceptInput, kaldi::nnet3::kAddRowRanges, kaldi::nnet3::kAddRows, kaldi::nnet3::kAddRowsMulti, kaldi::nnet3::kAddToRowsMulti, KALDI_ERR, kaldi::nnet3::kAllocMatrix, kaldi::nnet3::kBackprop, kaldi::nnet3::kBackpropNoModelUpdate, kaldi::nnet3::kCompressMatrix, kaldi::nnet3::kCopyRows, kaldi::nnet3::kCopyRowsMulti, kaldi::nnet3::kCopyToRowsMulti, kaldi::nnet3::kDeallocMatrix, kaldi::nnet3::kDecompressMatrix, kaldi::nnet3::kGotoLabel, kaldi::nnet3::kMatrixAdd, kaldi::nnet3::kMatrixCopy, kaldi::nnet3::kNoOperation, kaldi::nnet3::kNoOperationLabel, kaldi::nnet3::kNoOperationMarker, kaldi::nnet3::kNoOperationPermanent, kaldi::nnet3::kPropagate, kaldi::nnet3::kProvideOutput, kaldi::nnet3::kSetConst, kaldi::nnet3::kSwapMatrix, kaldi::WriteBasicType(), kaldi::WriteIntegerVector(), and kaldi::WriteToken().

320  {
321  WriteToken(os, binary, "<Cmd>");
322  if (binary) {
323  WriteBasicType(os, binary, static_cast<int32>(command_type));
324  WriteBasicType(os, binary, alpha);
325  std::vector<int32> args;
326  const int32 *src = &arg1;
327  args.insert(args.end(), src, src + 7); // arg1 through arg7.
328  while (!args.empty() && args.back() == -1)
329  args.pop_back();
330  WriteIntegerVector(os, binary, args);
331  } else {
332  std::string command_type_str;
333  switch (command_type) {
334  case kAllocMatrix:
335  os << "kAllocMatrix\n";
336  break;
337  case kDeallocMatrix:
338  os << "kDeallocMatrix\n";
339  break;
340  case kSwapMatrix:
341  os << "kSwapMatrix\n";
342  break;
343  case kSetConst:
344  os << "kSetConst\n";
345  break;
346  case kPropagate:
347  os << "kPropagate\n";
348  break;
349  case kBackprop:
350  os << "kBackprop\n";
351  break;
353  os << "kBackpropNoModelUpdate\n";
354  break;
355  case kMatrixCopy:
356  os << "kMatrixCopy\n";
357  break;
358  case kMatrixAdd:
359  os << "kMatrixAdd\n";
360  break;
361  case kCopyRows:
362  os << "kCopyRows\n";
363  break;
364  case kAddRows:
365  os << "kAddRows\n";
366  break;
367  case kCopyRowsMulti:
368  os << "kCopyRowsMulti\n";
369  break;
370  case kCopyToRowsMulti:
371  os << "kCopyToRowsMulti\n";
372  break;
373  case kAddRowsMulti:
374  os << "kAddRowsMulti\n";
375  break;
376  case kAddToRowsMulti:
377  os << "kAddToRowsMulti\n";
378  break;
379  case kAddRowRanges:
380  os << "kAddRowRanges\n";
381  break;
382  case kCompressMatrix:
383  os << "kCompressMatrix\n";
384  break;
385  case kDecompressMatrix:
386  os << "kDecompressMatrix\n";
387  break;
388  case kAcceptInput:
389  os << "kAcceptInput\n";
390  break;
391  case kProvideOutput:
392  os << "kProvideOutput\n";
393  break;
394  case kNoOperation:
395  os << "kNoOperation\n";
396  break;
398  os << "kNoOperationPermanent\n";
399  break;
400  case kNoOperationMarker:
401  os << "kNoOperationMarker\n";
402  break;
403  case kNoOperationLabel:
404  os << "kNoOperationLabel\n";
405  break;
406  case kGotoLabel:
407  os << "kGotoLabel\n";
408  break;
409  default:
410  KALDI_ERR << "Un-handled command type.";
411  }
412  os << "<Alpha> " << alpha << " ";
413  os << "<Args> " << arg1 << ' ' << arg2 << ' '
414  << arg3 << ' ' << arg4 << ' ' << arg5 << ' '
415  << arg6 << ' ' << arg7 << ' ';
416  }
417  WriteToken(os, binary, "</Cmd>");
418 }
kaldi::int32 int32
#define KALDI_ERR
Definition: kaldi-error.h:147
void WriteToken(std::ostream &os, bool binary, const char *token)
The WriteToken functions are for writing nonempty sequences of non-space characters.
Definition: io-funcs.cc:134
void WriteIntegerVector(std::ostream &os, bool binary, const std::vector< T > &v)
Function for writing STL vectors of integer types.
Definition: io-funcs-inl.h:198
void WriteBasicType(std::ostream &os, bool binary, T t)
WriteBasicType is the name of the write function for bool, integer types, and floating-point types...
Definition: io-funcs-inl.h:34

Member Data Documentation

◆ alpha

◆ arg1

◆ arg2

◆ arg3

◆ arg4

◆ arg5

◆ arg6

◆ arg7

◆ command_type

CommandType command_type

Definition at line 339 of file nnet-computation.h.

Referenced by ComputationLoopedOptimizer::AddMatrixSwapCommands(), DerivativeTimeLimiter::CanLimitMatrix(), ComputationChecker::CheckComputationCompression(), ComputationChecker::CheckComputationIndexes(), kaldi::nnet3::ComputeCommandAttributes(), ComputationExpander::ComputeCommands(), kaldi::nnet3::ComputeMatrixAccesses(), ComputationExpander::ComputePrecomputedIndexes(), ModelUpdateConsolidator::ConsolidateModelUpdate(), ModelUpdateConsolidator::ConsolidateUpdateForComponent(), kaldi::nnet3::ConvertAdditionToAssignment(), NnetComputer::DebugAfterExecute(), NnetComputer::DebugBeforeExecute(), VariableMergingOptimizer::DoMerge(), NnetComputer::ExecuteCommand(), MatrixExtender::ExtendMatrices(), ComputationAnalysis::FirstNontrivialAccess(), ComputationAnalysis::FirstNontrivialMatrixAccess(), MatrixExtender::FixComputation(), kaldi::nnet3::GetMaxMemoryUse(), kaldi::nnet3::IdentifyIndexesArgs(), kaldi::nnet3::IdentifyIndexesMultiArgs(), kaldi::nnet3::IdentifyIndexesRangesArgs(), kaldi::nnet3::IdentifySubmatrixArgs(), kaldi::nnet3::IsNoop(), DerivativeTimeLimiter::MapAddRowRangesCommand(), DerivativeTimeLimiter::MapIndexesCommand(), DerivativeTimeLimiter::MapIndexesMultiCommand(), DerivativeTimeLimiter::MapSimpleMatrixCommand(), MatrixExtender::MatrixExtender(), kaldi::nnet3::MatrixIsUnused(), VariableMergingOptimizer::MergeVariables(), DerivativeTimeLimiter::ModifyCommand(), kaldi::nnet3::MoveSizingCommands(), kaldi::nnet3::PrintCommand(), MemoryCompressionOptimizer::ProcessMatrix(), kaldi::nnet3::RemoveCommandsForUnusedMatrix(), kaldi::nnet3::RemoveUnnecessaryAllocation(), kaldi::nnet3::RemoveUnnecessaryZeroing(), DerivativeTimeLimiter::RemoveUnusedMemos(), ComputationRenumberer::RenumberMemos(), kaldi::nnet3::ReplaceRowWithMatrixOps(), kaldi::nnet3::SnipRowOps(), and RowOpsSplitter::SplitCommand().


The documentation for this struct was generated from the following files: