diff options
author | Hieu Hoang <hieuhoang@gmail.com> | 2020-10-06 01:26:20 +0300 |
---|---|---|
committer | Hieu Hoang <hieuhoang@gmail.com> | 2020-10-06 01:26:20 +0300 |
commit | dd638e16f5af7ded5b82eb942fec3d06294046d7 (patch) | |
tree | a8f39877573742f9e20871ed2ba1d6873280cfd1 | |
parent | cd18c7aa795db8b0f3e41a8dd52d3e2ba7bcd39d (diff) |
use manager pool instead of system pool. Get ready for thread-safe
-rw-r--r-- | moses2/FF/FeatureFunction.h | 2 | ||||
-rw-r--r-- | moses2/FF/FeatureFunctions.cpp | 4 | ||||
-rw-r--r-- | moses2/FF/FeatureFunctions.h | 2 | ||||
-rw-r--r-- | moses2/PhraseBased/Manager.cpp | 2 | ||||
-rw-r--r-- | moses2/TranslationModel/MSPT/MSPT.cpp | 25 | ||||
-rw-r--r-- | moses2/TranslationModel/MSPT/MSPT.h | 4 |
6 files changed, 15 insertions, 24 deletions
diff --git a/moses2/FF/FeatureFunction.h b/moses2/FF/FeatureFunction.h index 828a712b9..4fa2ee7c3 100644 --- a/moses2/FF/FeatureFunction.h +++ b/moses2/FF/FeatureFunction.h @@ -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 { diff --git a/moses2/FF/FeatureFunctions.cpp b/moses2/FF/FeatureFunctions.cpp index 39e2436b6..c11a2aadf 100644 --- a/moses2/FF/FeatureFunctions.cpp +++ b/moses2/FF/FeatureFunctions.cpp @@ -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); } } diff --git a/moses2/FF/FeatureFunctions.h b/moses2/FF/FeatureFunctions.h index 4c15d674a..43a5793c4 100644 --- a/moses2/FF/FeatureFunctions.h +++ b/moses2/FF/FeatureFunctions.h @@ -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); diff --git a/moses2/PhraseBased/Manager.cpp b/moses2/PhraseBased/Manager.cpp index cce30efb1..83cca53b1 100644 --- a/moses2/PhraseBased/Manager.cpp +++ b/moses2/PhraseBased/Manager.cpp @@ -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()); diff --git a/moses2/TranslationModel/MSPT/MSPT.cpp b/moses2/TranslationModel/MSPT/MSPT.cpp index 88e59324f..eb06fda21 100644 --- a/moses2/TranslationModel/MSPT/MSPT.cpp +++ b/moses2/TranslationModel/MSPT/MSPT.cpp @@ -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, diff --git a/moses2/TranslationModel/MSPT/MSPT.h b/moses2/TranslationModel/MSPT/MSPT.h index e527d9ead..f13fe5847 100644 --- a/moses2/TranslationModel/MSPT/MSPT.h +++ b/moses2/TranslationModel/MSPT/MSPT.h @@ -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); }; |