[x265] [PATCH] api: simplistic auto-determination of frame thread count
Steve Borho
steve at borho.org
Thu Nov 7 04:38:53 CET 2013
# HG changeset patch
# User Steve Borho <steve at borho.org>
# Date 1383795498 21600
# Wed Nov 06 21:38:18 2013 -0600
# Node ID 90d9c1067f50c750e5e0b23952ac0edd2595e575
# Parent 93cccbe49a93dd4c054ef06aca76974948793613
api: simplistic auto-determination of frame thread count
diff -r 93cccbe49a93 -r 90d9c1067f50 source/common/common.cpp
--- a/source/common/common.cpp Wed Nov 06 19:49:38 2013 -0600
+++ b/source/common/common.cpp Wed Nov 06 21:38:18 2013 -0600
@@ -141,7 +141,7 @@
/* Applying non-zero default values to all elements in the param structure */
param->logLevel = X265_LOG_INFO;
param->bEnableWavefront = 1;
- param->frameNumThreads = 1;
+ param->frameNumThreads = 0;
param->inputBitDepth = 8;
param->sourceCsp = X265_CSP_I420;
@@ -444,8 +444,8 @@
"Search Range must be less than 32768");
CHECK(param->keyframeMax < 0,
"Keyframe interval must be 0 (auto) 1 (intra-only) or greater than 1");
- CHECK(param->frameNumThreads <= 0,
- "frameNumThreads (--frame-threads) must be 1 or higher");
+ CHECK(param->frameNumThreads < 0,
+ "frameNumThreads (--frame-threads) must be 0 or higher");
CHECK(param->cbQpOffset < -12, "Min. Chroma Cb QP Offset is -12");
CHECK(param->cbQpOffset > 12, "Max. Chroma Cb QP Offset is 12");
CHECK(param->crQpOffset < -12, "Min. Chroma Cr QP Offset is -12");
diff -r 93cccbe49a93 -r 90d9c1067f50 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp Wed Nov 06 19:49:38 2013 -0600
+++ b/source/encoder/encoder.cpp Wed Nov 06 21:38:18 2013 -0600
@@ -1024,11 +1024,26 @@
_param->poolNumThreads = 1;
setThreadPool(ThreadPool::allocThreadPool(_param->poolNumThreads));
- int actual = ThreadPool::getThreadPool()->getThreadCount();
- if (actual > 1)
+ int poolThreadCount = ThreadPool::getThreadPool()->getThreadCount();
+ int rows = (_param->sourceHeight + _param->maxCUSize - 1) / _param->maxCUSize;
+
+ if (_param->frameNumThreads == 0)
{
- x265_log(_param, X265_LOG_INFO, "WPP streams / pool / frames : %d / %d / %d\n",
- (_param->sourceHeight + _param->maxCUSize - 1) / _param->maxCUSize, actual, _param->frameNumThreads);
+ // auto-detect frame threads
+ if (poolThreadCount > 32)
+ _param->frameNumThreads = 6; // dual-socket 10-core IvyBridge or higher
+ else if (poolThreadCount >= 16)
+ _param->frameNumThreads = 5; // 8 HT cores, or dual socket
+ else if (poolThreadCount >= 12)
+ _param->frameNumThreads = 3; // 6 HT cores
+ else if (poolThreadCount >= 4)
+ _param->frameNumThreads = 2; // Dual or Quad core
+ else
+ _param->frameNumThreads = 1;
+ }
+ if (poolThreadCount > 1)
+ {
+ x265_log(_param, X265_LOG_INFO, "WPP streams / pool / frames : %d / %d / %d\n", rows, poolThreadCount, _param->frameNumThreads);
}
else if (_param->frameNumThreads > 1)
{
@@ -1044,7 +1059,6 @@
{
x265_log(_param, X265_LOG_INFO, "Warning: picture-based SAO used with frame parallelism\n");
}
-
if (!_param->keyframeMin)
{
_param->keyframeMin = _param->keyframeMax;
diff -r 93cccbe49a93 -r 90d9c1067f50 source/x265.cpp
--- a/source/x265.cpp Wed Nov 06 19:49:38 2013 -0600
+++ b/source/x265.cpp Wed Nov 06 21:38:18 2013 -0600
@@ -266,7 +266,7 @@
H0(" --threads Number of threads for thread pool (0: detect CPU core count, default)\n");
H0("-p/--preset ultrafast, veryfast, faster, fast, medium, slow, slower, veryslow, or placebo\n");
H0("-t/--tune Tune the settings for a particular type of source or situation\n");
- H0("-F/--frame-threads Number of concurrently encoded frames. Default %d\n", param->frameNumThreads);
+ H0("-F/--frame-threads Number of concurrently encoded frames. 0: auto-determined by core count\n");
H0(" --log Logging level 0:ERROR 1:WARNING 2:INFO 3:DEBUG -1:NONE. Default %d\n", param->logLevel);
H0(" --csv Comma separated log file, log level >= 3 frame log, else one line per run\n");
H0(" --y4m Parse input stream as YUV4MPEG2 regardless of file extension\n");
diff -r 93cccbe49a93 -r 90d9c1067f50 source/x265.h
--- a/source/x265.h Wed Nov 06 19:49:38 2013 -0600
+++ b/source/x265.h Wed Nov 06 21:38:18 2013 -0600
@@ -289,8 +289,8 @@
{
int logLevel;
int bEnableWavefront; ///< enable wavefront parallel processing
- int poolNumThreads; ///< number of threads to allocate for thread pool
- int frameNumThreads; ///< number of concurrently encoded frames
+ int poolNumThreads; ///< number of threads to allocate for thread pool, 0 implies auto-detection (default)
+ int frameNumThreads; ///< number of concurrently encoded frames, 0 implies auto-detection (default)
const char *csvfn; ///< csv log filename. logLevel >= 3 is frame logging, else one line per run
// source specification
More information about the x265-devel
mailing list