<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jul 5, 2017 at 3:28 PM, <span dir="ltr"><<a href="mailto:aruna@multicorewareinc.com" target="_blank">aruna@multicorewareinc.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"># HG changeset patch<br>
# User Aruna Matheswaran <<a href="mailto:aruna@multicorewareinc.com">aruna@multicorewareinc.com</a>><br>
# Date 1498107303 -19800<br>
# Thu Jun 22 10:25:03 2017 +0530<br>
# Node ID 006c75cf822e92e3865fc97d21c25b<wbr>0fdc072b51<br>
# Parent 58b4fa89c42da0e9ef229035ea02f2<wbr>9d3a02fffe<br>
Allocate frame threads based on available pool threads<br>
<br>
This patch decides #frame-threads based on #pool-threads available. If pools not<br>
specified, #frame-threads will be decided based on detected #CPU-threads.<br>
<br>
This patch also decreases #frame-threads allocated for #pool-threads in the<br>
interval (15 - 31) and (>= 32) as there is high run to run variation in bitrate<br>
and SSIM with higher frame threads.With this reduction in #frame-threads there<br>
is ~3-4 % drop in fps with little SSIM improvement for #pool-threads (15 - 31)<br>
and no significant change in performance for #pool-threads (>= 32).<br></blockquote><div><br></div><div>Thanks. The improvements in quality seem to justify the change.</div><div>This has been pushed to default branch of x265.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
diff -r 58b4fa89c42d -r 006c75cf822e source/common/threadpool.cpp<br>
--- a/source/common/threadpool.cpp Fri Jun 30 16:31:29 2017 +0530<br>
+++ b/source/common/threadpool.cpp Thu Jun 22 10:25:03 2017 +0530<br>
@@ -253,6 +253,7 @@<br>
int cpusPerNode[MAX_NODE_NUM + 1];<br>
int threadsPerPool[MAX_NODE_NUM + 2];<br>
uint64_t nodeMaskPerPool[MAX_NODE_NUM + 2];<br>
+ int totalNumThreads = 0;<br>
<br>
memset(cpusPerNode, 0, sizeof(cpusPerNode));<br>
memset(threadsPerPool, 0, sizeof(threadsPerPool));<br>
@@ -388,9 +389,23 @@<br>
if (bNumaSupport)<br>
x265_log(p, X265_LOG_DEBUG, "NUMA node %d may use %d logical cores\n", i, cpusPerNode[i]);<br>
if (threadsPerPool[i])<br>
+ {<br>
numPools += (threadsPerPool[i] + MAX_POOL_THREADS - 1) / MAX_POOL_THREADS;<br>
+ totalNumThreads += threadsPerPool[i];<br>
+ }<br>
}<br>
+ if (!isThreadsReserved)<br>
+ {<br>
+ if (!numPools)<br>
+ {<br>
+ x265_log(p, X265_LOG_DEBUG, "No pool thread available. Deciding frame-threads based on detected CPU threads\n");<br>
+ totalNumThreads = ThreadPool::getCpuCount(); // auto-detect frame threads<br>
+ }<br>
<br>
+ if (!p->frameNumThreads)<br>
+ ThreadPool::<wbr>getFrameThreadsCount(p, totalNumThreads);<br>
+ }<br>
+<br>
if (!numPools)<br>
return NULL;<br>
<br>
@@ -412,7 +427,7 @@<br>
node++;<br>
int numThreads = X265_MIN(MAX_POOL_THREADS, threadsPerPool[node]);<br>
int origNumThreads = numThreads;<br>
- if (p->lookaheadThreads > numThreads / 2)<br>
+ if (i == 0 && p->lookaheadThreads > numThreads / 2)<br>
{<br>
p->lookaheadThreads = numThreads / 2;<br>
x265_log(p, X265_LOG_DEBUG, "Setting lookahead threads to a maximum of half the total number of threads\n");<br>
@@ -423,7 +438,7 @@<br>
maxProviders = 1;<br>
}<br>
<br>
- else<br>
+ else if (i == 0)<br>
numThreads -= p->lookaheadThreads;<br>
if (!pools[i].create(numThreads, maxProviders, nodeMaskPerPool[node]))<br>
{<br>
@@ -643,4 +658,21 @@<br>
#endif<br>
}<br>
<br>
+void ThreadPool::<wbr>getFrameThreadsCount(x265_<wbr>param* p, int cpuCount)<br>
+{<br>
+ int rows = (p->sourceHeight + p->maxCUSize - 1) >> g_log2Size[p->maxCUSize];<br>
+ if (!p->bEnableWavefront)<br>
+ p->frameNumThreads = X265_MIN3(cpuCount, (rows + 1) / 2, X265_MAX_FRAME_THREADS);<br>
+ else if (cpuCount >= 32)<br>
+ p->frameNumThreads = (p->sourceHeight > 2000) ? 6 : 5;<br>
+ else if (cpuCount >= 16)<br>
+ p->frameNumThreads = 4;<br>
+ else if (cpuCount >= 8)<br>
+ p->frameNumThreads = 3;<br>
+ else if (cpuCount >= 4)<br>
+ p->frameNumThreads = 2;<br>
+ else<br>
+ p->frameNumThreads = 1;<br>
+}<br>
+<br>
} // end namespace X265_NS<br>
diff -r 58b4fa89c42d -r 006c75cf822e source/common/threadpool.h<br>
--- a/source/common/threadpool.h Fri Jun 30 16:31:29 2017 +0530<br>
+++ b/source/common/threadpool.h Thu Jun 22 10:25:03 2017 +0530<br>
@@ -105,6 +105,7 @@<br>
static ThreadPool* allocThreadPools(x265_param* p, int& numPools, bool isThreadsReserved);<br>
static int getCpuCount();<br>
static int getNumaNodeCount();<br>
+ static void getFrameThreadsCount(x265_<wbr>param* p,int cpuCount);<br>
};<br>
<br>
/* Any worker thread may enlist the help of idle worker threads from the same<br>
diff -r 58b4fa89c42d -r 006c75cf822e source/encoder/encoder.cpp<br>
--- a/source/encoder/encoder.cpp Fri Jun 30 16:31:29 2017 +0530<br>
+++ b/source/encoder/encoder.cpp Thu Jun 22 10:25:03 2017 +0530<br>
@@ -134,26 +134,19 @@<br>
if (!p->bEnableWavefront && !p->bDistributeModeAnalysis && !p-><wbr>bDistributeMotionEstimation && !p->lookaheadSlices)<br>
allowPools = false;<br>
<br>
- if (!p->frameNumThreads)<br>
- {<br>
- // auto-detect frame threads<br>
- int cpuCount = ThreadPool::getCpuCount();<br>
- if (!p->bEnableWavefront)<br>
- p->frameNumThreads = X265_MIN3(cpuCount, (rows + 1) / 2, X265_MAX_FRAME_THREADS);<br>
- else if (cpuCount >= 32)<br>
- p->frameNumThreads = (p->sourceHeight > 2000) ? 8 : 6; // dual-socket 10-core IvyBridge or higher<br>
- else if (cpuCount >= 16)<br>
- p->frameNumThreads = 5; // 8 HT cores, or dual socket<br>
- else if (cpuCount >= 8)<br>
- p->frameNumThreads = 3; // 4 HT cores<br>
- else if (cpuCount >= 4)<br>
- p->frameNumThreads = 2; // Dual or Quad core<br>
- else<br>
- p->frameNumThreads = 1;<br>
- }<br>
m_numPools = 0;<br>
if (allowPools)<br>
m_threadPool = ThreadPool::allocThreadPools(<wbr>p, m_numPools, 0);<br>
+ else<br>
+ {<br>
+ if (!p->frameNumThreads)<br>
+ {<br>
+ // auto-detect frame threads<br>
+ int cpuCount = ThreadPool::getCpuCount();<br>
+ ThreadPool::<wbr>getFrameThreadsCount(p, cpuCount);<br>
+ }<br>
+ }<br>
+<br>
if (!m_numPools)<br>
{<br>
// issue warnings if any of these features were requested<br>
______________________________<wbr>_________________<br>
x265-devel mailing list<br>
<a href="mailto:x265-devel@videolan.org">x265-devel@videolan.org</a><br>
<a href="https://mailman.videolan.org/listinfo/x265-devel" rel="noreferrer" target="_blank">https://mailman.videolan.org/<wbr>listinfo/x265-devel</a><br>
</blockquote></div><br></div></div>