[x265] [PATCH] make cu level stats logging run time configurable

aarthi at multicorewareinc.com aarthi at multicorewareinc.com
Fri Jun 20 21:05:15 CEST 2014


# HG changeset patch
# User Aarthi Thirumalai<aarthi at multicorewareinc.com>
# Date 1403263555 -19800
#      Fri Jun 20 16:55:55 2014 +0530
# Node ID 71a8e0d9f931dfccf77db25e575841fdfe6baba4
# Parent  c2ebebb66bf4fd92c83288e821e98a24a4ba2610
make cu level stats logging run time configurable

diff -r c2ebebb66bf4 -r 71a8e0d9f931 source/CMakeLists.txt
--- a/source/CMakeLists.txt	Fri Jun 20 12:29:37 2014 +0530
+++ b/source/CMakeLists.txt	Fri Jun 20 16:55:55 2014 +0530
@@ -183,12 +183,7 @@
     endif()
 endif(WARNINGS_AS_ERRORS)
 
-option(LOG_CU_STATISTICS "Log Mode Decision Statistics at the CU Level" OFF)
-if(LOG_CU_STATISTICS)
-    add_definitions(-DLOG_CU_STATISTICS=1)
-else(LOG_CU_STATISTICS)
-    add_definitions(-DLOG_CU_STATISTICS=0)
-endif(LOG_CU_STATISTICS)
+
 
 option(ENABLE_PPA "Enable PPA profiling instrumentation" OFF)
 if(ENABLE_PPA)
diff -r c2ebebb66bf4 -r 71a8e0d9f931 source/Lib/TLibEncoder/TEncCu.cpp
--- a/source/Lib/TLibEncoder/TEncCu.cpp	Fri Jun 20 12:29:37 2014 +0530
+++ b/source/Lib/TLibEncoder/TEncCu.cpp	Fri Jun 20 16:55:55 2014 +0530
@@ -317,36 +317,35 @@
     m_tempCU[0]->initCU(cu->getPic(), cu->getAddr());
 
     // analysis of CU
-#if LOG_CU_STATISTICS
     int numPartition = cu->getTotalNumPart();
-#endif
 
     if (m_bestCU[0]->getSlice()->getSliceType() == I_SLICE)
     {
         xCompressIntraCU(m_bestCU[0], m_tempCU[0], 0, false);
-#if LOG_CU_STATISTICS
-        int i = 0, part;
-        do
+        if (m_param->bLogCuStats || m_param->rc.bStatWrite)
         {
-            m_log->totalCu++;
-            part = cu->getDepth(i);
-            int next = numPartition >> (part * 2);
-            if (part == g_maxCUDepth - 1 && cu->getPartitionSize(i) != SIZE_2Nx2N)
+            int i = 0, part;
+            do
             {
-                m_log->cntIntraNxN++;
+                m_log->totalCu++;
+                part = cu->getDepth(i);
+                int next = numPartition >> (part * 2);
+                if (part == g_maxCUDepth - 1 && cu->getPartitionSize(i) != SIZE_2Nx2N)
+                {
+                    m_log->cntIntraNxN++;
+                }
+                else
+                {
+                    m_log->cntIntra[part]++;
+                    if (cu->getLumaIntraDir()[i] > 1)
+                        m_log->cuIntraDistribution[part][ANGULAR_MODE_ID]++;
+                    else
+                        m_log->cuIntraDistribution[part][cu->getLumaIntraDir()[i]]++;
+                }
+                i += next;
             }
-            else
-            {
-                m_log->cntIntra[part]++;
-                if (cu->getLumaIntraDir()[i] > 1)
-                    m_log->cuIntraDistribution[part][ANGULAR_MODE_ID]++;
-                else
-                    m_log->cuIntraDistribution[part][cu->getLumaIntraDir()[i]]++;
-            }
-            i += next;
+            while (i < numPartition);
         }
-        while (i < numPartition);
-#endif // if LOG_CU_STATISTICS
     }
     else
     {
@@ -360,48 +359,49 @@
         }
         else
             xCompressCU(m_bestCU[0], m_tempCU[0], 0, false);
-#if LOG_CU_STATISTICS
-        int i = 0, part;
-        do
+        if (m_param->bLogCuStats || m_param->rc.bStatWrite)
         {
-            part = cu->getDepth(i);
-            m_log->cntTotalCu[part]++;
-            int next = numPartition >> (part * 2);
-            if (cu->isSkipped(i))
+            int i = 0, part;
+            do
             {
-                m_log->cntSkipCu[part]++;
-            }
-            else
-            {
-                m_log->totalCu++;
-                if (cu->getPredictionMode(0) == MODE_INTER)
+                part = cu->getDepth(i);
+                m_log->cntTotalCu[part]++;
+                int next = numPartition >> (part * 2);
+                if (cu->isSkipped(i))
                 {
-                    m_log->cntInter[part]++;
-                    if (cu->getPartitionSize(0) < AMP_ID)
-                        m_log->cuInterDistribution[part][cu->getPartitionSize(0)]++;
-                    else
-                        m_log->cuInterDistribution[part][AMP_ID]++;
+                    m_log->cntSkipCu[part]++;
                 }
-                else if (cu->getPredictionMode(0) == MODE_INTRA)
+                else
                 {
-                    if (part == g_maxCUDepth - 1 && cu->getPartitionSize(0) == SIZE_NxN)
+                    m_log->totalCu++;
+                    if (cu->getPredictionMode(0) == MODE_INTER)
                     {
-                        m_log->cntIntraNxN++;
+                        m_log->cntInter[part]++;
+                        if (cu->getPartitionSize(0) < AMP_ID)
+                            m_log->cuInterDistribution[part][cu->getPartitionSize(0)]++;
+                        else
+                            m_log->cuInterDistribution[part][AMP_ID]++;
                     }
-                    else
+                    else if (cu->getPredictionMode(0) == MODE_INTRA)
                     {
-                        m_log->cntIntra[part]++;
-                        if (cu->getLumaIntraDir()[0] > 1)
-                            m_log->cuIntraDistribution[part][ANGULAR_MODE_ID]++;
+                        if (part == g_maxCUDepth - 1 && cu->getPartitionSize(0) == SIZE_NxN)
+                        {
+                            m_log->cntIntraNxN++;
+                        }
                         else
-                            m_log->cuIntraDistribution[part][cu->getLumaIntraDir()[0]]++;
+                        {
+                            m_log->cntIntra[part]++;
+                            if (cu->getLumaIntraDir()[0] > 1)
+                                m_log->cuIntraDistribution[part][ANGULAR_MODE_ID]++;
+                            else
+                                m_log->cuIntraDistribution[part][cu->getLumaIntraDir()[0]]++;
+                        }
                     }
                 }
+                i = i + next;
             }
-            i = i + next;
+            while (i < numPartition);
         }
-        while (i < numPartition);
-#endif // if LOG_CU_STATISTICS
     }
 }
 
diff -r c2ebebb66bf4 -r 71a8e0d9f931 source/Lib/TLibEncoder/TEncCu.h
--- a/source/Lib/TLibEncoder/TEncCu.h	Fri Jun 20 12:29:37 2014 +0530
+++ b/source/Lib/TLibEncoder/TEncCu.h	Fri Jun 20 16:55:55 2014 +0530
@@ -131,10 +131,9 @@
 
 public:
 
-#if LOG_CU_STATISTICS
     StatisticLog  m_sliceTypeLog[3];
     StatisticLog* m_log;
-#endif
+
     TEncCu();
 
     void init(Encoder* top);
diff -r c2ebebb66bf4 -r 71a8e0d9f931 source/common/param.cpp
--- a/source/common/param.cpp	Fri Jun 20 12:29:37 2014 +0530
+++ b/source/common/param.cpp	Fri Jun 20 16:55:55 2014 +0530
@@ -103,6 +103,7 @@
     param->frameNumThreads = 0;
     param->poolNumThreads = 0;
     param->csvfn = NULL;
+    param->bLogCuStats = 0;
 
     /* Source specifications */
     param->internalBitDepth = x265_max_bit_depth;
@@ -559,6 +560,7 @@
             p->logLevel = parseName(value, logLevelNames, bError) - 1;
         }
     }
+    OPT("log-stats") p->bLogCuStats = atobool(value);
     OPT("repeat-headers") p->bRepeatHeaders = atobool(value);
     OPT("wpp") p->bEnableWavefront = atobool(value);
     OPT("ctu") p->maxCUSize = (uint32_t)atoi(value);
diff -r c2ebebb66bf4 -r 71a8e0d9f931 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp	Fri Jun 20 12:29:37 2014 +0530
+++ b/source/encoder/encoder.cpp	Fri Jun 20 16:55:55 2014 +0530
@@ -522,154 +522,154 @@
 
 void Encoder::printSummary()
 {
-#if LOG_CU_STATISTICS
-    for (int sliceType = 2; sliceType >= 0; sliceType--)
+    if (m_param->bLogCuStats)
     {
-        if (sliceType == P_SLICE && !m_analyzeP.m_numPics)
-            continue;
-        if (sliceType == B_SLICE && !m_analyzeB.m_numPics)
-            continue;
+        for (int sliceType = 2; sliceType >= 0; sliceType--)
+        {
+            if (sliceType == P_SLICE && !m_analyzeP.m_numPics)
+                continue;
+            if (sliceType == B_SLICE && !m_analyzeB.m_numPics)
+                continue;
 
-        StatisticLog finalLog;
-        for (int depth = 0; depth < (int)g_maxCUDepth; depth++)
-        {
-            for (int j = 0; j < m_totalFrameThreads; j++)
+            StatisticLog finalLog;
+            for (int depth = 0; depth < (int)g_maxCUDepth; depth++)
             {
-                for (int row = 0; row < m_frameEncoder[0].m_numRows; row++)
+                for (int j = 0; j < m_totalFrameThreads; j++)
                 {
-                    StatisticLog& enclog = m_frameEncoder[j].m_rows[row].m_cuCoder.m_sliceTypeLog[sliceType];
-                    if (depth == 0)
-                        finalLog.totalCu += enclog.totalCu;
-                    finalLog.cntIntra[depth] += enclog.cntIntra[depth];
-                    for (int m = 0; m < INTER_MODES; m++)
+                    for (int row = 0; row < m_frameEncoder[0].m_numRows; row++)
                     {
-                        if (m < INTRA_MODES)
+                        StatisticLog& enclog = m_frameEncoder[j].m_rows[row].m_cuCoder.m_sliceTypeLog[sliceType];
+                        if (depth == 0)
+                            finalLog.totalCu += enclog.totalCu;
+                        finalLog.cntIntra[depth] += enclog.cntIntra[depth];
+                        for (int m = 0; m < INTER_MODES; m++)
                         {
-                            finalLog.cuIntraDistribution[depth][m] += enclog.cuIntraDistribution[depth][m];
+                            if (m < INTRA_MODES)
+                            {
+                                finalLog.cuIntraDistribution[depth][m] += enclog.cuIntraDistribution[depth][m];
+                            }
+                            finalLog.cuInterDistribution[depth][m] += enclog.cuInterDistribution[depth][m];
                         }
-                        finalLog.cuInterDistribution[depth][m] += enclog.cuInterDistribution[depth][m];
-                    }
 
-                    if (depth == (int)g_maxCUDepth - 1)
-                        finalLog.cntIntraNxN += enclog.cntIntraNxN;
-                    if (sliceType != I_SLICE)
-                    {
-                        finalLog.cntTotalCu[depth] += enclog.cntTotalCu[depth];
-                        finalLog.cntInter[depth] += enclog.cntInter[depth];
-                        finalLog.cntSkipCu[depth] += enclog.cntSkipCu[depth];
+                        if (depth == (int)g_maxCUDepth - 1)
+                            finalLog.cntIntraNxN += enclog.cntIntraNxN;
+                        if (sliceType != I_SLICE)
+                        {
+                            finalLog.cntTotalCu[depth] += enclog.cntTotalCu[depth];
+                            finalLog.cntInter[depth] += enclog.cntInter[depth];
+                            finalLog.cntSkipCu[depth] += enclog.cntSkipCu[depth];
+                        }
                     }
                 }
-            }
 
-            uint64_t cntInter, cntSkipCu, cntIntra = 0, cntIntraNxN = 0, encCu = 0;
-            uint64_t cuInterDistribution[INTER_MODES], cuIntraDistribution[INTRA_MODES];
+                uint64_t cntInter, cntSkipCu, cntIntra = 0, cntIntraNxN = 0, encCu = 0;
+                uint64_t cuInterDistribution[INTER_MODES], cuIntraDistribution[INTRA_MODES];
 
-            // check for 0/0, if true assign 0 else calculate percentage
-            for (int n = 0; n < INTER_MODES; n++)
-            {
-                if (finalLog.cntInter[depth] == 0)
-                    cuInterDistribution[n] = 0;
+                // check for 0/0, if true assign 0 else calculate percentage
+                for (int n = 0; n < INTER_MODES; n++)
+                {
+                    if (finalLog.cntInter[depth] == 0)
+                        cuInterDistribution[n] = 0;
+                    else
+                        cuInterDistribution[n] = (finalLog.cuInterDistribution[depth][n] * 100) / finalLog.cntInter[depth];
+                    if (n < INTRA_MODES)
+                    {
+                        if (finalLog.cntIntra[depth] == 0)
+                        {
+                            cntIntraNxN = 0;
+                            cuIntraDistribution[n] = 0;
+                        }
+                        else
+                        {
+                            cntIntraNxN = (finalLog.cntIntraNxN * 100) / finalLog.cntIntra[depth];
+                            cuIntraDistribution[n] = (finalLog.cuIntraDistribution[depth][n] * 100) / finalLog.cntIntra[depth];
+                        }
+                    }
+                }
+
+                if (finalLog.totalCu == 0)
+                {
+                    encCu = 0;
+                }
                 else
-                    cuInterDistribution[n] = (finalLog.cuInterDistribution[depth][n] * 100) / finalLog.cntInter[depth];
-                if (n < INTRA_MODES)
                 {
-                    if (finalLog.cntIntra[depth] == 0)
+                    if (sliceType == I_SLICE)
                     {
-                        cntIntraNxN = 0;
-                        cuIntraDistribution[n] = 0;
+                        cntIntra = (finalLog.cntIntra[depth] * 100) / finalLog.totalCu;
+                        cntIntraNxN = (finalLog.cntIntraNxN * 100) / finalLog.totalCu;
                     }
                     else
                     {
-                        cntIntraNxN = (finalLog.cntIntraNxN * 100) / finalLog.cntIntra[depth];
-                        cuIntraDistribution[n] = (finalLog.cuIntraDistribution[depth][n] * 100) / finalLog.cntIntra[depth];
+                        encCu = ((finalLog.cntIntra[depth] + finalLog.cntInter[depth]) * 100) / finalLog.totalCu;
                     }
                 }
-            }
-
-            if (finalLog.totalCu == 0)
-            {
-                encCu = 0;
-            }
-            else
-            {
                 if (sliceType == I_SLICE)
                 {
-                    cntIntra = (finalLog.cntIntra[depth] * 100) / finalLog.totalCu;
-                    cntIntraNxN = (finalLog.cntIntraNxN * 100) / finalLog.totalCu;
-                }
-                else
-                {
-                    encCu = ((finalLog.cntIntra[depth] + finalLog.cntInter[depth]) * 100) / finalLog.totalCu;
-                }
-            }
-            if (sliceType == I_SLICE)
-            {
-                cntInter = 0;
-                cntSkipCu = 0;
-            }
-            else
-            {
-                if (finalLog.cntTotalCu[depth] == 0)
-                {
                     cntInter = 0;
-                    cntIntra = 0;
                     cntSkipCu = 0;
                 }
                 else
                 {
-                    cntInter = (finalLog.cntInter[depth] * 100) / finalLog.cntTotalCu[depth];
-                    cntIntra = (finalLog.cntIntra[depth] * 100) / finalLog.cntTotalCu[depth];
-                    cntSkipCu = (finalLog.cntSkipCu[depth] * 100) / finalLog.cntTotalCu[depth];
+                    if (finalLog.cntTotalCu[depth] == 0)
+                    {
+                        cntInter = 0;
+                        cntIntra = 0;
+                        cntSkipCu = 0;
+                    }
+                    else
+                    {
+                        cntInter = (finalLog.cntInter[depth] * 100) / finalLog.cntTotalCu[depth];
+                        cntIntra = (finalLog.cntIntra[depth] * 100) / finalLog.cntTotalCu[depth];
+                        cntSkipCu = (finalLog.cntSkipCu[depth] * 100) / finalLog.cntTotalCu[depth];
+                    }
                 }
-            }
-            // print statistics
-            int cuSize = g_maxCUSize >> depth;
-            char stats[256] = { 0 };
-            int len = 0;
-            if (sliceType != I_SLICE)
-            {
-                len += sprintf(stats + len, "EncCU "X265_LL "%% Merge "X265_LL "%%", encCu, cntSkipCu);
-            }
-            if (cntInter)
-            {
-                len += sprintf(stats + len, " Inter "X265_LL "%%", cntInter);
-                if (m_param->bEnableAMP)
-                    len += sprintf(stats + len, "(%dx%d "X265_LL "%% %dx%d "X265_LL "%% %dx%d "X265_LL "%% AMP "X265_LL "%%)",
-                                   cuSize, cuSize, cuInterDistribution[0],
-                                   cuSize / 2, cuSize, cuInterDistribution[2],
-                                   cuSize, cuSize / 2, cuInterDistribution[1],
-                                   cuInterDistribution[3]);
-                else if (m_param->bEnableRectInter)
-                    len += sprintf(stats + len, "(%dx%d "X265_LL "%% %dx%d "X265_LL "%% %dx%d "X265_LL "%%)",
-                                   cuSize, cuSize, cuInterDistribution[0],
-                                   cuSize / 2, cuSize, cuInterDistribution[2],
-                                   cuSize, cuSize / 2, cuInterDistribution[1]);
-            }
-            if (cntIntra)
-            {
-                len += sprintf(stats + len, " Intra "X265_LL "%%(DC "X265_LL "%% P "X265_LL "%% Ang "X265_LL "%%",
-                               cntIntra, cuIntraDistribution[0],
-                               cuIntraDistribution[1], cuIntraDistribution[2]);
+                // print statistics
+                int cuSize = g_maxCUSize >> depth;
+                char stats[256] = { 0 };
+                int len = 0;
                 if (sliceType != I_SLICE)
                 {
-                    if (depth == (int)g_maxCUDepth - 1)
-                        len += sprintf(stats + len, " %dx%d "X265_LL "%%", cuSize / 2, cuSize / 2, cntIntraNxN);
+                    len += sprintf(stats + len, "EncCU "X265_LL "%% Merge "X265_LL "%%", encCu, cntSkipCu);
                 }
+                if (cntInter)
+                {
+                    len += sprintf(stats + len, " Inter "X265_LL "%%", cntInter);
+                    if (m_param->bEnableAMP)
+                        len += sprintf(stats + len, "(%dx%d "X265_LL "%% %dx%d "X265_LL "%% %dx%d "X265_LL "%% AMP "X265_LL "%%)",
+                                       cuSize, cuSize, cuInterDistribution[0],
+                                       cuSize / 2, cuSize, cuInterDistribution[2],
+                                       cuSize, cuSize / 2, cuInterDistribution[1],
+                                       cuInterDistribution[3]);
+                    else if (m_param->bEnableRectInter)
+                        len += sprintf(stats + len, "(%dx%d "X265_LL "%% %dx%d "X265_LL "%% %dx%d "X265_LL "%%)",
+                                       cuSize, cuSize, cuInterDistribution[0],
+                                       cuSize / 2, cuSize, cuInterDistribution[2],
+                                       cuSize, cuSize / 2, cuInterDistribution[1]);
+                }
+                if (cntIntra)
+                {
+                    len += sprintf(stats + len, " Intra "X265_LL "%%(DC "X265_LL "%% P "X265_LL "%% Ang "X265_LL "%%",
+                                   cntIntra, cuIntraDistribution[0],
+                                   cuIntraDistribution[1], cuIntraDistribution[2]);
+                    if (sliceType != I_SLICE)
+                    {
+                        if (depth == (int)g_maxCUDepth - 1)
+                            len += sprintf(stats + len, " %dx%d "X265_LL "%%", cuSize / 2, cuSize / 2, cntIntraNxN);
+                    }
 
-                len += sprintf(stats + len, ")");
-                if (sliceType == I_SLICE)
-                {
-                    if (depth == (int)g_maxCUDepth - 1)
-                        len += sprintf(stats + len, " %dx%d: "X265_LL "%%", cuSize / 2, cuSize / 2, cntIntraNxN);
+                    len += sprintf(stats + len, ")");
+                    if (sliceType == I_SLICE)
+                    {
+                        if (depth == (int)g_maxCUDepth - 1)
+                            len += sprintf(stats + len, " %dx%d: "X265_LL "%%", cuSize / 2, cuSize / 2, cntIntraNxN);
+                    }
                 }
+                const char slicechars[] = "BPI";
+                if (stats[0])
+                    x265_log(m_param, X265_LOG_INFO, "%c%-2d: %s\n", slicechars[sliceType], cuSize, stats);
             }
-            const char slicechars[] = "BPI";
-            if (stats[0])
-                x265_log(m_param, X265_LOG_INFO, "%c%-2d: %s\n", slicechars[sliceType], cuSize, stats);
         }
     }
-
-#endif // if LOG_CU_STATISTICS
     if (m_param->logLevel >= X265_LOG_INFO)
     {
         char buffer[200];
diff -r c2ebebb66bf4 -r 71a8e0d9f931 source/encoder/frameencoder.cpp
--- a/source/encoder/frameencoder.cpp	Fri Jun 20 12:29:37 2014 +0530
+++ b/source/encoder/frameencoder.cpp	Fri Jun 20 16:55:55 2014 +0530
@@ -259,13 +259,16 @@
 
     slice->setScalingList(m_top->getScalingList());
     slice->getScalingList()->setUseTransformSkip(m_pps.getUseTransformSkip());
-#if LOG_CU_STATISTICS
-    for (int i = 0; i < m_numRows; i++)
+
+    /* We also need analysis of cu distribution across various modes in multipass encodes */
+    if (m_param->bLogCuStats || m_param->rc.bStatWrite)
     {
-        m_rows[i].m_cuCoder.m_log = &m_rows[i].m_cuCoder.m_sliceTypeLog[sliceType];
+        for (int i = 0; i < m_numRows; i++)
+        {
+            m_rows[i].m_cuCoder.m_log = &m_rows[i].m_cuCoder.m_sliceTypeLog[sliceType];
+        }
     }
 
-#endif
     if (slice->getPPS()->getDeblockingFilterControlPresentFlag())
     {
         slice->getPPS()->setDeblockingFilterOverrideEnabledFlag(!m_top->m_loopFilterOffsetInPPS);
diff -r c2ebebb66bf4 -r 71a8e0d9f931 source/x265.cpp
--- a/source/x265.cpp	Fri Jun 20 12:29:37 2014 +0530
+++ b/source/x265.cpp	Fri Jun 20 16:55:55 2014 +0530
@@ -71,6 +71,8 @@
     { "log-level",      required_argument, NULL, 0 },
     { "level",          required_argument, NULL, 0 },
     { "csv",            required_argument, NULL, 0 },
+    { "no-log-stats",         no_argument, NULL, 0 },
+    { "log-stats",            no_argument, NULL, 0 },
     { "y4m",                  no_argument, NULL, 0 },
     { "no-progress",          no_argument, NULL, 0 },
     { "output",         required_argument, NULL, 'o' },
@@ -315,6 +317,7 @@
     H0("   --log-level <string>          Logging level: none error warning info debug full. Default %s\n", logLevelNames[param->logLevel + 1]);
     H0("   --csv <filename>              Comma separated log file, log level >= 3 frame log, else one line per run\n");
     H0("   --no-progress                 Disable CLI progress reports\n");
+    H0("   --[no-]log-stats              Enable logging stats about distribution of cu across all modes. Default %s\n",OPT(param->bLogCuStats));
     H0("-o/--output <filename>           Bitstream output file name\n");
     H0("\nInput Options:\n");
     H0("   --input <filename>            Raw YUV or Y4M input file name. `-` for stdin\n");
diff -r c2ebebb66bf4 -r 71a8e0d9f931 source/x265.h
--- a/source/x265.h	Fri Jun 20 12:29:37 2014 +0530
+++ b/source/x265.h	Fri Jun 20 16:55:55 2014 +0530
@@ -674,6 +674,9 @@
      * chosen, the cu-transquant-bypass flag is set for that CU. */
     int       bCULossless;
 
+    /* Enable analysis and logging distribution of Cus encoded across various modes during mode decision.*/
+    int       bLogCuStats;
+
     /*== Rate Control ==*/
 
     struct


More information about the x265-devel mailing list