*********************************************************/
static void BMK_initCCtx(ZSTD_CCtx* ctx,
- const void* dictBuffer, size_t dictBufferSize, int cLevel,
+ const void* dictBuffer, const size_t dictBufferSize, const int cLevel,
const ZSTD_compressionParameters* comprParams, const BMK_advancedParams_t* adv) {
ZSTD_CCtx_reset(ctx);
ZSTD_CCtx_resetParameters(ctx);
static void BMK_initDCtx(ZSTD_DCtx* dctx,
- const void* dictBuffer, size_t dictBufferSize) {
+ const void* dictBuffer, const size_t dictBufferSize) {
ZSTD_DCtx_reset(dctx);
ZSTD_DCtx_loadDictionary(dctx, dictBuffer, dictBufferSize);
}
} BMK_initCCtxArgs;
static size_t local_initCCtx(void* payload) {
- BMK_initCCtxArgs* ag = (BMK_initCCtxArgs*)payload;
+ const BMK_initCCtxArgs* ag = (const BMK_initCCtxArgs*)payload;
BMK_initCCtx(ag->ctx, ag->dictBuffer, ag->dictBufferSize, ag->cLevel, ag->comprParams, ag->adv);
return 0;
}
} BMK_initDCtxArgs;
static size_t local_initDCtx(void* payload) {
- BMK_initDCtxArgs* ag = (BMK_initDCtxArgs*)payload;
+ const BMK_initDCtxArgs* ag = (const BMK_initDCtxArgs*)payload;
BMK_initDCtx(ag->dctx, ag->dictBuffer, ag->dictBufferSize);
return 0;
}
BMK_freeTimeState(timeStateDecompress);
return results;
}
- results.result.cSpeed = ((double)srcSize / intermediateResultCompress.result.result.nanoSecPerRun) * TIMELOOP_NANOSEC;
+ results.result.cSpeed = (srcSize * TIMELOOP_NANOSEC) / intermediateResultCompress.result.result.nanoSecPerRun;
results.result.cSize = intermediateResultCompress.result.result.sumOfReturn;
}
BMK_freeTimeState(timeStateDecompress);
return results;
}
- results.result.dSpeed = ((double)srcSize / intermediateResultDecompress.result.result.nanoSecPerRun) * TIMELOOP_NANOSEC;
+ results.result.dSpeed = (srcSize * TIMELOOP_NANOSEC) / intermediateResultDecompress.result.result.nanoSecPerRun;
}
BMK_freeTimeState(timeStateCompress);
if(compressionResults.result.nanoSecPerRun == 0) {
results.result.cSpeed = 0;
} else {
- results.result.cSpeed = (double)srcSize / compressionResults.result.nanoSecPerRun * TIMELOOP_NANOSEC;
+ results.result.cSpeed = srcSize * TIMELOOP_NANOSEC / compressionResults.result.nanoSecPerRun;
}
results.result.cSize = compressionResults.result.sumOfReturn;
}
if(decompressionResults.result.nanoSecPerRun == 0) {
results.result.dSpeed = 0;
} else {
- results.result.dSpeed = (double)srcSize / decompressionResults.result.nanoSecPerRun * TIMELOOP_NANOSEC;
+ results.result.dSpeed = srcSize * TIMELOOP_NANOSEC / decompressionResults.result.nanoSecPerRun;
}
}
}
return results;
}
-/* global winner used for display. */
-static winnerInfo_t g_winner = { { 0, 0, (size_t)-1, (size_t)-1 } , { 0, 0, 0, 0, 0, 0, ZSTD_fast } };
-static constraint_t g_targetConstraints;
static void BMK_printWinner(FILE* f, const U32 cLevel, const BMK_result_t result, const ZSTD_compressionParameters params, const size_t srcSize)
{
- if(DEBUG || compareResultLT(g_winner.result, result, g_targetConstraints, srcSize)) {
- char lvlstr[15] = "Custom Level";
- const U64 time = UTIL_clockSpanNano(g_time);
- const U64 minutes = time / (60ULL * TIMELOOP_NANOSEC);
+ char lvlstr[15] = "Custom Level";
+ const U64 time = UTIL_clockSpanNano(g_time);
+ const U64 minutes = time / (60ULL * TIMELOOP_NANOSEC);
- if(DEBUG && compareResultLT(g_winner.result, result, g_targetConstraints, srcSize)) {
- DISPLAY("New Winner: \n");
- }
+ DISPLAY("\r%79s\r", "");
- DISPLAY("\r%79s\r", "");
+ fprintf(f," {%3u,%3u,%3u,%3u,%3u,%3u, %s }, ",
+ params.windowLog, params.chainLog, params.hashLog, params.searchLog, params.searchLength,
+ params.targetLength, g_stratName[(U32)(params.strategy)]);
- fprintf(f," {%3u,%3u,%3u,%3u,%3u,%3u, %s }, ",
- params.windowLog, params.chainLog, params.hashLog, params.searchLog, params.searchLength,
- params.targetLength, g_stratName[(U32)(params.strategy)]);
+ if(cLevel != CUSTOM_LEVEL) {
+ snprintf(lvlstr, 15, " Level %2u ", cLevel);
+ }
- if(cLevel != CUSTOM_LEVEL) {
- snprintf(lvlstr, 15, " Level %2u ", cLevel);
- }
+ fprintf(f,
+ "/* %s */ /* R:%5.3f at %5.1f MB/s - %5.1f MB/s */",
+ lvlstr, (double)srcSize / result.cSize, (double)result.cSpeed / (1 << 20), (double)result.dSpeed / (1 << 20));
+
+ if(TIMED) { fprintf(f, " - %1lu:%2lu:%05.2f", (unsigned long) minutes / 60,(unsigned long) minutes % 60, (double)(time - minutes * TIMELOOP_NANOSEC * 60ULL)/TIMELOOP_NANOSEC); }
+ fprintf(f, "\n");
+}
- fprintf(f,
- "/* %s */ /* R:%5.3f at %5.1f MB/s - %5.1f MB/s */",
- lvlstr, (double)srcSize / result.cSize, (double)result.cSpeed / (1 << 20), (double)result.dSpeed / (1 << 20));
+static void BMK_printWinnerOpt(FILE* f, const U32 cLevel, const BMK_result_t result, const ZSTD_compressionParameters params, const constraint_t targetConstraints, const size_t srcSize)
+{
+ /* global winner used for constraints */
+ static winnerInfo_t g_winner = { { 0, 0, (size_t)-1, (size_t)-1 } , { 0, 0, 0, 0, 0, 0, ZSTD_fast } };
+
+ if(DEBUG || compareResultLT(g_winner.result, result, targetConstraints, srcSize)) {
+ if(DEBUG && compareResultLT(g_winner.result, result, targetConstraints, srcSize)) {
+ DISPLAY("New Winner: \n");
+ }
- if(TIMED) { fprintf(f, " - %1lu:%2lu:%05.2f", (unsigned long) minutes / 60,(unsigned long) minutes % 60, (double)(time - minutes * TIMELOOP_NANOSEC * 60ULL)/TIMELOOP_NANOSEC); }
- fprintf(f, "\n");
+ BMK_printWinner(f, cLevel, result, params, srcSize);
- if(compareResultLT(g_winner.result, result, g_targetConstraints, srcSize)) {
+ if(compareResultLT(g_winner.result, result, targetConstraints, srcSize)) {
BMK_translateAdvancedParams(params);
g_winner.result = result;
g_winner.params = params;
unsigned ind = 0;
for(i = 0; i < varyLen; i++) {
switch(varyParams[i]) {
- case wlog_ind: ind *= WLOG_RANGE; ind += ptr->windowLog - ZSTD_WINDOWLOG_MIN ; break;
- case clog_ind: ind *= CLOG_RANGE; ind += ptr->chainLog - ZSTD_CHAINLOG_MIN ; break;
- case hlog_ind: ind *= HLOG_RANGE; ind += ptr->hashLog - ZSTD_HASHLOG_MIN ; break;
- case slog_ind: ind *= SLOG_RANGE; ind += ptr->searchLog - ZSTD_SEARCHLOG_MIN ; break;
- case slen_ind: ind *= SLEN_RANGE; ind += ptr->searchLength - ZSTD_SEARCHLENGTH_MIN; break;
- case tlen_ind: ind *= TLEN_RANGE; ind += tlen_inv(ptr->targetLength) - ZSTD_TARGETLENGTH_MIN; break;
+ case wlog_ind: ind *= WLOG_RANGE; ind += ptr->windowLog
+ - ZSTD_WINDOWLOG_MIN ; break;
+ case clog_ind: ind *= CLOG_RANGE; ind += ptr->chainLog
+ - ZSTD_CHAINLOG_MIN ; break;
+ case hlog_ind: ind *= HLOG_RANGE; ind += ptr->hashLog
+ - ZSTD_HASHLOG_MIN ; break;
+ case slog_ind: ind *= SLOG_RANGE; ind += ptr->searchLog
+ - ZSTD_SEARCHLOG_MIN ; break;
+ case slen_ind: ind *= SLEN_RANGE; ind += ptr->searchLength
+ - ZSTD_SEARCHLENGTH_MIN; break;
+ case tlen_ind: ind *= TLEN_RANGE; ind += tlen_inv(ptr->targetLength)
+ - ZSTD_TARGETLENGTH_MIN; break;
}
}
return ind;
}
}
-/* Initialize memotable, immediately mark redundant / obviously infeasible params as such */
-static void createMemoTable(U8* memoTable, ZSTD_compressionParameters paramConstraints, const constraint_t target, const varInds_t* varyParams, const int varyLen, const size_t srcSize) {
+/* Initialize memoization table, which tracks and prevents repeated benchmarking
+ * of the same set of parameters. In addition, it is also used to immediately mark
+ * redundant / obviously non-optimal parameter configurations (e.g. wlog - 1 larger)
+ * than srcSize, clog > wlog, ...
+ */
+static void initMemoTable(U8* memoTable, ZSTD_compressionParameters paramConstraints, const constraint_t target, const varInds_t* varyParams, const int varyLen, const size_t srcSize) {
size_t i;
size_t arrayLen = memoTableLen(varyParams, varyLen);
int cwFixed = !paramConstraints.chainLog || !paramConstraints.windowLog;
int whFixed = !paramConstraints.windowLog || !paramConstraints.hashLog;
int wFixed = !paramConstraints.windowLog;
int j = 0;
+ assert(memoTable != NULL);
memset(memoTable, 0, arrayLen);
cParamZeroMin(¶mConstraints);
memoTable[i] = 255;
j++;
}
- if(wFixed && (1ULL << paramConstraints.windowLog) > srcSize) {
+ if(wFixed && (1ULL << (paramConstraints.windowLog - 1)) > srcSize) {
memoTable[i] = 255;
}
/* nil out parameter sets equivalent to others. */
}
/* frees all allocated memotables */
-static void memoTableFreeAll(U8** mtAll) {
+static void freeMemoTableArray(U8** mtAll) {
int i;
if(mtAll == NULL) { return; }
for(i = 1; i <= (int)ZSTD_btultra; i++) {
const int varLenNew = sanitizeVarArray(varNew, varyLen, varyParams, i);
mtAll[i] = malloc(sizeof(U8) * memoTableLen(varNew, varLenNew));
if(mtAll[i] == NULL) {
- memoTableFreeAll(mtAll);
+ freeMemoTableArray(mtAll);
return NULL;
}
- createMemoTable(mtAll[i], paramConstraints, target, varNew, varLenNew, srcSize);
+ initMemoTable(mtAll[i], paramConstraints, target, varNew, varLenNew, srcSize);
}
return mtAll;
DISPLAY("Count: %d\n", bmcount);
bmcount++;
}
- BMK_printWinner(stdout, CUSTOM_LEVEL, *resultPtr, cParams, buf.srcSize);
+ BMK_printWinnerOpt(stdout, CUSTOM_LEVEL, *resultPtr, cParams, target, buf.srcSize);
if(res == BETTER_RESULT || feas) {
memoTable[memind] = 255;
better = 0;
DEBUGOUTPUT("Start\n");
cparam = winnerInfo.params;
- BMK_printWinner(stdout, CUSTOM_LEVEL, winnerInfo.result, winnerInfo.params, buf.srcSize);
+ BMK_printWinnerOpt(stdout, CUSTOM_LEVEL, winnerInfo.result, winnerInfo.params, target, buf.srcSize);
candidateInfo.params = cparam;
/* all dist-1 candidates */
for(i = 0; i < varLen; i++) {
varArray, varLen, feas);
if(res == BETTER_RESULT) { /* synonymous with better when called w/ infeasibleBM */
winnerInfo = candidateInfo;
- BMK_printWinner(stdout, CUSTOM_LEVEL, winnerInfo.result, winnerInfo.params, buf.srcSize);
+ BMK_printWinnerOpt(stdout, CUSTOM_LEVEL, winnerInfo.result, winnerInfo.params, target, buf.srcSize);
better = 1;
if(compareResultLT(bestFeasible1.result, winnerInfo.result, target, buf.srcSize)) {
bestFeasible1 = winnerInfo;
varArray, varLen, feas);
if(res == BETTER_RESULT) { /* synonymous with better in this case*/
winnerInfo = candidateInfo;
- BMK_printWinner(stdout, CUSTOM_LEVEL, winnerInfo.result, winnerInfo.params, buf.srcSize);
+ BMK_printWinnerOpt(stdout, CUSTOM_LEVEL, winnerInfo.result, winnerInfo.params, target, buf.srcSize);
better = 1;
if(compareResultLT(bestFeasible1.result, winnerInfo.result, target, buf.srcSize)) {
bestFeasible1 = winnerInfo;
candidateInfo = climbOnce(target, varNew, varLenNew, memoTable, buf, ctx, init);
if(compareResultLT(winnerInfo.result, candidateInfo.result, target, buf.srcSize)) {
winnerInfo = candidateInfo;
- BMK_printWinner(stdout, CUSTOM_LEVEL, winnerInfo.result, winnerInfo.params, buf.srcSize);
+ BMK_printWinnerOpt(stdout, CUSTOM_LEVEL, winnerInfo.result, winnerInfo.params, target, buf.srcSize);
i = 0;
}
i++;
goto _cleanUp;
}
- createMemoTable(allMT[paramTarget.strategy], paramTarget, target, varNew, varLenNew, maxBlockSize);
+ initMemoTable(allMT[paramTarget.strategy], paramTarget, target, varNew, varLenNew, maxBlockSize);
} else {
allMT = createMemoTableArray(paramTarget, target, varArray, varLen, maxBlockSize);
}
}
target.cSpeed = (U32)winner.result.cSpeed;
- g_targetConstraints = target;
- BMK_printWinner(stdout, cLevel, winner.result, winner.params, buf.srcSize);
+ BMK_printWinnerOpt(stdout, cLevel, winner.result, winner.params, target, buf.srcSize);
}
- g_targetConstraints = target;
-
/* bench */
DISPLAY("\r%79s\r", "");
if(nbFiles == 1) {
ZSTD_compressionParameters CParams = ZSTD_getCParams(i, maxBlockSize, ctx.dictSize);
CParams = maskParams(CParams, paramTarget);
ec = BMK_benchParam(&candidate, buf, ctx, CParams);
- BMK_printWinner(stdout, i, candidate, CParams, buf.srcSize);
+ BMK_printWinnerOpt(stdout, i, candidate, CParams, target, buf.srcSize);
if(!ec && compareResultLT(winner.result, candidate, relaxTarget(target), buf.srcSize)) {
winner.result = candidate;
}
}
- BMK_printWinner(stdout, CUSTOM_LEVEL, winner.result, winner.params, buf.srcSize);
+ BMK_printWinnerOpt(stdout, CUSTOM_LEVEL, winner.result, winner.params, target, buf.srcSize);
BMK_translateAdvancedParams(winner.params);
DEBUGOUTPUT("Real Opt\n");
/* start 'real' tests */
goto _cleanUp;
}
/* end summary */
- BMK_printWinner(stdout, CUSTOM_LEVEL, winner.result, winner.params, buf.srcSize);
+ BMK_printWinnerOpt(stdout, CUSTOM_LEVEL, winner.result, winner.params, target, buf.srcSize);
BMK_translateAdvancedParams(winner.params);
DISPLAY("grillParams size - optimizer completed \n");
_cleanUp:
freeContexts(ctx);
freeBuffers(buf);
- memoTableFreeAll(allMT);
+ freeMemoTableArray(allMT);
return ret;
}