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