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()

ExamplesRepository ( )
inline

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

Member Function Documentation

◆ AcceptExamples()

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 KALDI_ASSERT.

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:185
void Wait()
decrease the counter

◆ ExamplesDone()

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 KALDI_ASSERT.

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:185
void Wait()
decrease the counter

◆ KALDI_DISALLOW_COPY_AND_ASSIGN()

KALDI_DISALLOW_COPY_AND_ASSIGN ( ExamplesRepository  )
private

◆ ProvideExamples()

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 KALDI_ASSERT.

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:185
void Wait()
decrease the counter

Member Data Documentation

◆ done_

bool done_
private

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

◆ empty_semaphore_

Semaphore empty_semaphore_
private

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

◆ examples_

std::vector<NnetExample> examples_
private

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

◆ full_semaphore_

Semaphore full_semaphore_
private

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


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