boost recycle per thread for QueueItem

This commit is contained in:
Hieu Hoang 2015-12-08 18:18:44 +00:00
parent dd040ea3b3
commit 06ca9e3158
4 changed files with 20 additions and 11 deletions

View File

@ -8,6 +8,7 @@
#include "Misc.h"
#include "../Manager.h"
#include "../../MemPool.h"
#include "../../TranslationTask.h"
using namespace std;
@ -82,20 +83,20 @@ void CubeEdge::CreateFirst(Manager &mgr, Queue &queue, SeenPositions &seenPositi
assert(hypos.size());
assert(tps.GetSize());
MemPool &pool = mgr.GetPool();
boost::object_pool<NSCubePruning::QueueItem> &pool = mgr.task.poolQueueItem;
QueueItem *newEle = new (pool.Allocate<QueueItem>()) QueueItem(mgr, *this, 0, 0);
QueueItem *newEle = new (pool.malloc()) QueueItem(mgr, *this, 0, 0);
queue.push(newEle);
SetSeenPosition(0, 0, seenPositions);
}
void CubeEdge::CreateNext(Manager &mgr, const QueueItem *ele, Queue &queue, SeenPositions &seenPositions)
{
MemPool &pool = mgr.GetPool();
boost::object_pool<NSCubePruning::QueueItem> &pool = mgr.task.poolQueueItem;
size_t hypoIndex = ele->hypoIndex + 1;
if (hypoIndex < hypos.size() && !SeenPosition(hypoIndex, ele->tpIndex, seenPositions)) {
QueueItem *newEle = new (pool.Allocate<QueueItem>()) QueueItem(mgr, *this, hypoIndex, ele->tpIndex);
QueueItem *newEle = new (pool.malloc()) QueueItem(mgr, *this, hypoIndex, ele->tpIndex);
queue.push(newEle);
SetSeenPosition(hypoIndex, ele->tpIndex, seenPositions);
@ -103,7 +104,7 @@ void CubeEdge::CreateNext(Manager &mgr, const QueueItem *ele, Queue &queue, Seen
size_t tpIndex = ele->tpIndex + 1;
if (tpIndex < tps.GetSize() && !SeenPosition(ele->hypoIndex, tpIndex, seenPositions)) {
QueueItem *newEle = new (pool.Allocate<QueueItem>()) QueueItem(mgr, *this, ele->hypoIndex, tpIndex);
QueueItem *newEle = new (pool.malloc()) QueueItem(mgr, *this, ele->hypoIndex, tpIndex);
queue.push(newEle);
SetSeenPosition(ele->hypoIndex, tpIndex, seenPositions);

View File

@ -25,13 +25,13 @@ class CubeEdge;
///////////////////////////////////////////
class QueueItem
{
~QueueItem(); // NOT IMPLEMENTED. Use MemPool
public:
QueueItem(Manager &mgr, CubeEdge &edge, size_t hypoIndex, size_t tpIndex);
CubeEdge &edge;
size_t hypoIndex, tpIndex;
Hypothesis *hypo;
~QueueItem() {}
protected:
void CreateHypothesis(Manager &mgr);
};
@ -70,6 +70,8 @@ public:
const TargetPhrases &tps,
const Bitmap &newBitmap);
~CubeEdge() {}
bool SeenPosition(const size_t x, const size_t y, SeenPositions &seenPositions) const;
void SetSeenPosition(const size_t x, const size_t y, SeenPositions &seenPositions) const;
@ -79,6 +81,7 @@ public:
protected:
private:
};

View File

@ -100,22 +100,26 @@ void Search::Decode(size_t stackInd)
while (!m_queue.empty() && pops < m_mgr.system.popLimit) {
// get best hypo from queue, add to stack
//cerr << "queue=" << queue.size() << endl;
QueueItem *ele = m_queue.top();
QueueItem *item = m_queue.top();
m_queue.pop();
Hypothesis *hypo = ele->hypo;
Hypothesis *hypo = item->hypo;
//cerr << "hypo=" << *hypo << " " << hypo->GetBitmap() << endl;
m_stacks.Add(hypo, m_mgr.GetHypoRecycle());
CubeEdge &edge = ele->edge;
edge.CreateNext(m_mgr, ele, m_queue, m_seenPositions);
CubeEdge &edge = item->edge;
edge.CreateNext(m_mgr, item, m_queue, m_seenPositions);
m_mgr.task.poolQueueItem.free(item);
++pops;
}
//m_mgr.task.poolQueueItem;
BOOST_FOREACH(CubeEdge *edge, edges) {
//cerr << "edge=" << *edge << endl;
m_mgr.task.poolCubeEdge.destroy(edge);
m_mgr.task.poolCubeEdge.free(edge);
}
}

View File

@ -11,6 +11,7 @@ class TranslationTask : public Task
{
public:
mutable boost::object_pool<NSCubePruning::CubeEdge> poolCubeEdge;
mutable boost::object_pool<NSCubePruning::QueueItem> poolQueueItem;
TranslationTask(System &system, const std::string &line);
virtual ~TranslationTask();