You need to sign in or sign up before continuing.
Commit f2f3bace authored by Alberto Gonzalez's avatar Alberto Gonzalez

Commit 3 concept fork

```------------------------------------------------------
- Función que completa número threads y número padre en vector.
```

------------------------------------------------------
parent a6dc44a0
...@@ -78,17 +78,35 @@ ...@@ -78,17 +78,35 @@
//END ALBERTO //END ALBERTO
//ALBERTO CONCEPT FORK //ALBERTO CONCEPT FORK
struct vectorModeCostStruct { //bool debugModeForTesting = true;
int mode; //const int THREADS_NUMBER = 4;
double cost; //int nodeId = 0;
};
bool debugModeForTesting = true;
const int VECTOR_SIZE = 341; // NODOS DEL TREE
const int VECTOR_BYTES = VECTOR_SIZE * sizeof(vectorModeCostStruct);
sem_t* sem; sem_t* sem;
vectorModeCostStruct* vector; vectorModeCostStruct* vector;
int nodeId = 0;
std::string posNode; std::string posNode;
void toStringVector()
{
for (int i = 0; i < VECTOR_SIZE; i++) {
std::cout << vector[i].mode;
std::cout << vector[i].cost << std::endl;
}
}
void toStringVector(int Level)
{
int end = 0;
for(int i=Level-1; i>-1; i--)
{
end += pow(4,i);
}
for (int i = 0; i < end; i++) {
std::cout << vector[i].posPadre << ", ";
std::cout << vector[i].threadNumber << std::endl;
}
}
//END ALBERTO CONCEPT FORK //END ALBERTO CONCEPT FORK
// ==================================================================================================================== // ====================================================================================================================
...@@ -176,7 +194,6 @@ void EncCu::create( EncCfg* encCfg ) ...@@ -176,7 +194,6 @@ void EncCu::create( EncCfg* encCfg )
m_CurrCtx = 0; m_CurrCtx = 0;
} }
void EncCu::destroy() void EncCu::destroy()
{ {
unsigned numWidths = gp_sizeIdxInfo->numWidths(); unsigned numWidths = gp_sizeIdxInfo->numWidths();
...@@ -292,23 +309,94 @@ void EncCu::init( EncLib* pcEncLib, const SPS& sps ) ...@@ -292,23 +309,94 @@ void EncCu::init( EncLib* pcEncLib, const SPS& sps )
//ALBERTO CONCEPT FORK //ALBERTO CONCEPT FORK
// Crear memoria compartida para el vector y el semáforo // Crear memoria compartida para el vector y el semáforo
createAndInitSemaphore();
// Inicializar vector de estructuras con valores iniciales de -1
//Estamos en el nivel 0
initStructVector();
toStringVector(5); //IMPRIMIR 5 NIVELES
//Comenzamos en el nodo 0 (único) del nivel 0 de 4
posNode.append("0");
}
void EncCu::createAndInitSemaphore()
{
int fd = shm_open("/myshm", O_CREAT | O_RDWR, 0666); int fd = shm_open("/myshm", O_CREAT | O_RDWR, 0666);
ftruncate(fd, VECTOR_BYTES + sizeof(sem_t)); ftruncate(fd, VECTOR_BYTES + sizeof(sem_t));
vector = (vectorModeCostStruct*) mmap(NULL, VECTOR_BYTES, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); vector = (vectorModeCostStruct*) mmap(NULL, VECTOR_BYTES, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
sem = (sem_t*) (vector + VECTOR_SIZE); sem = (sem_t*) (vector + VECTOR_SIZE);
sem_init(sem,1,1); sem_init(sem,1,1);
}
// Inicializar vector de estructuras con valores iniciales de -1
for (int i = 0; i < VECTOR_SIZE; i++) {
vector[i].mode = -1;
vector[i].cost = -1;
}
//Comenzamos en el nodo 0 (único) del nivel 0 de 4 void EncCu::initStructVector()
posNode.append("0"); {
//END ALBERTO CONCEPT FORK vector[0].posPadre=-1;
vector[0].threadNumber=1;
for (int i = 0; i < VECTOR_SIZE; i++)
{
vector[i].mode=-1;
vector[i].cost=-1;
int posPadreActual = i;
if(posPadreActual==(LEVEL0-1)) //Estamos en el nivel 0, el padre realiza el reparto de threads
{
int salto = 1;
int threadNumber = 1;
int start = posPadreActual+salto;
int end = posPadreActual+salto+4;
for(int j=start; j<end; j++)//Actualizar los 4 hijos
{
vector[j].posPadre=posPadreActual;
vector[j].threadNumber=threadNumber++;
}
}
else if(posPadreActual>=(LEVEL0) && posPadreActual<=(LEVEL1)) //Estamos en el nivel 1
{
updateFatherAndThreadNumbers(0,1,posPadreActual,i);
}
else if(posPadreActual>=(LEVEL1+LEVEL0) && posPadreActual<=(LEVEL2+LEVEL1)) //Estamos en el nivel 2
{
updateFatherAndThreadNumbers(1,2,posPadreActual,i);
}
else if(posPadreActual>=(LEVEL2+LEVEL1+LEVEL0) && posPadreActual<=(LEVEL3+LEVEL2+LEVEL1)) //Estamos en el nivel 3
{
int posPadreEnNivel = i-LEVEL2-LEVEL1-LEVEL0;
int salto = (LEVEL3-posPadreEnNivel)+4*posPadreEnNivel; //Saltos sobre los hermanos derechos del padre + Saltos sobre hijos izquierdos no del padre
int threadNumber = vector[i].threadNumber;
int start = posPadreActual+salto;
int end = posPadreActual+salto+4;
for(int j=start; j<end; j++)//Actualizar los 4 hijos
{
vector[j].posPadre=posPadreActual;
vector[j].threadNumber=threadNumber;
}
updateFatherAndThreadNumbers(2,3,posPadreActual,i);
}
}
} }
void EncCu::updateFatherAndThreadNumbers(int LevelLowIndex, int LevelUpIndex, int posPadreActual, int i)
{
int LevelLow = 0;
int LevelUp = levelValues[LevelUpIndex];
for(int j=LevelLowIndex; j>-1;j--)
{
LevelLow += levelValues[j];
}
int posPadreEnNivel = i-LevelLow;
int salto = (LevelUp-posPadreEnNivel)+4*posPadreEnNivel; //Saltos sobre los hermanos derechos del padre + Saltos sobre hijos izquierdos no del padre
int threadNumber = vector[i].threadNumber;
int start = posPadreActual+salto;
int end = posPadreActual+salto+4;
for(int j=start; j<end; j++)//Actualizar los 4 hijos
{
vector[j].posPadre=posPadreActual;
vector[j].threadNumber=threadNumber;
}
}
//END ALBERTO CONCEPT FORK
// ==================================================================================================================== // ====================================================================================================================
// Public member functions // Public member functions
// ==================================================================================================================== // ====================================================================================================================
...@@ -406,7 +494,7 @@ void EncCu::compressCtuForks(CodingStructure &cs, const UnitArea &area, const un ...@@ -406,7 +494,7 @@ void EncCu::compressCtuForks(CodingStructure &cs, const UnitArea &area, const un
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)
{ {
if(debugModeForTesting) /*if(debugModeForTesting)
{ {
debugModeForTesting = false; debugModeForTesting = false;
vector[4].mode=1; vector[4].mode=1;
...@@ -415,7 +503,7 @@ void EncCu::compressCtu(CodingStructure &cs, const UnitArea &area, const unsigne ...@@ -415,7 +503,7 @@ void EncCu::compressCtu(CodingStructure &cs, const UnitArea &area, const unsigne
else else
{ {
std::cout << vector[4].mode << "== 1?, " << vector[4].cost << "==6?" << std::endl; std::cout << vector[4].mode << "== 1?, " << vector[4].cost << "==6?" << std::endl;
} }*/
//ALBERTO CONCEPT FORK //ALBERTO CONCEPT FORK
for (int i = 0; i < 1; i++) { for (int i = 0; i < 1; i++) {
pid_t pid = fork(); pid_t pid = fork();
...@@ -842,6 +930,7 @@ void EncCu::xCompressCU( CodingStructure*& tempCS, CodingStructure*& bestCS, Par ...@@ -842,6 +930,7 @@ void EncCu::xCompressCU( CodingStructure*& tempCS, CodingStructure*& bestCS, Par
memcpy(tempCS->prevPLT.curPLT[i], curLastPLT[i], curLastPLTSize[comID] * sizeof(Pel)); memcpy(tempCS->prevPLT.curPLT[i], curLastPLT[i], curLastPLTSize[comID] * sizeof(Pel));
} }
EncTestMode currTestMode = m_modeCtrl->currTestMode(); EncTestMode currTestMode = m_modeCtrl->currTestMode();
//continue;
currTestMode.maxCostAllowed = maxCostAllowed; currTestMode.maxCostAllowed = maxCostAllowed;
if (pps.getUseDQP() && partitioner.isSepTree(*tempCS) && isChroma( partitioner.chType )) if (pps.getUseDQP() && partitioner.isSepTree(*tempCS) && isChroma( partitioner.chType ))
...@@ -1240,12 +1329,6 @@ void EncCu::updateLambda(Slice *slice, const int dQP, ...@@ -1240,12 +1329,6 @@ void EncCu::updateLambda(Slice *slice, const int dQP,
#endif // SHARP_LUMA_DELTA_QP || ENABLE_QPA_SUB_CTU #endif // SHARP_LUMA_DELTA_QP || ENABLE_QPA_SUB_CTU
//ALBERTO CONCEPT FORK //ALBERTO CONCEPT FORK
int LEVEL0 = 1;
int LEVEL1 = 4;
int LEVEL2 = 16;
int LEVEL3 = 64;
int LEVEL4 = 256;
int levelValues [5] = {LEVEL0,LEVEL1,LEVEL2,LEVEL3,LEVEL4};
int EncCu::determinePosNodeInVector(std::string posNode) int EncCu::determinePosNodeInVector(std::string posNode)
{ {
int index = -1; int index = -1;
...@@ -1274,59 +1357,8 @@ int EncCu::determinePosNodeInVector(std::string posNode) ...@@ -1274,59 +1357,8 @@ int EncCu::determinePosNodeInVector(std::string posNode)
index += levelValues[i]; index += levelValues[i];
} }
} }
/*for(int i=0; i<posNode.length(); i++)
{
double multFactor = 1;
for(int j=1; j<=i; j++)
{
double code = posNode[j] - '0';
multFactor *= (code+1)/4;
}
int levelNodes = levelValues[i]*multFactor;
index += levelNodes;
}*/
return index; return index;
} }
/*
return determinePosNodeInVectorRec(posNode,"",0,0);
}
bool EncCu::digits_below_or_equal(std::string a, std::string b) {
if (a.length() > b.length()) {
return false;
}
for (int i = 0; i < a.length(); i++) {
if (a[i] > b[i]) {
return false;
}
}
return true;
}
int EncCu::determinePosNodeInVectorRec(std::string posNode, std::string posSearch, int index, int counter)
{
if(posNode == posSearch)
{
return counter;
}
else
{
if(index < 4 && digits_below_or_equal(posSearch,posNode))
{
posSearch.append(std::to_string(index));
index++;
counter += pow(4,posSearch.length());
return determinePosNodeInVectorRec(posNode,posSearch,index, counter);
}
else
{
index = 0;
counter++;
return determinePosNodeInVectorRec(posNode,posSearch,index, counter);
}
}
}*/
//END ALBERTO CONCEPT FORK //END ALBERTO CONCEPT FORK
void EncCu::xCheckModeSplit(CodingStructure *&tempCS, CodingStructure *&bestCS, Partitioner &partitioner, const EncTestMode& encTestMode, const ModeType modeTypeParent, bool &skipInterPass, double *splitRdCostBest ) void EncCu::xCheckModeSplit(CodingStructure *&tempCS, CodingStructure *&bestCS, Partitioner &partitioner, const EncTestMode& encTestMode, const ModeType modeTypeParent, bool &skipInterPass, double *splitRdCostBest )
...@@ -1449,15 +1481,13 @@ void EncCu::xCheckModeSplit(CodingStructure *&tempCS, CodingStructure *&bestCS, ...@@ -1449,15 +1481,13 @@ void EncCu::xCheckModeSplit(CodingStructure *&tempCS, CodingStructure *&bestCS,
m_pcInterSearch->savePrevUniMvInfo(tempCS->area.Y(), tmpUniMvInfo, isUniMvInfoSaved); m_pcInterSearch->savePrevUniMvInfo(tempCS->area.Y(), tmpUniMvInfo, isUniMvInfoSaved);
} }
//ALBERTO CONCEPT FORK //ALBERTO CONCEPT FORK
int actualNodeId = 0; int actualNodeId = 0; //CU COUNTER
std::string original = posNode;
//END ALBERTO CONCEPT FORK //END ALBERTO CONCEPT FORK
do do
{ {
//ALBERTO CONCEPT FORK
posNode.append(std::to_string(actualNodeId));
//END ALBERTO CONCEPT FORK
const auto &subCUArea = partitioner.currArea();
const auto &subCUArea = partitioner.currArea();
if( tempCS->picture->Y().contains( subCUArea.lumaPos() ) ) if( tempCS->picture->Y().contains( subCUArea.lumaPos() ) )
{ {
const unsigned wIdx = gp_sizeIdxInfo->idxFrom( subCUArea.lwidth () ); const unsigned wIdx = gp_sizeIdxInfo->idxFrom( subCUArea.lwidth () );
...@@ -1471,15 +1501,25 @@ void EncCu::xCheckModeSplit(CodingStructure *&tempCS, CodingStructure *&bestCS, ...@@ -1471,15 +1501,25 @@ void EncCu::xCheckModeSplit(CodingStructure *&tempCS, CodingStructure *&bestCS,
tempSubCS->bestParent = bestSubCS->bestParent = bestCS; tempSubCS->bestParent = bestSubCS->bestParent = bestCS;
double newMaxCostAllowed = isLuma(partitioner.chType) ? std::min(encTestMode.maxCostAllowed, bestCS->cost - m_pcRdCost->calcRdCost(tempCS->fracBits, tempCS->dist)) : MAX_DOUBLE; double newMaxCostAllowed = isLuma(partitioner.chType) ? std::min(encTestMode.maxCostAllowed, bestCS->cost - m_pcRdCost->calcRdCost(tempCS->fracBits, tempCS->dist)) : MAX_DOUBLE;
newMaxCostAllowed = std::max(0.0, newMaxCostAllowed); newMaxCostAllowed = std::max(0.0, newMaxCostAllowed);
xCompressCU(tempSubCS, bestSubCS, partitioner, newMaxCostAllowed);//LLAMADA RECURSIVA
//ALBERTO CONCEPT FORK //ALBERTO CONCEPT FORK
int idexPosNode = determinePosNodeInVector("00000"); posNode.append(std::to_string(actualNodeId)); //INTRODUCIMOS SU ID DENTRO DEL PADRE
if(vector[idexPosNode].mode==-1 && vector[idexPosNode].cost == -1) std::cout << "CONTROL --> código bucle split" << posNode << " : (" << tempSubCS->area.lheight() <<","<< tempSubCS->area.lwidth() <<") " << std::endl;
if(posNode == "0311")
{ {
//vector[idexPosNode]->mode=3; toStringVector();
//vector[idexPosNode]->cost=bestSubCS->cost; }
//END ALBERTO CONCEPT FORK
xCompressCU(tempSubCS, bestSubCS, partitioner, newMaxCostAllowed);//LLAMADA RECURSIVA
//ALBERTO CONCEPT FORK
if(tempCS->area.lheight()>=8 && tempCS->area.lwidth()>= 8)
{
int idexPosNode = determinePosNodeInVector(posNode);
if(vector[idexPosNode].mode==-1 && vector[idexPosNode].cost == -1)
{
vector[idexPosNode].mode=encTestMode.type;
vector[idexPosNode].cost=tempSubCS->cost;
}
} }
//END ALBERTO CONCEPT FORK //END ALBERTO CONCEPT FORK
tempSubCS->bestParent = bestSubCS->bestParent = nullptr; tempSubCS->bestParent = bestSubCS->bestParent = nullptr;
...@@ -1496,6 +1536,8 @@ void EncCu::xCheckModeSplit(CodingStructure *&tempCS, CodingStructure *&bestCS, ...@@ -1496,6 +1536,8 @@ void EncCu::xCheckModeSplit(CodingStructure *&tempCS, CodingStructure *&bestCS,
{ {
tempCS->motionLut = oldMotionLut; tempCS->motionLut = oldMotionLut;
} }
posNode = original;
actualNodeId = 0;
return; return;
} }
...@@ -1537,14 +1579,24 @@ void EncCu::xCheckModeSplit(CodingStructure *&tempCS, CodingStructure *&bestCS, ...@@ -1537,14 +1579,24 @@ void EncCu::xCheckModeSplit(CodingStructure *&tempCS, CodingStructure *&bestCS,
{ {
tempCS->motionLut = oldMotionLut; tempCS->motionLut = oldMotionLut;
} }
posNode = original;
actualNodeId = 0;
return; return;
} }
} }
} }
//ALBERTO CONCEPT FORK //ALBERTO CONCEPT FORK
actualNodeId++; actualNodeId++;//NOS PONEMOS EN EL PRIMER NODO DE LA PARTICIÓN (AVANZAMOS NODO)
posNode.pop_back(); //LIMPIAMOS NODO ACTUAL DEL VECTOR DEL CÓDIGO (STRING)
//END ALBERTO CONCEPT FORK //END ALBERTO CONCEPT FORK
} while( partitioner.nextPart( *tempCS ) );
} while( partitioner.nextPart( *tempCS ) );//AVANZAMOS A LA SIGIENTE CU GENERADA EN TEMPCS
//ALBERTO CONCEPT FORK
posNode = original;
actualNodeId = 0;
//END ALBERTO CONCEPT FORK
partitioner.exitCurrSplit(); partitioner.exitCurrSplit();
...@@ -2151,7 +2203,6 @@ bool EncCu::xCheckRDCostIntra(CodingStructure *&tempCS, CodingStructure *&bestCS ...@@ -2151,7 +2203,6 @@ bool EncCu::xCheckRDCostIntra(CodingStructure *&tempCS, CodingStructure *&bestCS
return foundZeroRootCbf; return foundZeroRootCbf;
} }
void EncCu::xCheckPLT(CodingStructure *&tempCS, CodingStructure *&bestCS, Partitioner &partitioner, const EncTestMode& encTestMode) void EncCu::xCheckPLT(CodingStructure *&tempCS, CodingStructure *&bestCS, Partitioner &partitioner, const EncTestMode& encTestMode)
{ {
if (((partitioner.currArea().lumaSize().width * partitioner.currArea().lumaSize().height <= 16) && (isLuma(partitioner.chType)) ) if (((partitioner.currArea().lumaSize().width * partitioner.currArea().lumaSize().height <= 16) && (isLuma(partitioner.chType)) )
......
...@@ -228,6 +228,22 @@ public: ...@@ -228,6 +228,22 @@ public:
}; };
#endif #endif
struct vectorModeCostStruct {
int mode;
double cost;
int threadNumber;
int posPadre;
};
//ALBERTO CONCEPT FORK
const int VECTOR_SIZE = 341; // TREE NODES
const int VECTOR_BYTES = VECTOR_SIZE * sizeof(vectorModeCostStruct); // VECTOR SIZE
const int LEVEL0 = 1;
const int LEVEL1 = 4;
const int LEVEL2 = 16;
const int LEVEL3 = 64;
const int LEVEL4 = 256;
const int levelValues [5] = {LEVEL0,LEVEL1,LEVEL2,LEVEL3,LEVEL4};
//END ALBERTO CONCEPT FORK
class EncCu class EncCu
: DecCu : DecCu
{ {
...@@ -236,6 +252,7 @@ private: ...@@ -236,6 +252,7 @@ private:
static int iter; static int iter;
static int seconds; static int seconds;
//END ALBERTO //END ALBERTO
bool m_bestModeUpdated; bool m_bestModeUpdated;
struct CtxPair struct CtxPair
{ {
...@@ -306,6 +323,15 @@ public: ...@@ -306,6 +323,15 @@ public:
/// copy parameters from encoder class /// copy parameters from encoder class
void init ( EncLib* pcEncLib, const SPS& sps ); void init ( EncLib* pcEncLib, const SPS& sps );
//ALBERTO CONCEPT FORK
void createAndInitSemaphore();
void initStructVector();
void updateFatherAndThreadNumbers(int LevelLowIndex, int LevelUpIndex, int posPadreActual, int i);
//END ALBERTO CONCEPT FORK
void setDecCuReshaperInEncCU(EncReshape* pcReshape, ChromaFormat chromaFormatIdc) void setDecCuReshaperInEncCU(EncReshape* pcReshape, ChromaFormat chromaFormatIdc)
{ {
initDecCuReshaper((Reshape*) pcReshape, chromaFormatIdc); initDecCuReshaper((Reshape*) pcReshape, chromaFormatIdc);
...@@ -317,7 +343,7 @@ public: ...@@ -317,7 +343,7 @@ public:
void destroy (); void destroy ();
//ALBERT CONCEPT FORK //ALBERTO CONCEPT FORK
void compressCtuForks(CodingStructure &cs, const UnitArea &area, const unsigned ctuRsAddr, const EnumArray<int, ChannelType> &prevQP, const EnumArray<int, ChannelType> &currQP); void compressCtuForks(CodingStructure &cs, const UnitArea &area, const unsigned ctuRsAddr, const EnumArray<int, ChannelType> &prevQP, const EnumArray<int, ChannelType> &currQP);
//END ALBERTO CONCEPT FORK //END ALBERTO CONCEPT FORK
......
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