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

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

Collaboration diagram for DiscriminativeExamplesRepository:

Public Member Functions

void AcceptExample (const DiscriminativeNnetExample &example)
 The following function is called by the code that reads in the examples. More...
 
void ExamplesDone ()
 The following function is called by the code that reads in the examples, when we're done reading examples; it signals this way to this class that the stream is now empty. More...
 
DiscriminativeNnetExampleProvideExample ()
 This function is called by the code that does the training. More...
 
 DiscriminativeExamplesRepository ()
 

Private Member Functions

 KALDI_DISALLOW_COPY_AND_ASSIGN (DiscriminativeExamplesRepository)
 

Private Attributes

int32 buffer_size_
 
Semaphore full_semaphore_
 
Semaphore empty_semaphore_
 
std::mutex examples_mutex_
 
std::deque
< DiscriminativeNnetExample * > 
examples_
 
bool done_
 

Detailed Description

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

Definition at line 33 of file nnet-compute-discriminative-parallel.cc.

Constructor & Destructor Documentation

Member Function Documentation

void AcceptExample ( const DiscriminativeNnetExample example)
void ExamplesDone ( )

The following function is called by the code that reads in the examples, when we're done reading examples; it signals this way to this class that the stream is now empty.

Definition at line 73 of file nnet-compute-discriminative-parallel.cc.

References DiscriminativeExamplesRepository::buffer_size_, DiscriminativeExamplesRepository::done_, DiscriminativeExamplesRepository::empty_semaphore_, DiscriminativeExamplesRepository::examples_, DiscriminativeExamplesRepository::examples_mutex_, DiscriminativeExamplesRepository::full_semaphore_, rnnlm::i, KALDI_ASSERT, Semaphore::Signal(), and Semaphore::Wait().

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

KALDI_DISALLOW_COPY_AND_ASSIGN ( DiscriminativeExamplesRepository  )
private
DiscriminativeNnetExample * ProvideExample ( )

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

If there is an example available it will provide it, or it will sleep till one is available. It returns NULL when there are no examples left and ExamplesDone() has been called.

Definition at line 84 of file nnet-compute-discriminative-parallel.cc.

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

Referenced by DiscTrainParallelClass::operator()().

84  {
86  if (done_) {
87  KALDI_ASSERT(examples_.empty());
88  full_semaphore_.Signal(); // Increment the semaphore so
89  // the call by the next thread will not block.
90  return NULL; // no examples to return-- all finished.
91  } else {
92  examples_mutex_.lock();
93  KALDI_ASSERT(!examples_.empty());
94  DiscriminativeNnetExample *ans = examples_.front();
95  examples_.pop_front();
96  examples_mutex_.unlock();
98  return ans;
99  }
100 }
void Signal()
increase the counter
#define KALDI_ASSERT(cond)
Definition: kaldi-error.h:169
void Wait()
decrease the counter

Member Data Documentation

int32 buffer_size_
private

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