reuse Batch

This commit is contained in:
Hieu Hoang 2016-05-10 15:33:07 +01:00
parent 9063ccd14e
commit d9b2855cdd
4 changed files with 20 additions and 6 deletions

View File

@ -28,7 +28,7 @@ namespace NSBatch
Search::Search(Manager &mgr)
:Moses2::Search(mgr)
, m_stacks(mgr)
, m_batch(mgr.GetPool())
, m_batch(mgr.system.GetBatch(mgr.GetSystemPool()))
{
// TODO Auto-generated constructor stub

View File

@ -40,7 +40,7 @@ public:
protected:
Stacks m_stacks;
Batch m_batch;
Batch &m_batch;
void Decode(size_t stackInd);
void Extend(const Hypothesis &hypo, const InputPath &path);

View File

@ -95,14 +95,12 @@ void System::LoadMappings()
MemPool &System::GetSystemPool() const
{
MemPool &ret = GetThreadSpecificObj(m_systemPool);
return ret;
return GetThreadSpecificObj(m_systemPool);
}
MemPool &System::GetManagerPool() const
{
MemPool &ret = GetThreadSpecificObj(m_managerPool);
return ret;
return GetThreadSpecificObj(m_managerPool);
}
FactorCollection &System::GetVocab() const
@ -115,6 +113,18 @@ Recycler<HypothesisBase*> &System::GetHypoRecycler() const
return GetThreadSpecificObj(m_hypoRecycler);
}
Batch &System::GetBatch(MemPool &pool) const
{
Batch *obj;
obj = m_batch.get();
if (obj == NULL) {
obj = new Batch(pool);
m_batch.reset(obj);
}
assert(obj);
return *obj;
}
void System::IsPb()
{
switch (options.search.algo) {

View File

@ -59,6 +59,8 @@ public:
Recycler<HypothesisBase*> &GetHypoRecycler() const;
Batch &GetBatch(MemPool &pool) const;
protected:
mutable FactorCollection m_vocab;
mutable boost::thread_specific_ptr<MemPool> m_managerPool;
@ -66,6 +68,8 @@ protected:
mutable boost::thread_specific_ptr<Recycler<HypothesisBase*> > m_hypoRecycler;
mutable boost::thread_specific_ptr<Batch> m_batch;
void LoadWeights();
void LoadMappings();