mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2025-01-05 02:22:21 +03:00
Merge branch 'perf_moses2' of github.com:hieuhoang/mosesdecoder into perf_moses2
This commit is contained in:
commit
51335251c0
@ -165,7 +165,7 @@ void Search::PostDecode(size_t stackInd)
|
||||
CubeEdges &edges = m_cubeEdges[numWords];
|
||||
|
||||
// sort hypo for a particular bitmap and hypoEndPos
|
||||
CubeEdge::Hypotheses &sortedHypos = val.second.GetSortedAndPruneHypos(m_mgr);
|
||||
CubeEdge::Hypotheses &sortedHypos = val.second->GetSortedAndPruneHypos(m_mgr);
|
||||
|
||||
BOOST_FOREACH(const TargetPhrases *tps, path.targetPhrases) {
|
||||
if (tps && tps->GetSize()) {
|
||||
|
@ -19,15 +19,22 @@ namespace Moses2
|
||||
|
||||
namespace NSCubePruning
|
||||
{
|
||||
MiniStack::MiniStack(const Manager &mgr)
|
||||
:m_sortedHypos(NULL)
|
||||
{
|
||||
MemPool &pool = mgr.GetPool();
|
||||
m_coll = new (pool.Allocate<_HCType>()) _HCType(MemPoolAllocator<const Hypothesis*>(pool));
|
||||
}
|
||||
|
||||
CubeEdge::Hypotheses &MiniStack::GetSortedAndPruneHypos(const Manager &mgr) const
|
||||
{
|
||||
if (m_sortedHypos == NULL) {
|
||||
// create sortedHypos first
|
||||
MemPool &pool = mgr.GetPool();
|
||||
m_sortedHypos = new (pool.Allocate< Vector<const Hypothesis*> >()) Vector<const Hypothesis*>(pool, m_coll.size());
|
||||
m_sortedHypos = new (pool.Allocate< Vector<const Hypothesis*> >()) Vector<const Hypothesis*>(pool, m_coll->size());
|
||||
|
||||
size_t ind = 0;
|
||||
BOOST_FOREACH(const Hypothesis *hypo, m_coll) {
|
||||
BOOST_FOREACH(const Hypothesis *hypo, *m_coll) {
|
||||
(*m_sortedHypos)[ind] = hypo;
|
||||
++ind;
|
||||
}
|
||||
@ -81,9 +88,10 @@ void MiniStack::SortAndPruneHypos(const Manager &mgr) const
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
Stack::Stack(const Manager &mgr)
|
||||
:m_mgr(&mgr)
|
||||
{
|
||||
MemPool &pool = mgr.GetPool();
|
||||
m_coll = new (pool.Allocate<Coll>()) Coll(MemPoolAllocator< std::pair<HypoCoverage const, MiniStack> >(pool));
|
||||
m_coll = new (pool.Allocate<Coll>()) Coll(MemPoolAllocator< std::pair<HypoCoverage const, MiniStack*> >(pool));
|
||||
}
|
||||
|
||||
Stack::~Stack()
|
||||
@ -93,7 +101,7 @@ Stack::~Stack()
|
||||
|
||||
void Stack::Add(const Hypothesis *hypo, Recycler<Hypothesis*> &hypoRecycle)
|
||||
{
|
||||
StackAdd added = Add(hypo);
|
||||
StackAdd added = Add2(hypo);
|
||||
|
||||
if (added.toBeDeleted) {
|
||||
hypoRecycle.Add(added.toBeDeleted);
|
||||
@ -101,7 +109,7 @@ void Stack::Add(const Hypothesis *hypo, Recycler<Hypothesis*> &hypoRecycle)
|
||||
|
||||
}
|
||||
|
||||
StackAdd Stack::Add(const Hypothesis *hypo)
|
||||
StackAdd Stack::Add2(const Hypothesis *hypo)
|
||||
{
|
||||
HypoCoverage key(&hypo->GetBitmap(), hypo->GetInputPath().range.GetEndPos());
|
||||
MiniStack::_HCType &innerColl = GetMiniStack(key).GetColl();
|
||||
@ -139,7 +147,7 @@ std::vector<const Hypothesis*> Stack::GetBestHypos(size_t num) const
|
||||
{
|
||||
std::vector<const Hypothesis*> ret;
|
||||
BOOST_FOREACH(const Coll::value_type &val, *m_coll) {
|
||||
const MiniStack::_HCType &hypos = val.second.GetColl();
|
||||
const MiniStack::_HCType &hypos = val.second->GetColl();
|
||||
ret.insert(ret.end(), hypos.begin(), hypos.end());
|
||||
}
|
||||
|
||||
@ -158,7 +166,7 @@ size_t Stack::GetHypoSize() const
|
||||
{
|
||||
size_t ret = 0;
|
||||
BOOST_FOREACH(const Coll::value_type &val, *m_coll) {
|
||||
const MiniStack::_HCType &hypos = val.second.GetColl();
|
||||
const MiniStack::_HCType &hypos = val.second->GetColl();
|
||||
ret += hypos.size();
|
||||
}
|
||||
return ret;
|
||||
@ -166,22 +174,20 @@ size_t Stack::GetHypoSize() const
|
||||
|
||||
MiniStack &Stack::GetMiniStack(const HypoCoverage &key)
|
||||
{
|
||||
/*
|
||||
_HCType *ret;
|
||||
Coll::iterator iter = m_coll.find(key);
|
||||
if (iter == m_coll.end()) {
|
||||
ret = new _HCType();
|
||||
m_coll[key] = ret;
|
||||
MiniStack *ret;
|
||||
Coll::iterator iter = m_coll->find(key);
|
||||
if (iter == m_coll->end()) {
|
||||
MemPool &pool = m_mgr->GetPool();
|
||||
ret = new (pool.Allocate<MiniStack>()) MiniStack(*m_mgr);
|
||||
(*m_coll)[key] = ret;
|
||||
}
|
||||
else {
|
||||
ret = iter->second;
|
||||
}
|
||||
return *ret;
|
||||
*/
|
||||
return (*m_coll)[key];
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace NSCubePruning
|
||||
|
||||
}
|
||||
} //namespace Moses2
|
||||
|
||||
|
@ -28,22 +28,22 @@ class MiniStack
|
||||
public:
|
||||
typedef boost::unordered_set<const Hypothesis*,
|
||||
UnorderedComparer<Hypothesis>,
|
||||
UnorderedComparer<Hypothesis>
|
||||
UnorderedComparer<Hypothesis>,
|
||||
MemPoolAllocator<const Hypothesis*>
|
||||
> _HCType;
|
||||
|
||||
MiniStack()
|
||||
{}
|
||||
MiniStack(const Manager &mgr);
|
||||
|
||||
_HCType &GetColl()
|
||||
{ return m_coll; }
|
||||
{ return *m_coll; }
|
||||
|
||||
const _HCType &GetColl() const
|
||||
{ return m_coll; }
|
||||
{ return *m_coll; }
|
||||
|
||||
CubeEdge::Hypotheses &GetSortedAndPruneHypos(const Manager &mgr) const;
|
||||
|
||||
protected:
|
||||
_HCType m_coll;
|
||||
_HCType *m_coll;
|
||||
mutable CubeEdge::Hypotheses *m_sortedHypos;
|
||||
|
||||
void SortAndPruneHypos(const Manager &mgr) const;
|
||||
@ -59,13 +59,14 @@ public:
|
||||
typedef std::pair<const Bitmap*, size_t> HypoCoverage;
|
||||
// bitmap and current endPos of hypos
|
||||
|
||||
typedef boost::unordered_map<HypoCoverage,
|
||||
MiniStack,
|
||||
typedef boost::unordered_map<const HypoCoverage,
|
||||
MiniStack*,
|
||||
boost::hash<HypoCoverage>,
|
||||
std::equal_to<HypoCoverage>,
|
||||
MemPoolAllocator< std::pair<HypoCoverage const, MiniStack> >
|
||||
MemPoolAllocator< std::pair<HypoCoverage const, MiniStack*> >
|
||||
> Coll;
|
||||
|
||||
const Manager *m_mgr;
|
||||
|
||||
Stack(const Manager &mgr);
|
||||
virtual ~Stack();
|
||||
@ -86,7 +87,8 @@ public:
|
||||
protected:
|
||||
Coll *m_coll;
|
||||
|
||||
StackAdd Add(const Hypothesis *hypo);
|
||||
Stack(); // don't implement
|
||||
StackAdd Add2(const Hypothesis *hypo);
|
||||
|
||||
MiniStack &GetMiniStack(const HypoCoverage &key);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user