Commit 14d3d492 authored by Alberto Gonzalez's avatar Alberto Gonzalez

Commit 1 concept fork

parent abde05fe
...@@ -57,6 +57,16 @@ ...@@ -57,6 +57,16 @@
#include <chrono> #include <chrono>
//END ALBERTO //END ALBERTO
//ALBERTO CONCEPT FORK
#include <iostream>
#include <vector>
#include <semaphore.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/wait.h>
#include <unistd.h>
//END ALBERTO CONCEPT FORK
//! \ingroup EncoderLib //! \ingroup EncoderLib
//! \{ //! \{
...@@ -65,6 +75,17 @@ ...@@ -65,6 +75,17 @@
int EncCu::iter = 0; int EncCu::iter = 0;
//END ALBERTO //END ALBERTO
//ALBERTO CONCEPT FORK
struct vectorModeCostStruct {
int mode;
double cost;
};
const int VECTOR_SIZE = 1 << 10; // 4^10
const int VECTOR_BYTES = VECTOR_SIZE * sizeof(int);
sem_t* sem;
vectorModeCostStruct* vector;
//END ALBERTO CONCEPT FORK
// ==================================================================================================================== // ====================================================================================================================
const MergeIdxPair EncCu::m_geoModeTest[GEO_MAX_NUM_CANDS] = { const MergeIdxPair EncCu::m_geoModeTest[GEO_MAX_NUM_CANDS] = {
...@@ -261,91 +282,115 @@ void EncCu::init( EncLib* pcEncLib, const SPS& sps ) ...@@ -261,91 +282,115 @@ void EncCu::init( EncLib* pcEncLib, const SPS& sps )
void EncCu::compressCtu(CodingStructure &cs, const UnitArea &area, const unsigned ctuRsAddr, const EnumArray<int, ChannelType> &prevQP, const EnumArray<int, ChannelType> &currQP) void EncCu::compressCtu(CodingStructure &cs, const UnitArea &area, const unsigned ctuRsAddr, const EnumArray<int, ChannelType> &prevQP, const EnumArray<int, ChannelType> &currQP)
{ {
m_modeCtrl->initCTUEncoding( *cs.slice ); //ALBERTO CONCEPT FORK
cs.treeType = TREE_D; // Crear memoria compartida para el vector y el semáforo
int fd = shm_open("/myshm", O_CREAT | O_RDWR, 0666);
cs.slice->m_mapPltCost[0].clear(); ftruncate(fd, VECTOR_BYTES + sizeof(sem_t));
cs.slice->m_mapPltCost[1].clear(); vector = (vectorModeCostStruct*) mmap(NULL, VECTOR_BYTES, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
// init the partitioning manager sem = (sem_t*) (vector + VECTOR_SIZE);
QTBTPartitioner partitioner; sem_init(sem, 1, 1);
partitioner.initCtu(area, ChannelType::LUMA, *cs.slice);
if (m_pcEncCfg->getIBCMode()) for (int i = 0; i < VECTOR_SIZE; i++) {
{ pid_t pid = fork();
if (area.lx() == 0 && area.ly() == 0) if (pid == 0) { // proceso hijo
{ // acceder al vector en la posición i
m_pcInterSearch->resetIbcSearch(); sem_wait(sem);
} vectorModeCostStruct structura;
m_pcInterSearch->resetCtuRecord(); vector[i] = structura;
m_ctuIbcSearchRangeX = m_pcEncCfg->getIBCLocalSearchRangeX(); sem_post(sem);
m_ctuIbcSearchRangeY = m_pcEncCfg->getIBCLocalSearchRangeY(); //END ALBERTO CONCEPT FORK
} m_modeCtrl->initCTUEncoding( *cs.slice );
if (m_pcEncCfg->getIBCMode() && m_pcEncCfg->getIBCHashSearch() && (m_pcEncCfg->getIBCFastMethod() & IBC_FAST_METHOD_ADAPTIVE_SEARCHRANGE)) cs.treeType = TREE_D;
{
const int hashHitRatio = m_ibcHashMap.getHashHitRatio(area.Y()); // in percent cs.slice->m_mapPltCost[0].clear();
if (hashHitRatio < 5) // 5% cs.slice->m_mapPltCost[1].clear();
{ // init the partitioning manager
m_ctuIbcSearchRangeX >>= 1; QTBTPartitioner partitioner;
m_ctuIbcSearchRangeY >>= 1; partitioner.initCtu(area, ChannelType::LUMA, *cs.slice);
} if (m_pcEncCfg->getIBCMode())
if (cs.slice->getNumRefIdx(REF_PIC_LIST_0) > 0) {
{ if (area.lx() == 0 && area.ly() == 0)
m_ctuIbcSearchRangeX >>= 1; {
m_ctuIbcSearchRangeY >>= 1; m_pcInterSearch->resetIbcSearch();
} }
} m_pcInterSearch->resetCtuRecord();
// init current context pointer m_ctuIbcSearchRangeX = m_pcEncCfg->getIBCLocalSearchRangeX();
m_CurrCtx = m_ctxBuffer.data(); m_ctuIbcSearchRangeY = m_pcEncCfg->getIBCLocalSearchRangeY();
}
if (m_pcEncCfg->getIBCMode() && m_pcEncCfg->getIBCHashSearch() && (m_pcEncCfg->getIBCFastMethod() & IBC_FAST_METHOD_ADAPTIVE_SEARCHRANGE))
{
const int hashHitRatio = m_ibcHashMap.getHashHitRatio(area.Y()); // in percent
if (hashHitRatio < 5) // 5%
{
m_ctuIbcSearchRangeX >>= 1;
m_ctuIbcSearchRangeY >>= 1;
}
if (cs.slice->getNumRefIdx(REF_PIC_LIST_0) > 0)
{
m_ctuIbcSearchRangeX >>= 1;
m_ctuIbcSearchRangeY >>= 1;
}
}
// init current context pointer
m_CurrCtx = m_ctxBuffer.data();
CodingStructure *tempCS = m_pTempCS[gp_sizeIdxInfo->idxFrom( area.lumaSize().width )][gp_sizeIdxInfo->idxFrom( area.lumaSize().height )]; CodingStructure *tempCS = m_pTempCS[gp_sizeIdxInfo->idxFrom( area.lumaSize().width )][gp_sizeIdxInfo->idxFrom( area.lumaSize().height )];
CodingStructure *bestCS = m_pBestCS[gp_sizeIdxInfo->idxFrom( area.lumaSize().width )][gp_sizeIdxInfo->idxFrom( area.lumaSize().height )]; CodingStructure *bestCS = m_pBestCS[gp_sizeIdxInfo->idxFrom( area.lumaSize().width )][gp_sizeIdxInfo->idxFrom( area.lumaSize().height )];
cs.initSubStructure(*tempCS, partitioner.chType, partitioner.currArea(), false); cs.initSubStructure(*tempCS, partitioner.chType, partitioner.currArea(), false);
cs.initSubStructure(*bestCS, partitioner.chType, partitioner.currArea(), false); cs.initSubStructure(*bestCS, partitioner.chType, partitioner.currArea(), false);
tempCS->currQP[ChannelType::LUMA] = bestCS->currQP[ChannelType::LUMA] = tempCS->baseQP = bestCS->baseQP = tempCS->currQP[ChannelType::LUMA] = bestCS->currQP[ChannelType::LUMA] = tempCS->baseQP = bestCS->baseQP =
currQP[ChannelType::LUMA]; currQP[ChannelType::LUMA];
tempCS->prevQP[ChannelType::LUMA] = bestCS->prevQP[ChannelType::LUMA] = prevQP[ChannelType::LUMA]; tempCS->prevQP[ChannelType::LUMA] = bestCS->prevQP[ChannelType::LUMA] = prevQP[ChannelType::LUMA];
xCompressCU(tempCS, bestCS, partitioner); xCompressCU(tempCS, bestCS, partitioner);
cs.slice->m_mapPltCost[0].clear(); cs.slice->m_mapPltCost[0].clear();
cs.slice->m_mapPltCost[1].clear(); cs.slice->m_mapPltCost[1].clear();
// all signals were already copied during compression if the CTU was split - at this point only the structures are copied to the top level CS // all signals were already copied during compression if the CTU was split - at this point only the structures are copied to the top level CS
const bool copyUnsplitCTUSignals = bestCS->cus.size() == 1; const bool copyUnsplitCTUSignals = bestCS->cus.size() == 1;
cs.useSubStructure(*bestCS, partitioner.chType, CS::getArea(*bestCS, area, partitioner.chType), copyUnsplitCTUSignals, cs.useSubStructure(*bestCS, partitioner.chType, CS::getArea(*bestCS, area, partitioner.chType), copyUnsplitCTUSignals,
false, false, copyUnsplitCTUSignals, true); false, false, copyUnsplitCTUSignals, true);
if (CS::isDualITree (cs) && isChromaEnabled (cs.pcv->chrFormat)) if (CS::isDualITree (cs) && isChromaEnabled (cs.pcv->chrFormat))
{ {
m_CABACEstimator->getCtx() = m_CurrCtx->start; m_CABACEstimator->getCtx() = m_CurrCtx->start;
partitioner.initCtu(area, ChannelType::CHROMA, *cs.slice); partitioner.initCtu(area, ChannelType::CHROMA, *cs.slice);
cs.initSubStructure(*tempCS, partitioner.chType, partitioner.currArea(), false); cs.initSubStructure(*tempCS, partitioner.chType, partitioner.currArea(), false);
cs.initSubStructure(*bestCS, partitioner.chType, partitioner.currArea(), false); cs.initSubStructure(*bestCS, partitioner.chType, partitioner.currArea(), false);
tempCS->currQP[ChannelType::CHROMA] = bestCS->currQP[ChannelType::CHROMA] = tempCS->baseQP = bestCS->baseQP = tempCS->currQP[ChannelType::CHROMA] = bestCS->currQP[ChannelType::CHROMA] = tempCS->baseQP = bestCS->baseQP =
currQP[ChannelType::CHROMA]; currQP[ChannelType::CHROMA];
tempCS->prevQP[ChannelType::CHROMA] = bestCS->prevQP[ChannelType::CHROMA] = prevQP[ChannelType::CHROMA]; tempCS->prevQP[ChannelType::CHROMA] = bestCS->prevQP[ChannelType::CHROMA] = prevQP[ChannelType::CHROMA];
xCompressCU(tempCS, bestCS, partitioner); xCompressCU(tempCS, bestCS, partitioner);
const bool copyUnsplitCTUSignals = bestCS->cus.size() == 1; const bool copyUnsplitCTUSignals = bestCS->cus.size() == 1;
cs.useSubStructure(*bestCS, partitioner.chType, CS::getArea(*bestCS, area, partitioner.chType), cs.useSubStructure(*bestCS, partitioner.chType, CS::getArea(*bestCS, area, partitioner.chType),
copyUnsplitCTUSignals, false, false, copyUnsplitCTUSignals, true); copyUnsplitCTUSignals, false, false, copyUnsplitCTUSignals, true);
} }
if (m_pcEncCfg->getUseRateCtrl()) if (m_pcEncCfg->getUseRateCtrl())
{ {
(m_pcRateCtrl->getRCPic()->getLCU(ctuRsAddr)).m_actualMSE = (double)bestCS->dist / (double)m_pcRateCtrl->getRCPic()->getLCU(ctuRsAddr).m_numberOfPixel; (m_pcRateCtrl->getRCPic()->getLCU(ctuRsAddr)).m_actualMSE = (double)bestCS->dist / (double)m_pcRateCtrl->getRCPic()->getLCU(ctuRsAddr).m_numberOfPixel;
} }
// reset context states and uninit context pointer // reset context states and uninit context pointer
m_CABACEstimator->getCtx() = m_CurrCtx->start; m_CABACEstimator->getCtx() = m_CurrCtx->start;
m_CurrCtx = 0; m_CurrCtx = 0;
// Ensure that a coding was found // Ensure that a coding was found
// Selected mode's RD-cost must be not MAX_DOUBLE. // Selected mode's RD-cost must be not MAX_DOUBLE.
CHECK( bestCS->cus.empty() , "No possible encoding found" ); CHECK( bestCS->cus.empty() , "No possible encoding found" );
CHECK( bestCS->cus[0]->predMode == NUMBER_OF_PREDICTION_MODES, "No possible encoding found" ); CHECK( bestCS->cus[0]->predMode == NUMBER_OF_PREDICTION_MODES, "No possible encoding found" );
CHECK( bestCS->cost == MAX_DOUBLE , "No possible encoding found" ); CHECK( bestCS->cost == MAX_DOUBLE , "No possible encoding found" );
//ALBERTO CONCEPT FORK
exit(0);
}
}
//END ALBERTO CONCEPT FORK
munmap(vector, VECTOR_BYTES);
shm_unlink("/myshm");
} }
// ==================================================================================================================== // ====================================================================================================================
...@@ -723,6 +768,34 @@ void EncCu::xCompressCU( CodingStructure*& tempCS, CodingStructure*& bestCS, Par ...@@ -723,6 +768,34 @@ void EncCu::xCompressCU( CodingStructure*& tempCS, CodingStructure*& bestCS, Par
m_bestBcwCost.fill(std::numeric_limits<double>::max()); m_bestBcwCost.fill(std::numeric_limits<double>::max());
m_bestBcwIdx.fill(BCW_NUM); m_bestBcwIdx.fill(BCW_NUM);
} }
//ALBERTO CONCEPT FORK
std::cout << "-----------------------------------------------------" << std::endl;
int mode = 5;
int lastMode = m_modeCtrl->currTestMode().type;
/*Se avanza hasta el modo actual requerido por el proceso*/
while (lastMode != mode)
{
std::cout << "Avanzando modo: " << lastMode << ", buscando modo: " << mode << std::endl;
if (lastMode == mode || !(m_modeCtrl->nextMode(*tempCS, partitioner))) //Si se encuntra mode o no hay mas modes salimos del bucle
{
std::cout << "No otros modos" << ", modo reciente: <" << lastMode << ">" << std::endl;
break;
}
lastMode = m_modeCtrl->currTestMode().type;
}
if (lastMode != mode)
{
std::cout << "El proceso que busca el modo " << mode << " NO ha resultado satisfactorio, no se puede aplicar ese modo para CU" << std::endl;
return; //NO SE PUEDE APLICAR MODO PARA ESTA CU
}
else
{
std::cout << "El proceso que busca el modo " << mode << " SI ha resultado satisfactorio" << std::endl;
}
std::cout << "-----------------------------------------------------" << std::endl;
//END ALBERTO CONCEPT FORK
do do
{ {
for (int i = compBegin; i < (compBegin + numComp); i++) for (int i = compBegin; i < (compBegin + numComp); i++)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment