History

refact threadIdc and CPU cores logic in init module

huade committed 10 years ago

Commit ef38c2a1 parent e75c5851 file · +23 −21Browse files

Showing the changes to codec/encoder/core/src/encoder_ext.cpp (1 of 1 file). Show all

Unified · Split

codec/encoder/core/src/encoder_ext.cpp+23−21
@@ -180,6 +180,11 @@ int32_t SliceArgumentValidationFixedSliceMode(SLogContext* pLogCtx, · 179 unmodified lines
180180
181181 if (pSliceArgument->uiSliceNum == 0) {
182182 WelsCPUFeatureDetect (&iCpuCores);
183+ if (0 == iCpuCores ) {
184+ // cpuid not supported or doesn't expose the number of cores,
185+ // use high level system API as followed to detect number of pysical/logic processor
186+ iCpuCores = DynamicDetectCpuCores();
187+ }
183188 pSliceArgument->uiSliceNum = iCpuCores;
184189 }
185190
@@ -2245,8 +2250,8 @@ void FreeMemorySvc (sWelsEncCtx** ppCtx) { · 2059 unmodified lines
22452250 }
22462251 }
22472252
2248−int32_t InitSliceSettings (SLogContext* pLogCtx, SWelsSvcCodingParam* pCodingParam, const int32_t kiCpuCores,
2249− int16_t* pMaxSliceCount) {
2253+int32_t InitSliceSettings (SLogContext* pLogCtx, SWelsSvcCodingParam* pCodingParam,
2254+ const int32_t kiCpuCores, int16_t* pMaxSliceCount) {
22502255 int32_t iSpatialIdx = 0, iSpatialNum = pCodingParam->iSpatialLayerNum;
22512256 uint16_t iMaxSliceCount = 0;
22522257
@@ -2254,11 +2259,6 @@ int32_t InitSliceSettings (SLogContext* pLogCtx, SWelsSvcCodingParam* pCodingPar · 1 unmodified line
22542259 SSpatialLayerConfig* pDlp = &pCodingParam->sSpatialLayers[iSpatialIdx];
22552260 SSliceArgument* pSliceArgument = &pDlp->sSliceArgument;
22562261 int32_t iReturn = 0;
2257− int32_t iSliceNum = (SM_FIXEDSLCNUM_SLICE == pSliceArgument->uiSliceMode && 0==pSliceArgument->uiSliceNum) ? kiCpuCores : pSliceArgument->uiSliceNum;
2258− // NOTE: Per design, in case MT/DYNAMIC_SLICE_ASSIGN enabled, for SM_FIXEDSLCNUM_SLICE mode,
2259− // uiSliceNum of current spatial layer settings equals to uiCpuCores number; SM_SIZELIMITED_SLICE mode,
2260− // uiSliceNum intials as uiCpuCores also, stay tuned dynamically slicing in future
2261− pSliceArgument->uiSliceNum = iSliceNum; // used fixed one
22622262
22632263 switch (pSliceArgument->uiSliceMode) {
22642264 case SM_SIZELIMITED_SLICE:
@@ -2273,16 +2273,15 @@ int32_t InitSliceSettings (SLogContext* pLogCtx, SWelsSvcCodingParam* pCodingPar · 8 unmodified lines
22732273 if (pSliceArgument->uiSliceNum > iMaxSliceCount) {
22742274 iMaxSliceCount = pSliceArgument->uiSliceNum;
22752275 }
2276−
22772276 }
22782277 break;
22792278 case SM_SINGLE_SLICE:
2280− if (iSliceNum > iMaxSliceCount)
2281− iMaxSliceCount = iSliceNum;
2279+ if (pSliceArgument->uiSliceNum > iMaxSliceCount)
2280+ iMaxSliceCount = pSliceArgument->uiSliceNum;
22822281 break;
22832282 case SM_RASTER_SLICE:
2284− if (iSliceNum > iMaxSliceCount)
2285− iMaxSliceCount = iSliceNum;
2283+ if (pSliceArgument->uiSliceNum > iMaxSliceCount)
2284+ iMaxSliceCount = pSliceArgument->uiSliceNum;
22862285 break;
22872286 default:
22882287 break;
@@ -2371,16 +2370,19 @@ int32_t GetMultipleThreadIdc (SLogContext* pLogCtx, SWelsSvcCodingParam* pCoding · 82 unmodified lines
23712370 iCacheLineSize = 16; // 16 bytes aligned in default
23722371 #endif//X86_ASM
23732372
2374− if (pCodingParam->iMultipleThreadIdc > 0)
2375− uiCpuCores = pCodingParam->iMultipleThreadIdc;
2376− else {
2377− if (uiCpuCores ==
2378− 0) { // cpuid not supported or doesn't expose the number of cores, use high level system API as followed to detect number of pysical/logic processor
2379− uiCpuCores = DynamicDetectCpuCores();
2380− }// So far so many cpu cores up to MAX_THREADS_NUM mean for server platforms,
2381− // for client application here it is constrained by maximal to MAX_THREADS_NUM
2373+ if (0 == pCodingParam->iMultipleThreadIdc && uiCpuCores == 0) {
2374+ // cpuid not supported or doesn't expose the number of cores,
2375+ // use high level system API as followed to detect number of pysical/logic processor
2376+ uiCpuCores = DynamicDetectCpuCores();
23822377 }
2383− uiCpuCores = WELS_CLIP3 (uiCpuCores, 1, MAX_THREADS_NUM);
2378+
2379+ if(0 == pCodingParam->iMultipleThreadIdc)
2380+ pCodingParam->iMultipleThreadIdc = (uiCpuCores > 0) ? uiCpuCores : 1;
2381+
2382+ // So far so many cpu cores up to MAX_THREADS_NUM mean for server platforms,
2383+ // for client application here it is constrained by maximal to MAX_THREADS_NUM
2384+ pCodingParam->iMultipleThreadIdc = WELS_CLIP3 (pCodingParam->iMultipleThreadIdc, 1, MAX_THREADS_NUM);
2385+ uiCpuCores = pCodingParam->iMultipleThreadIdc;
23842386
23852387 if (InitSliceSettings (pLogCtx, pCodingParam, uiCpuCores, &iSliceNum)) {
23862388 WelsLog (pLogCtx, WELS_LOG_ERROR, "GetMultipleThreadIdc(), InitSliceSettings failed.");

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t