L# - level
--zstd= : Single run, parameter selection syntax same as zstdcli
--optimize= : find parameters to maximize compression ratio given parameters
- Can use all --zstd= commands to constrain the type of solution found in addition to the following constraints
- cSpeed= - Minimum compression speed
- dSpeed= - Minimum decompression speed
- cMem= - compression memory
- lvl= - Searches for solutions which are strictly better than that compression lvl in ratio and cSpeed,
- stc= - When invoked with lvl=, represents slack in ratio/cSpeed allowed for a solution to be considered
- - In normal operation, represents slack in strategy selection in choosing the default parameters
- prefer[Speed/Ratio]= - Only affects lvl= invocations. Defines value placed on compression speed or ratio
- when determining overall winner (default 1 for both).
+ Can use all --zstd= commands to constrain the type of solution found in addition to the following constraints
+ cSpeed= : Minimum compression speed
+ dSpeed= : Minimum decompression speed
+ cMem= : Maximum compression memory
+ lvl= : Searches for solutions which are strictly better than that compression lvl in ratio and cSpeed,
+ stc= : When invoked with lvl=, represents percentage slack in ratio/cSpeed allowed for a solution to be considered (Default 99%)
+ : In normal operation, represents percentage slack in choosing viable starting strategy selection in choosing the default parameters
+ (Lower value will begin with stronger strategies) (Default 90%)
+ preferSpeed= / preferRatio=
+ : Only affects lvl = invocations. Defines value placed on compression speed or ratio
+ when determining overall winner (default 1 for both, higher = more valued).
+ tries= : Maximum number of random restarts on a single strategy before switching (Default 5)
+ Higher values will make optimizer run longer, more chances to find better solution.
--optimize= : same as -O with more verbose syntax
-P# : generated sample compressibility
-t# : Caps runtime of operation in seconds (default : 99999 seconds (about 27 hours ))
U32 cMem; /* bytes */
} constraint_t;
-static constraint_t g_targetConstraints;
-
-typedef struct ll_node ll_node;
-struct ll_node {
+typedef struct winner_ll_node winner_ll_node;
+struct winner_ll_node {
winnerInfo_t res;
- ll_node* next;
+ winner_ll_node* next;
};
-static ll_node* g_winners; /* linked list sorted ascending by cSize & cSpeed */
+static winner_ll_node* g_winners; /* linked list sorted ascending by cSize & cSpeed */
static BMK_result_t g_lvltarget;
static int g_optmode = 0;
static constraint_t relaxTarget(constraint_t target) {
target.cMem = (U32)-1;
- target.cSpeed *= ((double)(g_strictness) / 100);
- target.dSpeed *= ((double)(g_strictness) / 100);
+ target.cSpeed *= ((double)g_strictness) / 100;
+ target.dSpeed *= ((double)g_strictness) / 100;
return target;
}
return SPEED_RESULT; /* r2 is faster but not smaller */
}
}
-/* assumes candidate is already strictly better than old winner. */
-/* 0 for success, 1 for no insert */
-/* indicate whether inserted as well? */
+
+/* 0 for insertion, 1 for no insert */
/* maintain invariant speedSizeCompare(n, n->next) = SPEED_RESULT */
-static int insertWinner(winnerInfo_t w) {
+static int insertWinner(winnerInfo_t w, constraint_t targetConstraints) {
BMK_result_t r = w.result;
- ll_node* cur_node = g_winners;
+ winner_ll_node* cur_node = g_winners;
/* first node to insert */
- if(!feasible(r, g_targetConstraints)) {
+ if(!feasible(r, targetConstraints)) {
return 1;
}
if(g_winners == NULL) {
- ll_node* first_node = malloc(sizeof(ll_node));
+ winner_ll_node* first_node = malloc(sizeof(winner_ll_node));
if(first_node == NULL) {
return 1;
}
}
case WORSE_RESULT:
{
- ll_node* tmp;
+ winner_ll_node* tmp;
cur_node->res = cur_node->next->res;
tmp = cur_node->next;
cur_node->next = cur_node->next->next;
}
case SIZE_RESULT: /* insert after first size result, then return */
{
- ll_node* newnode = malloc(sizeof(ll_node));
+ winner_ll_node* newnode = malloc(sizeof(winner_ll_node));
if(newnode == NULL) {
return 1;
}
}
case SPEED_RESULT:
{
- ll_node* newnode = malloc(sizeof(ll_node));
+ winner_ll_node* newnode = malloc(sizeof(winner_ll_node));
if(newnode == NULL) {
return 1;
}
}
case SIZE_RESULT: /* insert before first size result, then return */
{
- ll_node* newnode = malloc(sizeof(ll_node));
+ winner_ll_node* newnode = malloc(sizeof(winner_ll_node));
if(newnode == NULL) {
return 1;
}
const U64 time = UTIL_clockSpanNano(g_time);
const U64 minutes = time / (60ULL * TIMELOOP_NANOSEC);
- DISPLAY("\r%79s\r", "");
+ fprintf(f, "\r%79s\r", "");
fprintf(f," {%3u,%3u,%3u,%3u,%3u,%3u, %s }, ",
params.windowLog, params.chainLog, params.hashLog, params.searchLog, params.searchLength,
//prints out tradeoff table if using lvl
if(g_optmode && g_optimizer) {
winnerInfo_t w;
- ll_node* n;
+ winner_ll_node* n;
w.result = result;
w.params = params;
- insertWinner(w);
+ insertWinner(w, targetConstraints);
if(!DEBUG) { fprintf(f, "\033c"); }
fprintf(f, "\n");
/* the table */
fprintf(f, "================================\n");
for(n = g_winners; n != NULL; n = n->next) {
- DISPLAY("\r%79s\r", "");
+ fprintf(f, "\r%79s\r", "");
fprintf(f," {%3u,%3u,%3u,%3u,%3u,%3u, %s }, ",
n->res.params.windowLog, n->res.params.chainLog, n->res.params.hashLog, n->res.params.searchLog, n->res.params.searchLength,
(double)srcSize / result.cSize, (double)result.cSpeed / (1 MB), (double)result.dSpeed / (1 MB));
}
+
+#if 0
+ if(BMK_timeSpan(g_time) > g_grillDuration_s) {
+ exit(0);
+ }
+#endif
}
static void BMK_printWinners2(FILE* f, const winnerInfo_t* winners, size_t srcSize)
* cLevel - compression level to exceed (all solutions must be > lvl in cSpeed + ratio)
*/
-#define MAX_TRIES 5
+static int g_maxTries = 5;
#define TRY_DECAY 1
static int optimizeForSize(const char* const * const fileNamesTable, const size_t nbFiles, const char* dictFileName, constraint_t target, ZSTD_compressionParameters paramTarget, int cLevel)
}
/* use level'ing mode instead of normal target mode */
+ /* Should lvl be parameter-masked here? */
if(g_optmode) {
winner.params = ZSTD_getCParams(cLevel, maxBlockSize, ctx.dictSize);
if(BMK_benchParam(&winner.result, buf, ctx, winner.params)) {
ret = 3;
goto _cleanUp;
}
-
- target.cSpeed = (U32)winner.result.cSpeed;
-
- g_targetConstraints = target;
-
+
g_lvltarget = winner.result;
- g_lvltarget.cSpeed *= ((double)(g_strictness) / 100);
- g_lvltarget.cSize /= ((double)(g_strictness) / 100);
+ g_lvltarget.cSpeed *= ((double)g_strictness) / 100;
+ g_lvltarget.dSpeed *= ((double)g_strictness) / 100;
+ g_lvltarget.cSize /= ((double)g_strictness) / 100;
+
+ target.cSpeed = (U32)g_lvltarget.cSpeed;
+ target.dSpeed = (U32)g_lvltarget.dSpeed; //See if this is worth
BMK_printWinnerOpt(stdout, cLevel, winner.result, winner.params, target, buf.srcSize);
}
}
/* if the current params are too slow, just stop. */
- if(target.cSpeed > candidate.cSpeed * 2) { break; }
+ if(target.cSpeed > candidate.cSpeed * 3 / 2) { break; }
}
}
}
int bestStrategy = (int)winner.params.strategy;
if(paramTarget.strategy == 0) {
int st = (int)winner.params.strategy;
- int tries = MAX_TRIES;
+ int tries = g_maxTries;
{
/* one iterations of hill climbing with the level-defined parameters. */
while(st && tries > 0) {
winnerInfo_t wc;
DEBUGOUTPUT("StrategySwitch: %s\n", g_stratName[st]);
+
wc = optimizeFixedStrategy(buf, ctx, target, paramTarget,
st, varArray, varLen, allMT[st], tries);
if(compareResultLT(winner.result, wc.result, target, buf.srcSize)) {
winner = wc;
- tries = MAX_TRIES;
+ tries = g_maxTries;
bestStrategy = st;
} else {
st = nextStrategy(st, bestStrategy);
}
} else {
winner = optimizeFixedStrategy(buf, ctx, target, paramTarget, paramTarget.strategy,
- varArray, varLen, allMT[paramTarget.strategy], 10);
+ varArray, varLen, allMT[paramTarget.strategy], g_maxTries);
}
}
ZSTD_compressionParameters paramTarget = { 0, 0, 0, 0, 0, 0, 0 };
- assert(argc>=1); /* for exename */
-
g_time = UTIL_getTime();
+ assert(argc>=1); /* for exename */
+
/* Welcome message */
DISPLAY(WELCOME_MESSAGE);
for(i=1; i<argc; i++) {
const char* argument = argv[i];
- DISPLAY("%d: ", i);
- DISPLAY("%s\n", argument);
+ DEBUGOUTPUT("%d: ", i);
+ DEBUGOUTPUT("%s\n", argument);
assert(argument != NULL);
PARSE_SUB_ARGS("strict=", "stc=", g_strictness);
PARSE_SUB_ARGS("preferSpeed=", "prfSpd=", g_speedMultiplier);
PARSE_SUB_ARGS("preferRatio=", "prfRto=", g_ratioMultiplier);
+ PARSE_SUB_ARGS("maxTries", "tries", g_maxTries);
DISPLAY("invalid optimization parameter \n");
return 1;