All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ExamplesRepository Class Reference

This class stores neural net training examples to be used in multi-threaded training. More...

#include <nnet-example.h>

Collaboration diagram for ExamplesRepository:

Public Member Functions

void AcceptExamples (std::vector< NnetExample > *examples)
 The following function is called by the code that reads in the examples, with a batch of examples. More...
 
void ExamplesDone ()
 The following function is called by the code that reads in the examples, when we're done reading examples. More...
 
bool ProvideExamples (std::vector< NnetExample > *examples)
 This function is called by the code that does the training. More...
 
 ExamplesRepository ()
 

Private Member Functions

 KALDI_DISALLOW_COPY_AND_ASSIGN (ExamplesRepository)
 

Private Attributes

Semaphore full_semaphore_
 
Semaphore empty_semaphore_
 
std::vector< NnetExampleexamples_
 
bool done_
 

Detailed Description

This class stores neural net training examples to be used in multi-threaded training.

Definition at line 99 of file nnet-example.h.

Constructor & Destructor Documentation

ExamplesRepository ( )
inline

Definition at line 115 of file nnet-example.h.

Member Function Documentation

void AcceptExamples ( std::vector< NnetExample > *  examples)

The following function is called by the code that reads in the examples, with a batch of examples.

[It will empty the vector "examples").

Definition at line 209 of file nnet-example.cc.

References ExamplesRepository::empty_semaphore_, ExamplesRepository::examples_, ExamplesRepository::full_semaphore_, KALDI_ASSERT, Semaphore::Signal(), and Semaphore::Wait().

Referenced by kaldi::nnet2::DoBackpropParallel().

210  {
211  KALDI_ASSERT(!examples->empty());
213  KALDI_ASSERT(examples_.empty());
214  examples_.swap(*examples);
216 }
std::vector< NnetExample > examples_
Definition: nnet-example.h:120
void Signal()
increase the counter
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void Wait()
decrease the counter
void ExamplesDone ( )

The following function is called by the code that reads in the examples, when we're done reading examples.

Definition at line 218 of file nnet-example.cc.

References ExamplesRepository::done_, ExamplesRepository::empty_semaphore_, ExamplesRepository::examples_, ExamplesRepository::full_semaphore_, KALDI_ASSERT, Semaphore::Signal(), and Semaphore::Wait().

Referenced by kaldi::nnet2::DoBackpropParallel().

218  {
220  KALDI_ASSERT(examples_.empty());
221  done_ = true;
223 }
std::vector< NnetExample > examples_
Definition: nnet-example.h:120
void Signal()
increase the counter
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void Wait()
decrease the counter
KALDI_DISALLOW_COPY_AND_ASSIGN ( ExamplesRepository  )
private
bool ProvideExamples ( std::vector< NnetExample > *  examples)

This function is called by the code that does the training.

It gets the training examples, and if they are available, puts them in "examples" and returns true. It returns false when there are no examples left and ExamplesDone() has been called.

Definition at line 225 of file nnet-example.cc.

References ExamplesRepository::done_, ExamplesRepository::empty_semaphore_, ExamplesRepository::examples_, ExamplesRepository::full_semaphore_, KALDI_ASSERT, Semaphore::Signal(), and Semaphore::Wait().

Referenced by DoBackpropParallelClass::operator()().

226  {
228  if (done_) {
229  KALDI_ASSERT(examples_.empty());
230  full_semaphore_.Signal(); // Increment the semaphore so
231  // the call by the next thread will not block.
232  return false; // no examples to return-- all finished.
233  } else {
234  KALDI_ASSERT(!examples_.empty() && examples->empty());
235  examples->swap(examples_);
237  return true;
238  }
239 }
std::vector< NnetExample > examples_
Definition: nnet-example.h:120
void Signal()
increase the counter
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void Wait()
decrease the counter

Member Data Documentation

bool done_
private

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