use manager pool instead of system pool. Get ready for thread-safe

This commit is contained in:
Hieu Hoang 2020-10-05 15:26:20 -07:00
parent cd18c7aa79
commit dd638e16f5
6 changed files with 15 additions and 24 deletions

View File

@ -96,7 +96,7 @@ public:
const SCFG::TargetPhrases &tps, const Phrase<SCFG::Word> &sourcePhrase) const {
}
virtual void InitializeForInput(const System &system, const InputType &input) { };
virtual void InitializeForInput(const ManagerBase &mgr, const InputType &input) { };
// clean up temporary memory, called after processing each sentence
virtual void CleanUpAfterSentenceProcessing(const System &system, const InputType &input) const {

View File

@ -229,10 +229,10 @@ void FeatureFunctions::EvaluateWhenAppliedBatch(const Batch &batch) const
}
}
void FeatureFunctions::InitializeForInput(const InputType &input)
void FeatureFunctions::InitializeForInput(const ManagerBase &mgr, const InputType &input)
{
BOOST_FOREACH(FeatureFunction *ff, m_featureFunctions) {
ff->InitializeForInput(m_system, input);
ff->InitializeForInput(mgr, input);
}
}

View File

@ -87,7 +87,7 @@ public:
void EvaluateWhenAppliedBatch(const Batch &batch) const;
void InitializeForInput(const InputType &input);
void InitializeForInput(const ManagerBase &mgr, const InputType &input);
void CleanUpAfterSentenceProcessing(const InputType &input) const;
void ShowWeights(const Weights &allWeights);

View File

@ -63,7 +63,7 @@ void Manager::Init()
//TODO: need option to choose Sentence vs SentenceWithCandidates
m_input = Moses2::SentenceWithCandidates::CreateFromString(GetPool(), vocab, system, m_inputStr);
//cerr << "Manager::Init: " << m_input->Debug(system) << endl << flush;
system.featureFunctions.InitializeForInput(*m_input);
system.featureFunctions.InitializeForInput(*this, *m_input);
m_bitmaps = new Bitmaps(GetPool());

View File

@ -52,12 +52,13 @@ MSPT::~MSPT()
delete m_rootPb;
}
void MSPT::CreatePTForInput(const System &system, string phraseTableString)
void MSPT::CreatePTForInput(const ManagerBase &mgr, string phraseTableString)
{
//cerr << "In CreatePTForInput" << endl << flush;
const System &system = mgr.system;
FactorCollection &vocab = system.GetVocab();
MemPool &systemPool = system.GetSystemPool();
MemPool &pool = mgr.GetPool();
MemPool tmpSourcePool;
if (system.isPb) {
@ -85,7 +86,7 @@ void MSPT::CreatePTForInput(const System &system, string phraseTableString)
PhraseImpl *source = PhraseImpl::CreateFromString(tmpSourcePool, vocab, system,
toks[0]);
//cerr << "created soure" << endl;
TargetPhraseImpl *target = TargetPhraseImpl::CreateFromString(systemPool, *this, system,
TargetPhraseImpl *target = TargetPhraseImpl::CreateFromString(pool, *this, system,
toks[1]);
//cerr << "created target" << endl;
target->GetScores().CreateFromString(toks[2], *this, system, true);
@ -102,7 +103,7 @@ void MSPT::CreatePTForInput(const System &system, string phraseTableString)
//strcpy(target->properties, toks[6].c_str());
}
system.featureFunctions.EvaluateInIsolation(systemPool, system, *source,
system.featureFunctions.EvaluateInIsolation(pool, system, *source,
*target);
//cerr << "EvaluateInIsolation:" << target->Debug(system) << endl;
m_rootPb->AddRule(m_input, *source, target);
@ -114,7 +115,7 @@ void MSPT::CreatePTForInput(const System &system, string phraseTableString)
}
if (system.isPb) {
m_rootPb->SortAndPrune(m_tableLimit, systemPool, system);
m_rootPb->SortAndPrune(m_tableLimit, pool, system);
//cerr << "root=" << &m_rootPb << endl;
} else {
abort();
@ -129,21 +130,11 @@ void MSPT::CreatePTForInput(const System &system, string phraseTableString)
}
void MSPT::InitializeForInput(const System &system, const InputType &input)
void MSPT::InitializeForInput(const ManagerBase &mgr, const InputType &input)
{
//cerr << "InitializeForInput MSPT" << endl;
//cerr << input.Debug(system) << endl;
//cerr << "HH1" << endl << flush;
// downcast to SentenceWithCandidates
const SentenceWithCandidates &inputObj = static_cast<const SentenceWithCandidates&>(input);
//const SentenceWithCandidates &inputObj = dynamic_cast<const SentenceWithCandidates&>(input);
//cerr << "Casting done." << endl << flush;
//cerr << "PhraseTableString member: " << inputObj.getPhraseTableString() << endl << flush;
//cerr << "HH2" << endl << flush;
CreatePTForInput(system, inputObj.getPhraseTableString());
//cerr << "HH3" << endl << flush;
CreatePTForInput(mgr, inputObj.getPhraseTableString());
}
TargetPhrases* MSPT::Lookup(const Manager &mgr, MemPool &pool,

View File

@ -65,7 +65,7 @@ public:
const SCFG::Stacks &stacks,
SCFG::InputPath &path) const;
virtual void InitializeForInput(const System &system, const InputType &input);
virtual void InitializeForInput(const ManagerBase &mgr, const InputType &input);
protected:
PBNODE *m_rootPb;
@ -79,7 +79,7 @@ protected:
const Moses2::Range &subPhraseRange,
SCFG::InputPath &outPath) const;
void CreatePTForInput(const System &system, std::string phraseTableString);
void CreatePTForInput(const ManagerBase &mgr, std::string phraseTableString);
};