2017-08-18 23:52:05 +00:00
|
|
|
/*
|
2020-03-26 22:19:05 +00:00
|
|
|
* Copyright (c) 2015-2020, Yann Collet, Facebook, Inc.
|
2016-08-30 17:04:33 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
2017-08-18 23:52:05 +00:00
|
|
|
* This source code is licensed under both the BSD-style license (found in the
|
|
|
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
|
|
|
* in the COPYING file in the root directory of this source tree).
|
2017-09-08 07:09:23 +00:00
|
|
|
* You may select, at your option, one of the above-listed licenses.
|
2016-08-30 17:04:33 +00:00
|
|
|
*/
|
2015-10-25 23:06:36 +00:00
|
|
|
|
|
|
|
|
2016-02-10 12:37:52 +00:00
|
|
|
/*-************************************
|
|
|
|
* Dependencies
|
2015-10-25 23:06:36 +00:00
|
|
|
**************************************/
|
2018-12-20 22:54:05 +00:00
|
|
|
#include "util.h" /* Ensure platform.h is compiled first; also : compiler options, UTIL_GetFileSize */
|
2016-07-13 14:45:24 +00:00
|
|
|
#include <stdlib.h> /* malloc */
|
|
|
|
#include <stdio.h> /* fprintf, fopen, ftello64 */
|
|
|
|
#include <string.h> /* strcmp */
|
|
|
|
#include <math.h> /* log */
|
2018-05-12 00:32:26 +00:00
|
|
|
#include <assert.h>
|
2015-10-25 23:06:36 +00:00
|
|
|
|
2019-04-10 19:37:03 +00:00
|
|
|
#include "timefn.h" /* SEC_TO_MICRO, UTIL_time_t, UTIL_clockSpanMicro, UTIL_clockSpanNano, UTIL_getTime */
|
2015-10-25 23:06:36 +00:00
|
|
|
#include "mem.h"
|
2016-07-11 01:12:17 +00:00
|
|
|
#define ZSTD_STATIC_LINKING_ONLY /* ZSTD_parameters, ZSTD_estimateCCtxSize */
|
2016-06-04 17:47:02 +00:00
|
|
|
#include "zstd.h"
|
2015-10-25 23:06:36 +00:00
|
|
|
#include "datagen.h"
|
|
|
|
#include "xxhash.h"
|
2018-11-13 19:01:59 +00:00
|
|
|
#include "benchfn.h"
|
|
|
|
#include "benchzstd.h"
|
2018-07-16 23:16:31 +00:00
|
|
|
#include "zstd_errors.h"
|
2018-08-24 01:04:50 +00:00
|
|
|
#include "zstd_internal.h" /* should not be needed */
|
|
|
|
|
2015-10-25 23:06:36 +00:00
|
|
|
|
2016-02-10 12:37:52 +00:00
|
|
|
/*-************************************
|
2015-10-25 23:06:36 +00:00
|
|
|
* Constants
|
|
|
|
**************************************/
|
2016-04-28 12:40:45 +00:00
|
|
|
#define PROGRAM_DESCRIPTION "ZSTD parameters tester"
|
2015-10-25 23:06:36 +00:00
|
|
|
#define AUTHOR "Yann Collet"
|
2018-05-12 00:32:26 +00:00
|
|
|
#define WELCOME_MESSAGE "*** %s %s %i-bits, by %s ***\n", PROGRAM_DESCRIPTION, ZSTD_VERSION_STRING, (int)(sizeof(void*)*8), AUTHOR
|
2015-10-25 23:06:36 +00:00
|
|
|
|
2018-06-18 18:59:45 +00:00
|
|
|
#define TIMELOOP_NANOSEC (1*1000000000ULL) /* 1 second */
|
2018-05-14 00:25:53 +00:00
|
|
|
#define NB_LEVELS_TRACKED 22 /* ensured being >= ZSTD_maxCLevel() in BMK_init_level_constraints() */
|
2015-10-25 23:06:36 +00:00
|
|
|
|
2015-11-27 16:52:57 +00:00
|
|
|
static const size_t maxMemory = (sizeof(size_t)==4) ? (2 GB - 64 MB) : (size_t)(1ULL << ((sizeof(size_t)*8)-31));
|
2015-10-25 23:06:36 +00:00
|
|
|
|
|
|
|
#define COMPRESSIBILITY_DEFAULT 0.50
|
|
|
|
|
2017-11-30 03:11:12 +00:00
|
|
|
static const U64 g_maxVariationTime = 60 * SEC_TO_MICRO;
|
2015-10-27 11:18:00 +00:00
|
|
|
static const int g_maxNbVariations = 64;
|
2015-10-25 23:06:36 +00:00
|
|
|
|
2018-08-24 01:04:50 +00:00
|
|
|
|
2016-02-10 12:37:52 +00:00
|
|
|
/*-************************************
|
2015-10-25 23:06:36 +00:00
|
|
|
* Macros
|
|
|
|
**************************************/
|
|
|
|
#define DISPLAY(...) fprintf(stderr, __VA_ARGS__)
|
2018-08-14 21:24:05 +00:00
|
|
|
#define DISPLAYLEVEL(n, ...) if(g_displayLevel >= n) { fprintf(stderr, __VA_ARGS__); }
|
2018-08-15 21:00:57 +00:00
|
|
|
#define DEBUGOUTPUT(...) { if (DEBUG) DISPLAY(__VA_ARGS__); }
|
2018-08-14 21:24:05 +00:00
|
|
|
|
2018-07-13 00:30:39 +00:00
|
|
|
#define TIMED 0
|
|
|
|
#ifndef DEBUG
|
2018-07-20 21:35:09 +00:00
|
|
|
# define DEBUG 0
|
2018-07-13 00:30:39 +00:00
|
|
|
#endif
|
2015-10-25 23:06:36 +00:00
|
|
|
|
2017-04-18 00:57:35 +00:00
|
|
|
#undef MIN
|
|
|
|
#undef MAX
|
|
|
|
#define MIN(a,b) ( (a) < (b) ? (a) : (b) )
|
|
|
|
#define MAX(a,b) ( (a) > (b) ? (a) : (b) )
|
2018-06-04 23:32:37 +00:00
|
|
|
#define CUSTOM_LEVEL 99
|
2018-08-13 23:38:51 +00:00
|
|
|
#define BASE_CLEVEL 1
|
2015-10-25 23:06:36 +00:00
|
|
|
|
2018-08-09 17:42:35 +00:00
|
|
|
#define FADT_MIN 0
|
|
|
|
#define FADT_MAX ((U32)-1)
|
2018-06-18 18:59:45 +00:00
|
|
|
|
|
|
|
#define WLOG_RANGE (ZSTD_WINDOWLOG_MAX - ZSTD_WINDOWLOG_MIN + 1)
|
|
|
|
#define CLOG_RANGE (ZSTD_CHAINLOG_MAX - ZSTD_CHAINLOG_MIN + 1)
|
|
|
|
#define HLOG_RANGE (ZSTD_HASHLOG_MAX - ZSTD_HASHLOG_MIN + 1)
|
|
|
|
#define SLOG_RANGE (ZSTD_SEARCHLOG_MAX - ZSTD_SEARCHLOG_MIN + 1)
|
2018-12-06 23:00:52 +00:00
|
|
|
#define MML_RANGE (ZSTD_MINMATCH_MAX - ZSTD_MINMATCH_MIN + 1)
|
|
|
|
#define TLEN_RANGE 17
|
2018-12-07 00:16:16 +00:00
|
|
|
#define STRT_RANGE (ZSTD_STRATEGY_MAX - ZSTD_STRATEGY_MIN + 1)
|
2018-12-06 23:00:52 +00:00
|
|
|
#define FADT_RANGE 3
|
2018-06-18 18:59:45 +00:00
|
|
|
|
2018-12-07 22:07:54 +00:00
|
|
|
#define CHECKTIME(r) { if(BMK_timeSpan_s(g_time) > g_timeLimit_s) { DEBUGOUTPUT("Time Limit Reached\n"); return r; } }
|
|
|
|
#define CHECKTIMEGT(ret, val, _gototag) { if(BMK_timeSpan_s(g_time) > g_timeLimit_s) { DEBUGOUTPUT("Time Limit Reached\n"); ret = val; goto _gototag; } }
|
2018-08-06 23:52:17 +00:00
|
|
|
|
2018-08-10 23:14:12 +00:00
|
|
|
#define PARAM_UNSET ((U32)-2) /* can't be -1 b/c fadt uses -1 */
|
|
|
|
|
2018-12-07 00:16:16 +00:00
|
|
|
static const char* g_stratName[ZSTD_STRATEGY_MAX+1] = {
|
2018-08-10 23:14:12 +00:00
|
|
|
"(none) ", "ZSTD_fast ", "ZSTD_dfast ",
|
|
|
|
"ZSTD_greedy ", "ZSTD_lazy ", "ZSTD_lazy2 ",
|
2018-12-06 23:00:52 +00:00
|
|
|
"ZSTD_btlazy2 ", "ZSTD_btopt ", "ZSTD_btultra ",
|
|
|
|
"ZSTD_btultra2"};
|
2018-08-10 23:14:12 +00:00
|
|
|
|
|
|
|
static const U32 tlen_table[TLEN_RANGE] = { 0, 1, 2, 4, 6, 8, 12, 16, 24, 32, 48, 64, 96, 128, 256, 512, 999 };
|
2018-08-09 17:42:35 +00:00
|
|
|
|
2018-08-24 01:04:50 +00:00
|
|
|
|
2018-08-09 17:42:35 +00:00
|
|
|
/*-************************************
|
|
|
|
* Setup for Adding new params
|
|
|
|
**************************************/
|
|
|
|
|
|
|
|
/* indices for each of the variables */
|
|
|
|
typedef enum {
|
|
|
|
wlog_ind = 0,
|
|
|
|
clog_ind = 1,
|
|
|
|
hlog_ind = 2,
|
|
|
|
slog_ind = 3,
|
2018-11-20 22:56:07 +00:00
|
|
|
mml_ind = 4,
|
2018-08-09 17:42:35 +00:00
|
|
|
tlen_ind = 5,
|
|
|
|
strt_ind = 6,
|
|
|
|
fadt_ind = 7, /* forceAttachDict */
|
|
|
|
NUM_PARAMS = 8
|
|
|
|
} varInds_t;
|
|
|
|
|
2018-08-10 23:14:12 +00:00
|
|
|
typedef struct {
|
|
|
|
U32 vals[NUM_PARAMS];
|
|
|
|
} paramValues_t;
|
|
|
|
|
2018-12-06 23:00:52 +00:00
|
|
|
/* minimum value of parameters */
|
2018-08-22 01:19:27 +00:00
|
|
|
static const U32 mintable[NUM_PARAMS] =
|
2018-12-07 00:16:16 +00:00
|
|
|
{ ZSTD_WINDOWLOG_MIN, ZSTD_CHAINLOG_MIN, ZSTD_HASHLOG_MIN, ZSTD_SEARCHLOG_MIN, ZSTD_MINMATCH_MIN, ZSTD_TARGETLENGTH_MIN, ZSTD_STRATEGY_MIN, FADT_MIN };
|
2018-08-09 17:42:35 +00:00
|
|
|
|
2018-12-06 23:00:52 +00:00
|
|
|
/* maximum value of parameters */
|
2018-08-22 01:19:27 +00:00
|
|
|
static const U32 maxtable[NUM_PARAMS] =
|
2018-12-07 00:16:16 +00:00
|
|
|
{ ZSTD_WINDOWLOG_MAX, ZSTD_CHAINLOG_MAX, ZSTD_HASHLOG_MAX, ZSTD_SEARCHLOG_MAX, ZSTD_MINMATCH_MAX, ZSTD_TARGETLENGTH_MAX, ZSTD_STRATEGY_MAX, FADT_MAX };
|
2018-08-09 17:42:35 +00:00
|
|
|
|
|
|
|
/* # of values parameters can take on */
|
2018-08-22 01:19:27 +00:00
|
|
|
static const U32 rangetable[NUM_PARAMS] =
|
2018-11-20 22:56:07 +00:00
|
|
|
{ WLOG_RANGE, CLOG_RANGE, HLOG_RANGE, SLOG_RANGE, MML_RANGE, TLEN_RANGE, STRT_RANGE, FADT_RANGE };
|
2018-08-09 17:42:35 +00:00
|
|
|
|
2018-08-10 23:14:12 +00:00
|
|
|
/* ZSTD_cctxSetParameter() index to set */
|
2018-08-22 01:19:27 +00:00
|
|
|
static const ZSTD_cParameter cctxSetParamTable[NUM_PARAMS] =
|
2018-12-06 23:00:52 +00:00
|
|
|
{ ZSTD_c_windowLog, ZSTD_c_chainLog, ZSTD_c_hashLog, ZSTD_c_searchLog, ZSTD_c_minMatch, ZSTD_c_targetLength, ZSTD_c_strategy, ZSTD_c_forceAttachDict };
|
2018-08-09 17:42:35 +00:00
|
|
|
|
2018-08-10 23:14:12 +00:00
|
|
|
/* names of parameters */
|
2018-08-22 01:19:27 +00:00
|
|
|
static const char* g_paramNames[NUM_PARAMS] =
|
2018-11-20 22:56:07 +00:00
|
|
|
{ "windowLog", "chainLog", "hashLog","searchLog", "minMatch", "targetLength", "strategy", "forceAttachDict" };
|
2018-08-09 17:42:35 +00:00
|
|
|
|
2018-08-10 23:14:12 +00:00
|
|
|
/* shortened names of parameters */
|
2018-08-22 01:19:27 +00:00
|
|
|
static const char* g_shortParamNames[NUM_PARAMS] =
|
2018-11-20 22:56:07 +00:00
|
|
|
{ "wlog", "clog", "hlog", "slog", "mml", "tlen", "strat", "fadt" };
|
2018-08-09 17:42:35 +00:00
|
|
|
|
2018-08-10 23:14:12 +00:00
|
|
|
/* maps value from { 0 to rangetable[param] - 1 } to valid paramvalues */
|
2018-12-07 22:07:54 +00:00
|
|
|
static U32 rangeMap(varInds_t param, int ind)
|
|
|
|
{
|
2019-01-25 23:38:08 +00:00
|
|
|
U32 const uind = (U32)MAX(MIN(ind, (int)rangetable[param] - 1), 0);
|
2018-08-09 17:42:35 +00:00
|
|
|
switch(param) {
|
|
|
|
case wlog_ind: /* using default: triggers -Wswitch-enum */
|
|
|
|
case clog_ind:
|
|
|
|
case hlog_ind:
|
|
|
|
case slog_ind:
|
2018-11-20 22:56:07 +00:00
|
|
|
case mml_ind:
|
2018-08-09 17:42:35 +00:00
|
|
|
case strt_ind:
|
2019-01-25 23:38:08 +00:00
|
|
|
return mintable[param] + uind;
|
2018-12-07 22:07:54 +00:00
|
|
|
case tlen_ind:
|
2019-01-25 23:38:08 +00:00
|
|
|
return tlen_table[uind];
|
2018-12-07 22:07:54 +00:00
|
|
|
case fadt_ind: /* 0, 1, 2 -> -1, 0, 1 */
|
2019-01-25 23:38:08 +00:00
|
|
|
return uind - 1;
|
2018-08-09 17:42:35 +00:00
|
|
|
case NUM_PARAMS:
|
2018-12-07 22:07:54 +00:00
|
|
|
default:;
|
2018-08-09 17:42:35 +00:00
|
|
|
}
|
2018-12-07 22:07:54 +00:00
|
|
|
DISPLAY("Error, not a valid param\n ");
|
|
|
|
assert(0);
|
|
|
|
return (U32)-1;
|
2018-08-09 17:42:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* inverse of rangeMap */
|
2018-12-07 22:07:54 +00:00
|
|
|
static int invRangeMap(varInds_t param, U32 value)
|
|
|
|
{
|
2018-08-09 17:42:35 +00:00
|
|
|
value = MIN(MAX(mintable[param], value), maxtable[param]);
|
|
|
|
switch(param) {
|
2018-12-07 22:07:54 +00:00
|
|
|
case wlog_ind:
|
|
|
|
case clog_ind:
|
|
|
|
case hlog_ind:
|
|
|
|
case slog_ind:
|
|
|
|
case mml_ind:
|
|
|
|
case strt_ind:
|
2019-01-25 23:38:08 +00:00
|
|
|
return (int)(value - mintable[param]);
|
2018-08-09 17:42:35 +00:00
|
|
|
case tlen_ind: /* bin search */
|
|
|
|
{
|
|
|
|
int lo = 0;
|
|
|
|
int hi = TLEN_RANGE;
|
|
|
|
while(lo < hi) {
|
|
|
|
int mid = (lo + hi) / 2;
|
|
|
|
if(tlen_table[mid] < value) {
|
|
|
|
lo = mid + 1;
|
|
|
|
} if(tlen_table[mid] == value) {
|
|
|
|
return mid;
|
|
|
|
} else {
|
|
|
|
hi = mid;
|
|
|
|
}
|
|
|
|
}
|
2018-08-22 01:19:27 +00:00
|
|
|
return lo;
|
2018-08-09 17:42:35 +00:00
|
|
|
}
|
|
|
|
case fadt_ind:
|
2018-08-15 18:46:19 +00:00
|
|
|
return (int)value + 1;
|
2018-08-09 17:42:35 +00:00
|
|
|
case NUM_PARAMS:
|
2018-12-07 22:07:54 +00:00
|
|
|
default:;
|
2018-08-09 17:42:35 +00:00
|
|
|
}
|
2018-12-07 22:07:54 +00:00
|
|
|
DISPLAY("Error, not a valid param\n ");
|
|
|
|
assert(0);
|
|
|
|
return -2;
|
2018-08-09 17:42:35 +00:00
|
|
|
}
|
|
|
|
|
2018-08-10 23:14:12 +00:00
|
|
|
/* display of params */
|
fix confusion between unsigned <-> U32
as suggested in #1441.
generally U32 and unsigned are the same thing,
except when they are not ...
case : 32-bit compilation for MIPS (uint32_t == unsigned long)
A vast majority of transformation consists in transforming U32 into unsigned.
In rare cases, it's the other way around (typically for internal code, such as seeds).
Among a few issues this patches solves :
- some parameters were declared with type `unsigned` in *.h,
but with type `U32` in their implementation *.c .
- some parameters have type unsigned*,
but the caller user a pointer to U32 instead.
These fixes are useful.
However, the bulk of changes is about %u formating,
which requires unsigned type,
but generally receives U32 values instead,
often just for brevity (U32 is shorter than unsigned).
These changes are generally minor, or even annoying.
As a consequence, the amount of code changed is larger than I would expect for such a patch.
Testing is also a pain :
it requires manually modifying `mem.h`,
in order to lie about `U32`
and force it to be an `unsigned long` typically.
On a 64-bit system, this will break the equivalence unsigned == U32.
Unfortunately, it will also break a few static_assert(), controlling structure sizes.
So it also requires modifying `debug.h` to make `static_assert()` a noop.
And then reverting these changes.
So it's inconvenient, and as a consequence,
this property is currently not checked during CI tests.
Therefore, these problems can emerge again in the future.
I wonder if it is worth ensuring proper distinction of U32 != unsigned in CI tests.
It's another restriction for coding, adding more frustration during merge tests,
since most platforms don't need this distinction (hence contributor will not see it),
and while this can matter in theory, the number of platforms impacted seems minimal.
Thoughts ?
2018-12-22 00:19:44 +00:00
|
|
|
static void displayParamVal(FILE* f, varInds_t param, unsigned value, int width)
|
2018-12-07 22:07:54 +00:00
|
|
|
{
|
2018-08-10 23:14:12 +00:00
|
|
|
switch(param) {
|
2018-08-22 01:19:27 +00:00
|
|
|
case wlog_ind:
|
|
|
|
case clog_ind:
|
|
|
|
case hlog_ind:
|
|
|
|
case slog_ind:
|
2018-11-20 22:56:07 +00:00
|
|
|
case mml_ind:
|
2018-12-07 22:07:54 +00:00
|
|
|
case tlen_ind:
|
|
|
|
if(width) {
|
|
|
|
fprintf(f, "%*u", width, value);
|
|
|
|
} else {
|
|
|
|
fprintf(f, "%u", value);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case strt_ind:
|
|
|
|
if(width) {
|
|
|
|
fprintf(f, "%*s", width, g_stratName[value]);
|
|
|
|
} else {
|
|
|
|
fprintf(f, "%s", g_stratName[value]);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case fadt_ind: /* force attach dict */
|
|
|
|
if(width) {
|
|
|
|
fprintf(f, "%*d", width, (int)value);
|
|
|
|
} else {
|
|
|
|
fprintf(f, "%d", (int)value);
|
|
|
|
}
|
|
|
|
break;
|
2018-08-10 23:14:12 +00:00
|
|
|
case NUM_PARAMS:
|
2018-12-07 22:07:54 +00:00
|
|
|
default:
|
|
|
|
DISPLAY("Error, not a valid param\n ");
|
|
|
|
assert(0);
|
|
|
|
break;
|
2018-08-10 23:14:12 +00:00
|
|
|
}
|
2018-08-09 17:42:35 +00:00
|
|
|
}
|
|
|
|
|
2018-08-24 01:04:50 +00:00
|
|
|
|
2016-02-10 12:37:52 +00:00
|
|
|
/*-************************************
|
2018-07-31 00:42:46 +00:00
|
|
|
* Benchmark Parameters/Global Variables
|
2015-10-25 23:06:36 +00:00
|
|
|
**************************************/
|
2018-06-04 23:32:37 +00:00
|
|
|
|
2018-08-15 21:00:57 +00:00
|
|
|
/* General Utility */
|
2018-08-06 23:52:17 +00:00
|
|
|
static U32 g_timeLimit_s = 99999; /* about 27 hours */
|
2018-08-15 21:00:57 +00:00
|
|
|
static UTIL_time_t g_time; /* to be used to compare solution finding speeds to compare to original */
|
2015-10-25 23:06:36 +00:00
|
|
|
static U32 g_blockSize = 0;
|
2015-10-26 14:45:58 +00:00
|
|
|
static U32 g_rand = 1;
|
2018-08-15 21:00:57 +00:00
|
|
|
|
|
|
|
/* Display */
|
|
|
|
static int g_displayLevel = 3;
|
2018-12-07 22:07:54 +00:00
|
|
|
static BYTE g_silenceParams[NUM_PARAMS]; /* can selectively silence some params when displaying them */
|
2018-08-15 21:00:57 +00:00
|
|
|
|
|
|
|
/* Mode Selection */
|
2015-10-27 01:59:12 +00:00
|
|
|
static U32 g_singleRun = 0;
|
2018-07-27 21:19:55 +00:00
|
|
|
static U32 g_optimizer = 0;
|
2018-08-15 21:00:57 +00:00
|
|
|
static int g_optmode = 0;
|
|
|
|
|
|
|
|
/* For cLevel Table generation */
|
2015-10-27 11:18:00 +00:00
|
|
|
static U32 g_target = 0;
|
2015-10-27 12:12:25 +00:00
|
|
|
static U32 g_noSeed = 0;
|
2018-08-13 19:51:22 +00:00
|
|
|
|
2018-08-15 21:00:57 +00:00
|
|
|
/* For optimizer */
|
|
|
|
static paramValues_t g_params; /* Initialized at the beginning of main w/ emptyParams() function */
|
|
|
|
static double g_ratioMultiplier = 5.;
|
2018-08-15 21:57:10 +00:00
|
|
|
static U32 g_strictness = PARAM_UNSET; /* range 1 - 100, measure of how strict */
|
2018-08-24 00:21:38 +00:00
|
|
|
static BMK_benchResult_t g_lvltarget;
|
2018-08-15 01:04:58 +00:00
|
|
|
|
2018-08-13 19:51:22 +00:00
|
|
|
typedef enum {
|
|
|
|
directMap,
|
|
|
|
xxhashMap,
|
|
|
|
noMemo
|
|
|
|
} memoTableType_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
memoTableType_t tableType;
|
|
|
|
BYTE* table;
|
|
|
|
size_t tableLen;
|
|
|
|
varInds_t varArray[NUM_PARAMS];
|
|
|
|
size_t varLen;
|
|
|
|
} memoTable_t;
|
2018-07-25 18:37:20 +00:00
|
|
|
|
|
|
|
typedef struct {
|
2018-08-24 00:21:38 +00:00
|
|
|
BMK_benchResult_t result;
|
2018-08-09 17:42:35 +00:00
|
|
|
paramValues_t params;
|
2018-07-25 18:37:20 +00:00
|
|
|
} winnerInfo_t;
|
|
|
|
|
|
|
|
typedef struct {
|
2018-07-27 18:47:14 +00:00
|
|
|
U32 cSpeed; /* bytes / sec */
|
2018-07-25 18:37:20 +00:00
|
|
|
U32 dSpeed;
|
2018-08-22 01:19:27 +00:00
|
|
|
U32 cMem; /* bytes */
|
2018-07-25 18:37:20 +00:00
|
|
|
} constraint_t;
|
|
|
|
|
2018-07-27 23:49:33 +00:00
|
|
|
typedef struct winner_ll_node winner_ll_node;
|
|
|
|
struct winner_ll_node {
|
2018-07-25 18:37:20 +00:00
|
|
|
winnerInfo_t res;
|
2018-07-27 23:49:33 +00:00
|
|
|
winner_ll_node* next;
|
2018-07-25 18:37:20 +00:00
|
|
|
};
|
|
|
|
|
2018-07-27 23:49:33 +00:00
|
|
|
static winner_ll_node* g_winners; /* linked list sorted ascending by cSize & cSpeed */
|
2015-10-25 23:06:36 +00:00
|
|
|
|
2018-07-31 00:42:46 +00:00
|
|
|
/*
|
|
|
|
* Additional Global Variables (Defined Above Use)
|
|
|
|
* g_level_constraint
|
|
|
|
* g_alreadyTested
|
|
|
|
* g_maxTries
|
2018-08-15 21:00:57 +00:00
|
|
|
* g_clockGranularity
|
2018-07-31 00:42:46 +00:00
|
|
|
*/
|
|
|
|
|
2018-08-24 01:04:50 +00:00
|
|
|
|
2016-02-10 12:37:52 +00:00
|
|
|
/*-*******************************************************
|
2018-08-22 01:19:27 +00:00
|
|
|
* General Util Functions
|
2015-10-25 23:06:36 +00:00
|
|
|
*********************************************************/
|
|
|
|
|
2018-08-15 21:57:10 +00:00
|
|
|
/* nullified useless params, to ensure count stats */
|
|
|
|
/* cleans up params for memoizing / display */
|
|
|
|
static paramValues_t sanitizeParams(paramValues_t params)
|
|
|
|
{
|
|
|
|
if (params.vals[strt_ind] == ZSTD_fast)
|
|
|
|
params.vals[clog_ind] = 0, params.vals[slog_ind] = 0;
|
|
|
|
if (params.vals[strt_ind] == ZSTD_dfast)
|
|
|
|
params.vals[slog_ind] = 0;
|
2018-12-06 23:00:52 +00:00
|
|
|
if ( (params.vals[strt_ind] < ZSTD_btopt) && (params.vals[strt_ind] != ZSTD_fast) )
|
2018-08-15 21:57:10 +00:00
|
|
|
params.vals[tlen_ind] = 0;
|
|
|
|
|
|
|
|
return params;
|
|
|
|
}
|
|
|
|
|
2018-12-07 22:07:54 +00:00
|
|
|
static ZSTD_compressionParameters pvalsToCParams(paramValues_t p)
|
|
|
|
{
|
2018-08-10 23:14:12 +00:00
|
|
|
ZSTD_compressionParameters c;
|
|
|
|
memset(&c, 0, sizeof(ZSTD_compressionParameters));
|
|
|
|
c.windowLog = p.vals[wlog_ind];
|
|
|
|
c.chainLog = p.vals[clog_ind];
|
|
|
|
c.hashLog = p.vals[hlog_ind];
|
|
|
|
c.searchLog = p.vals[slog_ind];
|
2018-11-20 22:56:07 +00:00
|
|
|
c.minMatch = p.vals[mml_ind];
|
2018-08-10 23:14:12 +00:00
|
|
|
c.targetLength = p.vals[tlen_ind];
|
|
|
|
c.strategy = p.vals[strt_ind];
|
|
|
|
/* no forceAttachDict */
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2018-12-07 22:07:54 +00:00
|
|
|
static paramValues_t cParamsToPVals(ZSTD_compressionParameters c)
|
|
|
|
{
|
2018-08-10 23:14:12 +00:00
|
|
|
paramValues_t p;
|
|
|
|
varInds_t i;
|
|
|
|
p.vals[wlog_ind] = c.windowLog;
|
|
|
|
p.vals[clog_ind] = c.chainLog;
|
|
|
|
p.vals[hlog_ind] = c.hashLog;
|
|
|
|
p.vals[slog_ind] = c.searchLog;
|
2018-11-20 22:56:07 +00:00
|
|
|
p.vals[mml_ind] = c.minMatch;
|
2018-08-10 23:14:12 +00:00
|
|
|
p.vals[tlen_ind] = c.targetLength;
|
|
|
|
p.vals[strt_ind] = c.strategy;
|
|
|
|
|
|
|
|
/* set all other params to their minimum value */
|
2018-12-07 22:07:54 +00:00
|
|
|
for (i = strt_ind + 1; i < NUM_PARAMS; i++) {
|
2018-08-10 23:14:12 +00:00
|
|
|
p.vals[i] = mintable[i];
|
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* equivalent of ZSTD_adjustCParams for paramValues_t */
|
2018-12-07 22:07:54 +00:00
|
|
|
static paramValues_t
|
|
|
|
adjustParams(paramValues_t p, const size_t maxBlockSize, const size_t dictSize)
|
|
|
|
{
|
2018-08-10 23:14:12 +00:00
|
|
|
paramValues_t ot = p;
|
|
|
|
varInds_t i;
|
|
|
|
p = cParamsToPVals(ZSTD_adjustCParams(pvalsToCParams(p), maxBlockSize, dictSize));
|
2018-12-08 00:02:24 +00:00
|
|
|
if (!dictSize) { p.vals[fadt_ind] = 0; }
|
2018-08-10 23:14:12 +00:00
|
|
|
/* retain value of all other parameters */
|
|
|
|
for(i = strt_ind + 1; i < NUM_PARAMS; i++) {
|
|
|
|
p.vals[i] = ot.vals[i];
|
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2015-10-25 23:06:36 +00:00
|
|
|
static size_t BMK_findMaxMem(U64 requiredMem)
|
|
|
|
{
|
2016-07-13 14:45:24 +00:00
|
|
|
size_t const step = 64 MB;
|
|
|
|
void* testmem = NULL;
|
2015-10-25 23:06:36 +00:00
|
|
|
|
|
|
|
requiredMem = (((requiredMem >> 26) + 1) << 26);
|
2015-11-27 16:52:57 +00:00
|
|
|
if (requiredMem > maxMemory) requiredMem = maxMemory;
|
2015-10-25 23:06:36 +00:00
|
|
|
|
2018-08-14 18:57:15 +00:00
|
|
|
requiredMem += 2 * step;
|
|
|
|
while (!testmem && requiredMem > 0) {
|
2016-07-13 14:45:24 +00:00
|
|
|
testmem = malloc ((size_t)requiredMem);
|
2018-08-14 18:57:15 +00:00
|
|
|
requiredMem -= step;
|
2015-10-25 23:06:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
free (testmem);
|
2018-08-14 18:57:15 +00:00
|
|
|
return (size_t) requiredMem;
|
2015-10-25 23:06:36 +00:00
|
|
|
}
|
|
|
|
|
2018-08-15 21:57:10 +00:00
|
|
|
/* accuracy in seconds only, span can be multiple years */
|
2018-12-07 22:07:54 +00:00
|
|
|
static U32 BMK_timeSpan_s(const UTIL_time_t tStart)
|
|
|
|
{
|
|
|
|
return (U32)(UTIL_clockSpanMicro(tStart) / 1000000ULL);
|
|
|
|
}
|
2015-10-25 23:06:36 +00:00
|
|
|
|
2017-04-04 22:35:06 +00:00
|
|
|
static U32 FUZ_rotl32(U32 x, U32 r)
|
|
|
|
{
|
|
|
|
return ((x << r) | (x >> (32 - r)));
|
|
|
|
}
|
|
|
|
|
2018-09-27 22:13:43 +00:00
|
|
|
static U32 FUZ_rand(U32* src)
|
2015-10-25 23:06:36 +00:00
|
|
|
{
|
|
|
|
const U32 prime1 = 2654435761U;
|
|
|
|
const U32 prime2 = 2246822519U;
|
|
|
|
U32 rand32 = *src;
|
|
|
|
rand32 *= prime1;
|
|
|
|
rand32 += prime2;
|
|
|
|
rand32 = FUZ_rotl32(rand32, 13);
|
|
|
|
*src = rand32;
|
|
|
|
return rand32 >> 5;
|
|
|
|
}
|
|
|
|
|
2018-12-07 22:07:54 +00:00
|
|
|
#define BOUNDCHECK(val,min,max) { \
|
2018-08-09 17:42:35 +00:00
|
|
|
if (((val)<(min)) | ((val)>(max))) { \
|
2018-06-18 18:59:45 +00:00
|
|
|
DISPLAY("INVALID PARAMETER CONSTRAINTS\n"); \
|
|
|
|
return 0; \
|
|
|
|
} }
|
|
|
|
|
2018-12-07 22:07:54 +00:00
|
|
|
static int paramValid(const paramValues_t paramTarget)
|
|
|
|
{
|
2018-08-09 17:42:35 +00:00
|
|
|
U32 i;
|
|
|
|
for(i = 0; i < NUM_PARAMS; i++) {
|
2018-12-07 22:07:54 +00:00
|
|
|
BOUNDCHECK(paramTarget.vals[i], mintable[i], maxtable[i]);
|
2018-06-18 18:59:45 +00:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-12-07 22:07:54 +00:00
|
|
|
/* cParamUnsetMin() :
|
|
|
|
* if any parameter in paramTarget is not yet set,
|
|
|
|
* it will receive its corresponding minimal value.
|
|
|
|
* This function never fails */
|
|
|
|
static paramValues_t cParamUnsetMin(paramValues_t paramTarget)
|
|
|
|
{
|
|
|
|
varInds_t vi;
|
|
|
|
for (vi = 0; vi < NUM_PARAMS; vi++) {
|
|
|
|
if (paramTarget.vals[vi] == PARAM_UNSET) {
|
|
|
|
paramTarget.vals[vi] = mintable[vi];
|
2018-08-09 17:42:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return paramTarget;
|
2018-06-18 18:59:45 +00:00
|
|
|
}
|
|
|
|
|
2018-12-07 22:07:54 +00:00
|
|
|
static paramValues_t emptyParams(void)
|
|
|
|
{
|
2018-08-15 21:57:10 +00:00
|
|
|
U32 i;
|
|
|
|
paramValues_t p;
|
|
|
|
for(i = 0; i < NUM_PARAMS; i++) {
|
|
|
|
p.vals[i] = PARAM_UNSET;
|
2018-08-09 17:42:35 +00:00
|
|
|
}
|
2018-08-15 21:57:10 +00:00
|
|
|
return p;
|
2018-08-09 17:42:35 +00:00
|
|
|
}
|
|
|
|
|
2018-12-07 22:07:54 +00:00
|
|
|
static winnerInfo_t initWinnerInfo(const paramValues_t p)
|
|
|
|
{
|
2018-08-15 21:57:10 +00:00
|
|
|
winnerInfo_t w1;
|
2020-12-03 15:36:45 +00:00
|
|
|
w1.result.cSpeed = 0;
|
|
|
|
w1.result.dSpeed = 0;
|
2018-08-15 21:57:10 +00:00
|
|
|
w1.result.cMem = (size_t)-1;
|
|
|
|
w1.result.cSize = (size_t)-1;
|
|
|
|
w1.params = p;
|
|
|
|
return w1;
|
|
|
|
}
|
2018-08-10 23:14:12 +00:00
|
|
|
|
2018-12-07 22:07:54 +00:00
|
|
|
static paramValues_t
|
|
|
|
overwriteParams(paramValues_t base, const paramValues_t mask)
|
|
|
|
{
|
2018-08-15 21:57:10 +00:00
|
|
|
U32 i;
|
|
|
|
for(i = 0; i < NUM_PARAMS; i++) {
|
|
|
|
if(mask.vals[i] != PARAM_UNSET) {
|
|
|
|
base.vals[i] = mask.vals[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return base;
|
|
|
|
}
|
|
|
|
|
2018-12-07 22:07:54 +00:00
|
|
|
static void
|
|
|
|
paramVaryOnce(const varInds_t paramIndex, const int amt, paramValues_t* ptr)
|
|
|
|
{
|
|
|
|
ptr->vals[paramIndex] = rangeMap(paramIndex,
|
|
|
|
invRangeMap(paramIndex, ptr->vals[paramIndex]) + amt);
|
2018-08-15 21:57:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* varies ptr by nbChanges respecting varyParams*/
|
2018-12-07 22:07:54 +00:00
|
|
|
static void
|
|
|
|
paramVariation(paramValues_t* ptr, memoTable_t* mtAll, const U32 nbChanges)
|
2018-08-15 21:57:10 +00:00
|
|
|
{
|
|
|
|
paramValues_t p;
|
2019-01-25 23:38:08 +00:00
|
|
|
int validated = 0;
|
2018-08-15 21:57:10 +00:00
|
|
|
while (!validated) {
|
|
|
|
U32 i;
|
|
|
|
p = *ptr;
|
|
|
|
for (i = 0 ; i < nbChanges ; i++) {
|
|
|
|
const U32 changeID = (U32)FUZ_rand(&g_rand) % (mtAll[p.vals[strt_ind]].varLen << 1);
|
2019-01-25 23:38:08 +00:00
|
|
|
paramVaryOnce(mtAll[p.vals[strt_ind]].varArray[changeID >> 1],
|
|
|
|
(int)((changeID & 1) << 1) - 1,
|
|
|
|
&p);
|
2018-08-15 21:57:10 +00:00
|
|
|
}
|
|
|
|
validated = paramValid(p);
|
|
|
|
}
|
|
|
|
*ptr = p;
|
2018-06-18 18:59:45 +00:00
|
|
|
}
|
|
|
|
|
2018-08-15 21:57:10 +00:00
|
|
|
/* Completely random parameter selection */
|
|
|
|
static paramValues_t randomParams(void)
|
|
|
|
{
|
|
|
|
varInds_t v; paramValues_t p;
|
2018-08-28 01:46:42 +00:00
|
|
|
for(v = 0; v < NUM_PARAMS; v++) {
|
2019-01-25 23:38:08 +00:00
|
|
|
p.vals[v] = rangeMap(v, (int)(FUZ_rand(&g_rand) % rangetable[v]));
|
2018-08-15 21:57:10 +00:00
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
static U64 g_clockGranularity = 100000000ULL;
|
|
|
|
|
2018-12-07 22:07:54 +00:00
|
|
|
static void init_clockGranularity(void)
|
|
|
|
{
|
|
|
|
UTIL_time_t const clockStart = UTIL_getTime();
|
2018-08-15 21:57:10 +00:00
|
|
|
U64 el1 = 0, el2 = 0;
|
|
|
|
int i = 0;
|
|
|
|
do {
|
|
|
|
el1 = el2;
|
|
|
|
el2 = UTIL_clockSpanNano(clockStart);
|
|
|
|
if(el1 < el2) {
|
|
|
|
U64 iv = el2 - el1;
|
|
|
|
if(g_clockGranularity > iv) {
|
|
|
|
g_clockGranularity = iv;
|
|
|
|
i = 0;
|
|
|
|
} else {
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while(i < 10);
|
|
|
|
DEBUGOUTPUT("Granularity: %llu\n", (unsigned long long)g_clockGranularity);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-************************************
|
|
|
|
* Optimizer Util Functions
|
|
|
|
**************************************/
|
|
|
|
|
2018-07-13 00:30:39 +00:00
|
|
|
/* checks results are feasible */
|
2018-08-24 00:21:38 +00:00
|
|
|
static int feasible(const BMK_benchResult_t results, const constraint_t target) {
|
|
|
|
return (results.cSpeed >= target.cSpeed)
|
|
|
|
&& (results.dSpeed >= target.dSpeed)
|
|
|
|
&& (results.cMem <= target.cMem)
|
|
|
|
&& (!g_optmode || results.cSize <= g_lvltarget.cSize);
|
2018-07-13 00:30:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* hill climbing value for part 1 */
|
2018-08-22 01:19:27 +00:00
|
|
|
/* Scoring here is a linear reward for all set constraints normalized between 0 to 1
|
|
|
|
* (with 0 at 0 and 1 being fully fulfilling the constraint), summed with a logarithmic
|
2018-08-07 01:00:36 +00:00
|
|
|
* bonus to exceeding the constraint value. We also give linear ratio for compression ratio.
|
2018-08-22 01:19:27 +00:00
|
|
|
* The constant factors are experimental.
|
2018-08-07 01:00:36 +00:00
|
|
|
*/
|
2018-12-07 22:07:54 +00:00
|
|
|
static double
|
|
|
|
resultScore(const BMK_benchResult_t res, const size_t srcSize, const constraint_t target)
|
|
|
|
{
|
2018-07-13 00:30:39 +00:00
|
|
|
double cs = 0., ds = 0., rt, cm = 0.;
|
|
|
|
const double r1 = 1, r2 = 0.1, rtr = 0.5;
|
|
|
|
double ret;
|
|
|
|
if(target.cSpeed) { cs = res.cSpeed / (double)target.cSpeed; }
|
|
|
|
if(target.dSpeed) { ds = res.dSpeed / (double)target.dSpeed; }
|
|
|
|
if(target.cMem != (U32)-1) { cm = (double)target.cMem / res.cMem; }
|
|
|
|
rt = ((double)srcSize / res.cSize);
|
|
|
|
|
2018-08-22 01:19:27 +00:00
|
|
|
ret = (MIN(1, cs) + MIN(1, ds) + MIN(1, cm))*r1 + rt * rtr +
|
2018-07-13 00:30:39 +00:00
|
|
|
(MAX(0, log(cs))+ MAX(0, log(ds))+ MAX(0, log(cm))) * r2;
|
2018-07-27 18:47:14 +00:00
|
|
|
|
2018-07-13 00:30:39 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-07-25 18:55:09 +00:00
|
|
|
/* calculates normalized squared euclidean distance of result1 if it is in the first quadrant relative to lvlRes */
|
2018-12-07 22:07:54 +00:00
|
|
|
static double
|
|
|
|
resultDistLvl(const BMK_benchResult_t result1, const BMK_benchResult_t lvlRes)
|
|
|
|
{
|
2020-12-03 15:36:45 +00:00
|
|
|
double normalizedCSpeedGain1 = ((double)result1.cSpeed / lvlRes.cSpeed) - 1;
|
2018-07-25 18:37:20 +00:00
|
|
|
double normalizedRatioGain1 = ((double)lvlRes.cSize / result1.cSize) - 1;
|
|
|
|
if(normalizedRatioGain1 < 0 || normalizedCSpeedGain1 < 0) {
|
2018-07-25 00:26:21 +00:00
|
|
|
return 0.0;
|
|
|
|
}
|
2018-08-13 19:51:22 +00:00
|
|
|
return normalizedRatioGain1 * g_ratioMultiplier + normalizedCSpeedGain1;
|
2018-07-25 00:26:21 +00:00
|
|
|
}
|
|
|
|
|
2018-08-22 01:19:27 +00:00
|
|
|
/* return true if r2 strictly better than r1 */
|
2018-12-07 22:07:54 +00:00
|
|
|
static int
|
|
|
|
compareResultLT(const BMK_benchResult_t result1, const BMK_benchResult_t result2, const constraint_t target, size_t srcSize)
|
|
|
|
{
|
2018-07-25 18:37:20 +00:00
|
|
|
if(feasible(result1, target) && feasible(result2, target)) {
|
2018-07-27 18:47:14 +00:00
|
|
|
if(g_optmode) {
|
|
|
|
return resultDistLvl(result1, g_lvltarget) < resultDistLvl(result2, g_lvltarget);
|
|
|
|
} else {
|
2018-12-07 22:07:54 +00:00
|
|
|
return (result1.cSize > result2.cSize)
|
|
|
|
|| (result1.cSize == result2.cSize && result2.cSpeed > result1.cSpeed)
|
|
|
|
|| (result1.cSize == result2.cSize && result2.cSpeed == result1.cSpeed && result2.dSpeed > result1.dSpeed);
|
2018-07-25 18:37:20 +00:00
|
|
|
}
|
2018-07-25 00:26:21 +00:00
|
|
|
}
|
2018-12-07 22:07:54 +00:00
|
|
|
return feasible(result2, target)
|
|
|
|
|| (!feasible(result1, target)
|
|
|
|
&& (resultScore(result1, srcSize, target) < resultScore(result2, srcSize, target)));
|
2018-07-25 00:26:21 +00:00
|
|
|
}
|
|
|
|
|
2018-07-13 00:30:39 +00:00
|
|
|
static constraint_t relaxTarget(constraint_t target) {
|
|
|
|
target.cMem = (U32)-1;
|
2019-04-18 22:06:56 +00:00
|
|
|
target.cSpeed = (target.cSpeed * g_strictness) / 100;
|
|
|
|
target.dSpeed = (target.dSpeed * g_strictness) / 100;
|
2018-07-13 00:30:39 +00:00
|
|
|
return target;
|
|
|
|
}
|
|
|
|
|
2018-12-07 22:07:54 +00:00
|
|
|
static void optimizerAdjustInput(paramValues_t* pc, const size_t maxBlockSize)
|
|
|
|
{
|
2018-08-15 21:57:10 +00:00
|
|
|
varInds_t v;
|
|
|
|
for(v = 0; v < NUM_PARAMS; v++) {
|
|
|
|
if(pc->vals[v] != PARAM_UNSET) {
|
|
|
|
U32 newval = MIN(MAX(pc->vals[v], mintable[v]), maxtable[v]);
|
|
|
|
if(newval != pc->vals[v]) {
|
|
|
|
pc->vals[v] = newval;
|
2018-12-07 22:07:54 +00:00
|
|
|
DISPLAY("Warning: parameter %s not in valid range, adjusting to ",
|
|
|
|
g_paramNames[v]);
|
|
|
|
displayParamVal(stderr, v, newval, 0); DISPLAY("\n");
|
2018-08-15 21:57:10 +00:00
|
|
|
}
|
|
|
|
}
|
2018-08-09 17:42:35 +00:00
|
|
|
}
|
2018-07-20 21:35:09 +00:00
|
|
|
|
2018-08-15 21:57:10 +00:00
|
|
|
if(pc->vals[wlog_ind] != PARAM_UNSET) {
|
2018-07-20 21:35:09 +00:00
|
|
|
|
2018-08-15 21:57:10 +00:00
|
|
|
U32 sshb = maxBlockSize > 1 ? ZSTD_highbit32((U32)(maxBlockSize-1)) + 1 : 1;
|
|
|
|
/* edge case of highBit not working for 0 */
|
2018-07-16 23:16:31 +00:00
|
|
|
|
2018-08-15 21:57:10 +00:00
|
|
|
if(maxBlockSize < (1ULL << 31) && sshb + 1 < pc->vals[wlog_ind]) {
|
|
|
|
U32 adjust = MAX(mintable[wlog_ind], sshb);
|
|
|
|
if(adjust != pc->vals[wlog_ind]) {
|
|
|
|
pc->vals[wlog_ind] = adjust;
|
2018-12-07 22:07:54 +00:00
|
|
|
DISPLAY("Warning: windowLog larger than src/block size, adjusted to %u\n",
|
fix confusion between unsigned <-> U32
as suggested in #1441.
generally U32 and unsigned are the same thing,
except when they are not ...
case : 32-bit compilation for MIPS (uint32_t == unsigned long)
A vast majority of transformation consists in transforming U32 into unsigned.
In rare cases, it's the other way around (typically for internal code, such as seeds).
Among a few issues this patches solves :
- some parameters were declared with type `unsigned` in *.h,
but with type `U32` in their implementation *.c .
- some parameters have type unsigned*,
but the caller user a pointer to U32 instead.
These fixes are useful.
However, the bulk of changes is about %u formating,
which requires unsigned type,
but generally receives U32 values instead,
often just for brevity (U32 is shorter than unsigned).
These changes are generally minor, or even annoying.
As a consequence, the amount of code changed is larger than I would expect for such a patch.
Testing is also a pain :
it requires manually modifying `mem.h`,
in order to lie about `U32`
and force it to be an `unsigned long` typically.
On a 64-bit system, this will break the equivalence unsigned == U32.
Unfortunately, it will also break a few static_assert(), controlling structure sizes.
So it also requires modifying `debug.h` to make `static_assert()` a noop.
And then reverting these changes.
So it's inconvenient, and as a consequence,
this property is currently not checked during CI tests.
Therefore, these problems can emerge again in the future.
I wonder if it is worth ensuring proper distinction of U32 != unsigned in CI tests.
It's another restriction for coding, adding more frustration during merge tests,
since most platforms don't need this distinction (hence contributor will not see it),
and while this can matter in theory, the number of platforms impacted seems minimal.
Thoughts ?
2018-12-22 00:19:44 +00:00
|
|
|
(unsigned)pc->vals[wlog_ind]);
|
2018-08-15 21:57:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-16 23:16:31 +00:00
|
|
|
|
2018-08-15 21:57:10 +00:00
|
|
|
if(pc->vals[wlog_ind] != PARAM_UNSET && pc->vals[clog_ind] != PARAM_UNSET) {
|
|
|
|
U32 maxclog;
|
|
|
|
if(pc->vals[strt_ind] == PARAM_UNSET || pc->vals[strt_ind] >= (U32)ZSTD_btlazy2) {
|
|
|
|
maxclog = pc->vals[wlog_ind] + 1;
|
|
|
|
} else {
|
|
|
|
maxclog = pc->vals[wlog_ind];
|
|
|
|
}
|
2018-08-10 23:14:12 +00:00
|
|
|
|
2018-08-15 21:57:10 +00:00
|
|
|
if(pc->vals[clog_ind] > maxclog) {
|
|
|
|
pc->vals[clog_ind] = maxclog;
|
2018-12-07 22:07:54 +00:00
|
|
|
DISPLAY("Warning: chainlog too much larger than windowLog size, adjusted to %u\n",
|
fix confusion between unsigned <-> U32
as suggested in #1441.
generally U32 and unsigned are the same thing,
except when they are not ...
case : 32-bit compilation for MIPS (uint32_t == unsigned long)
A vast majority of transformation consists in transforming U32 into unsigned.
In rare cases, it's the other way around (typically for internal code, such as seeds).
Among a few issues this patches solves :
- some parameters were declared with type `unsigned` in *.h,
but with type `U32` in their implementation *.c .
- some parameters have type unsigned*,
but the caller user a pointer to U32 instead.
These fixes are useful.
However, the bulk of changes is about %u formating,
which requires unsigned type,
but generally receives U32 values instead,
often just for brevity (U32 is shorter than unsigned).
These changes are generally minor, or even annoying.
As a consequence, the amount of code changed is larger than I would expect for such a patch.
Testing is also a pain :
it requires manually modifying `mem.h`,
in order to lie about `U32`
and force it to be an `unsigned long` typically.
On a 64-bit system, this will break the equivalence unsigned == U32.
Unfortunately, it will also break a few static_assert(), controlling structure sizes.
So it also requires modifying `debug.h` to make `static_assert()` a noop.
And then reverting these changes.
So it's inconvenient, and as a consequence,
this property is currently not checked during CI tests.
Therefore, these problems can emerge again in the future.
I wonder if it is worth ensuring proper distinction of U32 != unsigned in CI tests.
It's another restriction for coding, adding more frustration during merge tests,
since most platforms don't need this distinction (hence contributor will not see it),
and while this can matter in theory, the number of platforms impacted seems minimal.
Thoughts ?
2018-12-22 00:19:44 +00:00
|
|
|
(unsigned)pc->vals[clog_ind]);
|
2018-08-15 21:57:10 +00:00
|
|
|
}
|
2018-08-10 23:14:12 +00:00
|
|
|
}
|
|
|
|
|
2018-08-15 21:57:10 +00:00
|
|
|
if(pc->vals[wlog_ind] != PARAM_UNSET && pc->vals[hlog_ind] != PARAM_UNSET) {
|
|
|
|
if(pc->vals[wlog_ind] + 1 < pc->vals[hlog_ind]) {
|
|
|
|
pc->vals[hlog_ind] = pc->vals[wlog_ind] + 1;
|
2018-12-07 22:07:54 +00:00
|
|
|
DISPLAY("Warning: hashlog too much larger than windowLog size, adjusted to %u\n",
|
fix confusion between unsigned <-> U32
as suggested in #1441.
generally U32 and unsigned are the same thing,
except when they are not ...
case : 32-bit compilation for MIPS (uint32_t == unsigned long)
A vast majority of transformation consists in transforming U32 into unsigned.
In rare cases, it's the other way around (typically for internal code, such as seeds).
Among a few issues this patches solves :
- some parameters were declared with type `unsigned` in *.h,
but with type `U32` in their implementation *.c .
- some parameters have type unsigned*,
but the caller user a pointer to U32 instead.
These fixes are useful.
However, the bulk of changes is about %u formating,
which requires unsigned type,
but generally receives U32 values instead,
often just for brevity (U32 is shorter than unsigned).
These changes are generally minor, or even annoying.
As a consequence, the amount of code changed is larger than I would expect for such a patch.
Testing is also a pain :
it requires manually modifying `mem.h`,
in order to lie about `U32`
and force it to be an `unsigned long` typically.
On a 64-bit system, this will break the equivalence unsigned == U32.
Unfortunately, it will also break a few static_assert(), controlling structure sizes.
So it also requires modifying `debug.h` to make `static_assert()` a noop.
And then reverting these changes.
So it's inconvenient, and as a consequence,
this property is currently not checked during CI tests.
Therefore, these problems can emerge again in the future.
I wonder if it is worth ensuring proper distinction of U32 != unsigned in CI tests.
It's another restriction for coding, adding more frustration during merge tests,
since most platforms don't need this distinction (hence contributor will not see it),
and while this can matter in theory, the number of platforms impacted seems minimal.
Thoughts ?
2018-12-22 00:19:44 +00:00
|
|
|
(unsigned)pc->vals[hlog_ind]);
|
2018-08-15 21:57:10 +00:00
|
|
|
}
|
|
|
|
}
|
2018-08-22 01:19:27 +00:00
|
|
|
|
2018-08-15 21:57:10 +00:00
|
|
|
if(pc->vals[slog_ind] != PARAM_UNSET && pc->vals[clog_ind] != PARAM_UNSET) {
|
|
|
|
if(pc->vals[slog_ind] > pc->vals[clog_ind]) {
|
|
|
|
pc->vals[clog_ind] = pc->vals[slog_ind];
|
2018-12-07 22:07:54 +00:00
|
|
|
DISPLAY("Warning: searchLog larger than chainLog, adjusted to %u\n",
|
fix confusion between unsigned <-> U32
as suggested in #1441.
generally U32 and unsigned are the same thing,
except when they are not ...
case : 32-bit compilation for MIPS (uint32_t == unsigned long)
A vast majority of transformation consists in transforming U32 into unsigned.
In rare cases, it's the other way around (typically for internal code, such as seeds).
Among a few issues this patches solves :
- some parameters were declared with type `unsigned` in *.h,
but with type `U32` in their implementation *.c .
- some parameters have type unsigned*,
but the caller user a pointer to U32 instead.
These fixes are useful.
However, the bulk of changes is about %u formating,
which requires unsigned type,
but generally receives U32 values instead,
often just for brevity (U32 is shorter than unsigned).
These changes are generally minor, or even annoying.
As a consequence, the amount of code changed is larger than I would expect for such a patch.
Testing is also a pain :
it requires manually modifying `mem.h`,
in order to lie about `U32`
and force it to be an `unsigned long` typically.
On a 64-bit system, this will break the equivalence unsigned == U32.
Unfortunately, it will also break a few static_assert(), controlling structure sizes.
So it also requires modifying `debug.h` to make `static_assert()` a noop.
And then reverting these changes.
So it's inconvenient, and as a consequence,
this property is currently not checked during CI tests.
Therefore, these problems can emerge again in the future.
I wonder if it is worth ensuring proper distinction of U32 != unsigned in CI tests.
It's another restriction for coding, adding more frustration during merge tests,
since most platforms don't need this distinction (hence contributor will not see it),
and while this can matter in theory, the number of platforms impacted seems minimal.
Thoughts ?
2018-12-22 00:19:44 +00:00
|
|
|
(unsigned)pc->vals[slog_ind]);
|
2018-08-15 21:57:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-07 22:07:54 +00:00
|
|
|
static int
|
|
|
|
redundantParams(const paramValues_t paramValues, const constraint_t target, const size_t maxBlockSize)
|
|
|
|
{
|
2018-08-22 01:19:27 +00:00
|
|
|
return
|
2018-08-15 21:57:10 +00:00
|
|
|
(ZSTD_estimateCStreamSize_usingCParams(pvalsToCParams(paramValues)) > (size_t)target.cMem) /* Uses too much memory */
|
|
|
|
|| ((1ULL << (paramValues.vals[wlog_ind] - 1)) >= maxBlockSize && paramValues.vals[wlog_ind] != mintable[wlog_ind]) /* wlog too much bigger than src size */
|
|
|
|
|| (paramValues.vals[clog_ind] > (paramValues.vals[wlog_ind] + (paramValues.vals[strt_ind] > ZSTD_btlazy2))) /* chainLog larger than windowLog*/
|
|
|
|
|| (paramValues.vals[slog_ind] > paramValues.vals[clog_ind]) /* searchLog larger than chainLog */
|
|
|
|
|| (paramValues.vals[hlog_ind] > paramValues.vals[wlog_ind] + 1); /* hashLog larger than windowLog + 1 */
|
|
|
|
}
|
|
|
|
|
2018-12-07 22:07:54 +00:00
|
|
|
|
2018-08-15 21:57:10 +00:00
|
|
|
/*-************************************
|
2018-08-22 01:19:27 +00:00
|
|
|
* Display Functions
|
2018-08-15 21:57:10 +00:00
|
|
|
**************************************/
|
|
|
|
|
2018-12-07 22:07:54 +00:00
|
|
|
/* BMK_paramValues_into_commandLine() :
|
|
|
|
* transform a set of parameters paramValues_t
|
|
|
|
* into a command line compatible with `zstd` syntax
|
|
|
|
* and writes it into FILE* f.
|
|
|
|
* f must be already opened and writable */
|
|
|
|
static void
|
|
|
|
BMK_paramValues_into_commandLine(FILE* f, const paramValues_t params)
|
|
|
|
{
|
2018-08-15 21:57:10 +00:00
|
|
|
varInds_t v;
|
|
|
|
int first = 1;
|
|
|
|
fprintf(f,"--zstd=");
|
2018-08-28 01:46:42 +00:00
|
|
|
for (v = 0; v < NUM_PARAMS; v++) {
|
|
|
|
if (g_silenceParams[v]) { continue; }
|
|
|
|
if (!first) { fprintf(f, ","); }
|
2018-08-15 21:57:10 +00:00
|
|
|
fprintf(f,"%s=", g_paramNames[v]);
|
2018-08-22 01:19:27 +00:00
|
|
|
|
fix confusion between unsigned <-> U32
as suggested in #1441.
generally U32 and unsigned are the same thing,
except when they are not ...
case : 32-bit compilation for MIPS (uint32_t == unsigned long)
A vast majority of transformation consists in transforming U32 into unsigned.
In rare cases, it's the other way around (typically for internal code, such as seeds).
Among a few issues this patches solves :
- some parameters were declared with type `unsigned` in *.h,
but with type `U32` in their implementation *.c .
- some parameters have type unsigned*,
but the caller user a pointer to U32 instead.
These fixes are useful.
However, the bulk of changes is about %u formating,
which requires unsigned type,
but generally receives U32 values instead,
often just for brevity (U32 is shorter than unsigned).
These changes are generally minor, or even annoying.
As a consequence, the amount of code changed is larger than I would expect for such a patch.
Testing is also a pain :
it requires manually modifying `mem.h`,
in order to lie about `U32`
and force it to be an `unsigned long` typically.
On a 64-bit system, this will break the equivalence unsigned == U32.
Unfortunately, it will also break a few static_assert(), controlling structure sizes.
So it also requires modifying `debug.h` to make `static_assert()` a noop.
And then reverting these changes.
So it's inconvenient, and as a consequence,
this property is currently not checked during CI tests.
Therefore, these problems can emerge again in the future.
I wonder if it is worth ensuring proper distinction of U32 != unsigned in CI tests.
It's another restriction for coding, adding more frustration during merge tests,
since most platforms don't need this distinction (hence contributor will not see it),
and while this can matter in theory, the number of platforms impacted seems minimal.
Thoughts ?
2018-12-22 00:19:44 +00:00
|
|
|
if (v == strt_ind) { fprintf(f,"%u", (unsigned)params.vals[v]); }
|
2018-08-15 21:57:10 +00:00
|
|
|
else { displayParamVal(f, v, params.vals[v], 0); }
|
|
|
|
first = 0;
|
|
|
|
}
|
|
|
|
fprintf(f, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* comparison function: */
|
|
|
|
/* strictly better, strictly worse, equal, speed-side adv, size-side adv */
|
|
|
|
#define WORSE_RESULT 0
|
|
|
|
#define BETTER_RESULT 1
|
|
|
|
#define ERROR_RESULT 2
|
|
|
|
|
|
|
|
#define SPEED_RESULT 4
|
|
|
|
#define SIZE_RESULT 5
|
|
|
|
/* maybe have epsilon-eq to limit table size? */
|
2018-12-07 22:07:54 +00:00
|
|
|
static int
|
|
|
|
speedSizeCompare(const BMK_benchResult_t r1, const BMK_benchResult_t r2)
|
|
|
|
{
|
2018-08-15 21:57:10 +00:00
|
|
|
if(r1.cSpeed < r2.cSpeed) {
|
|
|
|
if(r1.cSize >= r2.cSize) {
|
|
|
|
return BETTER_RESULT;
|
|
|
|
}
|
|
|
|
return SPEED_RESULT; /* r2 is smaller but not faster. */
|
|
|
|
} else {
|
|
|
|
if(r1.cSize <= r2.cSize) {
|
|
|
|
return WORSE_RESULT;
|
|
|
|
}
|
|
|
|
return SIZE_RESULT; /* r2 is faster but not smaller */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 0 for insertion, 1 for no insert */
|
|
|
|
/* maintain invariant speedSizeCompare(n, n->next) = SPEED_RESULT */
|
2018-12-07 22:07:54 +00:00
|
|
|
static int
|
|
|
|
insertWinner(const winnerInfo_t w, const constraint_t targetConstraints)
|
|
|
|
{
|
2018-08-24 00:21:38 +00:00
|
|
|
BMK_benchResult_t r = w.result;
|
2018-08-15 21:57:10 +00:00
|
|
|
winner_ll_node* cur_node = g_winners;
|
|
|
|
/* first node to insert */
|
|
|
|
if(!feasible(r, targetConstraints)) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(g_winners == NULL) {
|
|
|
|
winner_ll_node* first_node = malloc(sizeof(winner_ll_node));
|
|
|
|
if(first_node == NULL) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
first_node->next = NULL;
|
|
|
|
first_node->res = w;
|
|
|
|
g_winners = first_node;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(cur_node->next != NULL) {
|
|
|
|
switch(speedSizeCompare(cur_node->res.result, r)) {
|
|
|
|
case WORSE_RESULT:
|
|
|
|
{
|
|
|
|
return 1; /* never insert if better */
|
|
|
|
}
|
|
|
|
case BETTER_RESULT:
|
|
|
|
{
|
|
|
|
winner_ll_node* tmp;
|
|
|
|
cur_node->res = cur_node->next->res;
|
|
|
|
tmp = cur_node->next;
|
|
|
|
cur_node->next = cur_node->next->next;
|
|
|
|
free(tmp);
|
2018-08-22 01:19:27 +00:00
|
|
|
break;
|
2018-08-15 21:57:10 +00:00
|
|
|
}
|
|
|
|
case SIZE_RESULT:
|
|
|
|
{
|
|
|
|
cur_node = cur_node->next;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SPEED_RESULT: /* insert after first size result, then return */
|
|
|
|
{
|
|
|
|
winner_ll_node* newnode = malloc(sizeof(winner_ll_node));
|
|
|
|
if(newnode == NULL) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
newnode->res = cur_node->res;
|
|
|
|
cur_node->res = w;
|
|
|
|
newnode->next = cur_node->next;
|
|
|
|
cur_node->next = newnode;
|
|
|
|
return 0;
|
|
|
|
}
|
2018-08-22 01:19:27 +00:00
|
|
|
}
|
2018-08-15 21:57:10 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(cur_node->next == NULL);
|
|
|
|
switch(speedSizeCompare(cur_node->res.result, r)) {
|
|
|
|
case WORSE_RESULT:
|
|
|
|
{
|
|
|
|
return 1; /* never insert if better */
|
|
|
|
}
|
|
|
|
case BETTER_RESULT:
|
|
|
|
{
|
|
|
|
cur_node->res = w;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case SIZE_RESULT:
|
|
|
|
{
|
|
|
|
winner_ll_node* newnode = malloc(sizeof(winner_ll_node));
|
|
|
|
if(newnode == NULL) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
newnode->res = w;
|
|
|
|
newnode->next = NULL;
|
|
|
|
cur_node->next = newnode;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
case SPEED_RESULT: /* insert before first size result, then return */
|
|
|
|
{
|
|
|
|
winner_ll_node* newnode = malloc(sizeof(winner_ll_node));
|
|
|
|
if(newnode == NULL) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
newnode->res = cur_node->res;
|
|
|
|
cur_node->res = w;
|
|
|
|
newnode->next = cur_node->next;
|
|
|
|
cur_node->next = newnode;
|
|
|
|
return 0;
|
|
|
|
}
|
2018-08-22 01:19:27 +00:00
|
|
|
default:
|
2018-08-15 21:57:10 +00:00
|
|
|
return 1;
|
2018-08-22 01:19:27 +00:00
|
|
|
}
|
2018-08-15 21:57:10 +00:00
|
|
|
}
|
|
|
|
|
2018-12-07 22:07:54 +00:00
|
|
|
static void
|
|
|
|
BMK_displayOneResult(FILE* f, winnerInfo_t res, const size_t srcSize)
|
|
|
|
{
|
|
|
|
varInds_t v;
|
|
|
|
int first = 1;
|
|
|
|
res.params = cParamUnsetMin(res.params);
|
|
|
|
fprintf(f, " {");
|
|
|
|
for (v = 0; v < NUM_PARAMS; v++) {
|
|
|
|
if (g_silenceParams[v]) { continue; }
|
|
|
|
if (!first) { fprintf(f, ","); }
|
|
|
|
displayParamVal(f, v, res.params.vals[v], 3);
|
|
|
|
first = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
{ double const ratio = res.result.cSize ?
|
|
|
|
(double)srcSize / res.result.cSize : 0;
|
|
|
|
double const cSpeedMBps = (double)res.result.cSpeed / MB_UNIT;
|
|
|
|
double const dSpeedMBps = (double)res.result.dSpeed / MB_UNIT;
|
|
|
|
|
|
|
|
fprintf(f, " }, /* R:%5.3f at %5.1f MB/s - %5.1f MB/s */\n",
|
|
|
|
ratio, cSpeedMBps, dSpeedMBps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Writes to f the results of a parameter benchmark */
|
|
|
|
/* when used with --optimize, will only print results better than previously discovered */
|
|
|
|
static void
|
|
|
|
BMK_printWinner(FILE* f, const int cLevel, const BMK_benchResult_t result, const paramValues_t params, const size_t srcSize)
|
|
|
|
{
|
|
|
|
char lvlstr[15] = "Custom Level";
|
|
|
|
winnerInfo_t w;
|
|
|
|
w.params = params;
|
|
|
|
w.result = result;
|
|
|
|
|
|
|
|
fprintf(f, "\r%79s\r", "");
|
|
|
|
|
|
|
|
if(cLevel != CUSTOM_LEVEL) {
|
|
|
|
snprintf(lvlstr, 15, " Level %2d ", cLevel);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(TIMED) {
|
|
|
|
const U64 mn_in_ns = 60ULL * TIMELOOP_NANOSEC;
|
2018-12-20 22:54:05 +00:00
|
|
|
const U64 time_ns = UTIL_clockSpanNano(g_time);
|
|
|
|
const U64 minutes = time_ns / mn_in_ns;
|
2018-12-07 22:07:54 +00:00
|
|
|
fprintf(f, "%1lu:%2lu:%05.2f - ",
|
|
|
|
(unsigned long) minutes / 60,
|
|
|
|
(unsigned long) minutes % 60,
|
2018-12-20 22:54:05 +00:00
|
|
|
(double)(time_ns - (minutes * mn_in_ns)) / TIMELOOP_NANOSEC );
|
2018-12-07 22:07:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(f, "/* %s */ ", lvlstr);
|
|
|
|
BMK_displayOneResult(f, w, srcSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
BMK_printWinnerOpt(FILE* f, const U32 cLevel, const BMK_benchResult_t result, const paramValues_t params, const constraint_t targetConstraints, const size_t srcSize)
|
2018-08-15 21:57:10 +00:00
|
|
|
{
|
|
|
|
/* global winner used for constraints */
|
|
|
|
/* cSize, cSpeed, dSpeed, cMem */
|
2018-12-07 22:07:54 +00:00
|
|
|
static winnerInfo_t g_winner = { { (size_t)-1LL, 0, 0, (size_t)-1LL },
|
|
|
|
{ { PARAM_UNSET, PARAM_UNSET, PARAM_UNSET, PARAM_UNSET, PARAM_UNSET, PARAM_UNSET, PARAM_UNSET, PARAM_UNSET } }
|
|
|
|
};
|
|
|
|
if ( DEBUG
|
|
|
|
|| compareResultLT(g_winner.result, result, targetConstraints, srcSize)
|
|
|
|
|| g_displayLevel >= 4) {
|
|
|
|
if ( DEBUG
|
|
|
|
&& compareResultLT(g_winner.result, result, targetConstraints, srcSize)) {
|
2018-08-15 21:57:10 +00:00
|
|
|
DISPLAY("New Winner: \n");
|
|
|
|
}
|
|
|
|
|
2018-12-07 22:07:54 +00:00
|
|
|
if(g_displayLevel >= 2) {
|
|
|
|
BMK_printWinner(f, cLevel, result, params, srcSize);
|
|
|
|
}
|
2018-08-15 21:57:10 +00:00
|
|
|
|
|
|
|
if(compareResultLT(g_winner.result, result, targetConstraints, srcSize)) {
|
2018-12-07 22:07:54 +00:00
|
|
|
if(g_displayLevel >= 1) { BMK_paramValues_into_commandLine(f, params); }
|
2018-08-15 21:57:10 +00:00
|
|
|
g_winner.result = result;
|
|
|
|
g_winner.params = params;
|
|
|
|
}
|
2018-08-22 01:19:27 +00:00
|
|
|
}
|
2018-08-15 21:57:10 +00:00
|
|
|
|
|
|
|
if(g_optmode && g_optimizer && (DEBUG || g_displayLevel == 3)) {
|
|
|
|
winnerInfo_t w;
|
|
|
|
winner_ll_node* n;
|
|
|
|
w.result = result;
|
|
|
|
w.params = params;
|
|
|
|
insertWinner(w, targetConstraints);
|
|
|
|
|
|
|
|
if(!DEBUG) { fprintf(f, "\033c"); }
|
2018-08-22 01:19:27 +00:00
|
|
|
fprintf(f, "\n");
|
|
|
|
|
2018-08-15 21:57:10 +00:00
|
|
|
/* the table */
|
|
|
|
fprintf(f, "================================\n");
|
|
|
|
for(n = g_winners; n != NULL; n = n->next) {
|
|
|
|
BMK_displayOneResult(f, n->res, srcSize);
|
|
|
|
}
|
|
|
|
fprintf(f, "================================\n");
|
|
|
|
fprintf(f, "Level Bounds: R: > %.3f AND C: < %.1f MB/s \n\n",
|
2018-08-24 01:04:50 +00:00
|
|
|
(double)srcSize / g_lvltarget.cSize, (double)g_lvltarget.cSpeed / MB_UNIT);
|
2018-08-15 21:57:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
fprintf(f, "Overall Winner: \n");
|
|
|
|
BMK_displayOneResult(f, g_winner, srcSize);
|
2018-12-07 22:07:54 +00:00
|
|
|
BMK_paramValues_into_commandLine(f, g_winner.params);
|
2018-08-15 21:57:10 +00:00
|
|
|
|
|
|
|
fprintf(f, "Latest BMK: \n");\
|
|
|
|
BMK_displayOneResult(f, w, srcSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-07 22:07:54 +00:00
|
|
|
|
|
|
|
/* BMK_print_cLevelEntry() :
|
|
|
|
* Writes one cLevelTable entry, for one level.
|
|
|
|
* f must exist, be already opened, and be seekable.
|
|
|
|
* this function cannot error.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
BMK_print_cLevelEntry(FILE* f, const int cLevel,
|
|
|
|
paramValues_t params,
|
|
|
|
const BMK_benchResult_t result, const size_t srcSize)
|
|
|
|
{
|
|
|
|
varInds_t v;
|
|
|
|
int first = 1;
|
|
|
|
|
|
|
|
assert(cLevel >= 0);
|
|
|
|
assert(cLevel <= NB_LEVELS_TRACKED);
|
|
|
|
params = cParamUnsetMin(params);
|
|
|
|
|
|
|
|
fprintf(f, " {");
|
|
|
|
/* print cParams.
|
|
|
|
* assumption : all cParams are present and in order in the following range */
|
|
|
|
for (v = 0; v <= strt_ind; v++) {
|
|
|
|
if (!first) { fprintf(f, ","); }
|
|
|
|
displayParamVal(f, v, params.vals[v], 3);
|
|
|
|
first = 0;
|
|
|
|
}
|
|
|
|
/* print comment */
|
|
|
|
{ double const ratio = result.cSize ?
|
|
|
|
(double)srcSize / result.cSize : 0;
|
|
|
|
double const cSpeedMBps = (double)result.cSpeed / MB_UNIT;
|
|
|
|
double const dSpeedMBps = (double)result.dSpeed / MB_UNIT;
|
|
|
|
|
|
|
|
fprintf(f, " }, /* level %2i: R=%5.3f at %5.1f MB/s - %5.1f MB/s */\n",
|
|
|
|
cLevel, ratio, cSpeedMBps, dSpeedMBps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* BMK_print_cLevelTable() :
|
|
|
|
* print candidate compression table into proposed FILE* f.
|
|
|
|
* f must exist, be already opened, and be seekable.
|
|
|
|
* winners must be a table of NB_LEVELS_TRACKED+1 elements winnerInfo_t, all entries presumed initialized
|
|
|
|
* this function cannot error.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
BMK_print_cLevelTable(FILE* f, const winnerInfo_t* winners, const size_t srcSize)
|
2018-08-15 21:57:10 +00:00
|
|
|
{
|
|
|
|
int cLevel;
|
|
|
|
|
|
|
|
fprintf(f, "\n /* Proposed configurations : */ \n");
|
2018-12-07 22:07:54 +00:00
|
|
|
fprintf(f, " /* W, C, H, S, L, T, strat */ \n");
|
2018-08-15 21:57:10 +00:00
|
|
|
|
|
|
|
for (cLevel=0; cLevel <= NB_LEVELS_TRACKED; cLevel++)
|
2018-12-07 22:07:54 +00:00
|
|
|
BMK_print_cLevelEntry(f,
|
|
|
|
cLevel, winners[cLevel].params,
|
|
|
|
winners[cLevel].result, srcSize);
|
2018-08-15 21:57:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-12-07 22:07:54 +00:00
|
|
|
/* BMK_saveAndPrint_cLevelTable() :
|
|
|
|
* save candidate compression table into FILE* f,
|
|
|
|
* and then to stdout.
|
|
|
|
* f must exist, be already opened, and be seekable.
|
|
|
|
* winners must be a table of NB_LEVELS_TRACKED+1 elements winnerInfo_t, all entries presumed initialized
|
|
|
|
* this function cannot error.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
BMK_saveAndPrint_cLevelTable(FILE* const f,
|
|
|
|
const winnerInfo_t* winners,
|
|
|
|
const size_t srcSize)
|
2018-08-15 21:57:10 +00:00
|
|
|
{
|
|
|
|
fseek(f, 0, SEEK_SET);
|
2018-12-07 22:07:54 +00:00
|
|
|
BMK_print_cLevelTable(f, winners, srcSize);
|
2018-08-15 21:57:10 +00:00
|
|
|
fflush(f);
|
2018-12-07 22:07:54 +00:00
|
|
|
BMK_print_cLevelTable(stdout, winners, srcSize);
|
2018-08-15 21:57:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*-*******************************************************
|
|
|
|
* Functions to Benchmark
|
|
|
|
*********************************************************/
|
|
|
|
|
|
|
|
typedef struct {
|
2018-08-24 00:21:38 +00:00
|
|
|
ZSTD_CCtx* cctx;
|
2018-08-15 21:57:10 +00:00
|
|
|
const void* dictBuffer;
|
|
|
|
size_t dictBufferSize;
|
|
|
|
int cLevel;
|
|
|
|
const paramValues_t* comprParams;
|
|
|
|
} BMK_initCCtxArgs;
|
|
|
|
|
|
|
|
static size_t local_initCCtx(void* payload) {
|
|
|
|
const BMK_initCCtxArgs* ag = (const BMK_initCCtxArgs*)payload;
|
|
|
|
varInds_t i;
|
2018-11-16 00:12:39 +00:00
|
|
|
ZSTD_CCtx_reset(ag->cctx, ZSTD_reset_session_and_parameters);
|
2018-12-06 01:26:02 +00:00
|
|
|
ZSTD_CCtx_setParameter(ag->cctx, ZSTD_c_compressionLevel, ag->cLevel);
|
2018-08-15 21:57:10 +00:00
|
|
|
|
|
|
|
for(i = 0; i < NUM_PARAMS; i++) {
|
|
|
|
if(ag->comprParams->vals[i] != PARAM_UNSET)
|
2018-08-24 00:21:38 +00:00
|
|
|
ZSTD_CCtx_setParameter(ag->cctx, cctxSetParamTable[i], ag->comprParams->vals[i]);
|
2018-08-15 21:57:10 +00:00
|
|
|
}
|
2018-08-24 00:21:38 +00:00
|
|
|
ZSTD_CCtx_loadDictionary(ag->cctx, ag->dictBuffer, ag->dictBufferSize);
|
2018-08-15 21:57:10 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2018-07-16 23:16:31 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
ZSTD_DCtx* dctx;
|
|
|
|
const void* dictBuffer;
|
|
|
|
size_t dictBufferSize;
|
|
|
|
} BMK_initDCtxArgs;
|
|
|
|
|
|
|
|
static size_t local_initDCtx(void* payload) {
|
2018-08-07 01:37:55 +00:00
|
|
|
const BMK_initDCtxArgs* ag = (const BMK_initDCtxArgs*)payload;
|
2018-11-16 00:12:39 +00:00
|
|
|
ZSTD_DCtx_reset(ag->dctx, ZSTD_reset_session_and_parameters);
|
2018-08-10 23:14:12 +00:00
|
|
|
ZSTD_DCtx_loadDictionary(ag->dctx, ag->dictBuffer, ag->dictBufferSize);
|
2018-07-16 23:16:31 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* additional argument is just the context */
|
|
|
|
static size_t local_defaultCompress(
|
2018-11-30 19:16:26 +00:00
|
|
|
const void* srcBuffer, size_t srcSize,
|
|
|
|
void* dstBuffer, size_t dstSize,
|
|
|
|
void* addArgs)
|
|
|
|
{
|
|
|
|
ZSTD_CCtx* cctx = (ZSTD_CCtx*)addArgs;
|
2018-07-20 21:35:09 +00:00
|
|
|
assert(dstSize == ZSTD_compressBound(srcSize)); /* specific to this version, which is only used in paramgrill */
|
2018-11-30 19:16:26 +00:00
|
|
|
return ZSTD_compress2(cctx, dstBuffer, dstSize, srcBuffer, srcSize);
|
2018-07-16 23:16:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* additional argument is just the context */
|
|
|
|
static size_t local_defaultDecompress(
|
2018-08-22 01:19:27 +00:00
|
|
|
const void* srcBuffer, size_t srcSize,
|
|
|
|
void* dstBuffer, size_t dstSize,
|
2018-07-16 23:16:31 +00:00
|
|
|
void* addArgs) {
|
|
|
|
size_t moreToFlush = 1;
|
|
|
|
ZSTD_DCtx* dctx = (ZSTD_DCtx*)addArgs;
|
|
|
|
ZSTD_inBuffer in;
|
|
|
|
ZSTD_outBuffer out;
|
|
|
|
in.src = srcBuffer;
|
|
|
|
in.size = srcSize;
|
|
|
|
in.pos = 0;
|
|
|
|
out.dst = dstBuffer;
|
|
|
|
out.size = dstSize;
|
|
|
|
out.pos = 0;
|
|
|
|
while (moreToFlush) {
|
|
|
|
if(out.pos == out.size) {
|
|
|
|
return (size_t)-ZSTD_error_dstSize_tooSmall;
|
|
|
|
}
|
2018-12-04 18:28:36 +00:00
|
|
|
moreToFlush = ZSTD_decompressStream(dctx,
|
2018-07-16 23:16:31 +00:00
|
|
|
&out, &in);
|
|
|
|
if (ZSTD_isError(moreToFlush)) {
|
|
|
|
return moreToFlush;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return out.pos;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-08-15 21:57:10 +00:00
|
|
|
/*-************************************
|
2018-08-22 01:19:27 +00:00
|
|
|
* Data Initialization Functions
|
2018-08-15 21:57:10 +00:00
|
|
|
**************************************/
|
2018-08-10 23:14:12 +00:00
|
|
|
|
2018-08-15 21:57:10 +00:00
|
|
|
typedef struct {
|
|
|
|
void* srcBuffer;
|
|
|
|
size_t srcSize;
|
|
|
|
const void** srcPtrs;
|
|
|
|
size_t* srcSizes;
|
|
|
|
void** dstPtrs;
|
|
|
|
size_t* dstCapacities;
|
|
|
|
size_t* dstSizes;
|
|
|
|
void** resPtrs;
|
|
|
|
size_t* resSizes;
|
|
|
|
size_t nbBlocks;
|
|
|
|
size_t maxBlockSize;
|
|
|
|
} buffers_t;
|
2018-08-10 23:14:12 +00:00
|
|
|
|
2018-08-15 21:57:10 +00:00
|
|
|
typedef struct {
|
|
|
|
size_t dictSize;
|
|
|
|
void* dictBuffer;
|
|
|
|
ZSTD_CCtx* cctx;
|
|
|
|
ZSTD_DCtx* dctx;
|
|
|
|
} contexts_t;
|
2018-08-10 23:14:12 +00:00
|
|
|
|
2018-08-09 17:42:35 +00:00
|
|
|
static void freeNonSrcBuffers(const buffers_t b) {
|
2020-12-03 15:36:45 +00:00
|
|
|
free((void*)b.srcPtrs);
|
2018-07-27 21:19:55 +00:00
|
|
|
free(b.srcSizes);
|
|
|
|
|
|
|
|
if(b.dstPtrs != NULL) {
|
|
|
|
free(b.dstPtrs[0]);
|
|
|
|
}
|
|
|
|
free(b.dstPtrs);
|
|
|
|
free(b.dstCapacities);
|
|
|
|
free(b.dstSizes);
|
|
|
|
|
|
|
|
if(b.resPtrs != NULL) {
|
|
|
|
free(b.resPtrs[0]);
|
|
|
|
}
|
|
|
|
free(b.resPtrs);
|
2018-08-13 23:38:51 +00:00
|
|
|
free(b.resSizes);
|
2018-07-27 21:19:55 +00:00
|
|
|
}
|
|
|
|
|
2018-08-09 17:42:35 +00:00
|
|
|
static void freeBuffers(const buffers_t b) {
|
|
|
|
if(b.srcPtrs != NULL) {
|
|
|
|
free(b.srcBuffer);
|
|
|
|
}
|
|
|
|
freeNonSrcBuffers(b);
|
|
|
|
}
|
|
|
|
|
2018-08-06 22:08:35 +00:00
|
|
|
/* srcBuffer will be freed by freeBuffers now */
|
2018-08-13 19:51:22 +00:00
|
|
|
static int createBuffersFromMemory(buffers_t* buff, void * srcBuffer, const size_t nbFiles,
|
2018-08-06 22:08:35 +00:00
|
|
|
const size_t* fileSizes)
|
2018-07-27 21:19:55 +00:00
|
|
|
{
|
2018-08-06 22:08:35 +00:00
|
|
|
size_t pos = 0, n, blockSize;
|
|
|
|
U32 maxNbBlocks, blockNb = 0;
|
|
|
|
buff->srcSize = 0;
|
|
|
|
for(n = 0; n < nbFiles; n++) {
|
|
|
|
buff->srcSize += fileSizes[n];
|
|
|
|
}
|
|
|
|
|
|
|
|
if(buff->srcSize == 0) {
|
|
|
|
DISPLAY("No data to bench\n");
|
2018-08-14 18:57:15 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2018-08-06 22:08:35 +00:00
|
|
|
|
|
|
|
blockSize = g_blockSize ? g_blockSize : buff->srcSize;
|
|
|
|
maxNbBlocks = (U32) ((buff->srcSize + (blockSize-1)) / blockSize) + (U32)nbFiles;
|
|
|
|
|
2018-07-27 21:19:55 +00:00
|
|
|
buff->srcPtrs = (const void**)calloc(maxNbBlocks, sizeof(void*));
|
|
|
|
buff->srcSizes = (size_t*)malloc(maxNbBlocks * sizeof(size_t));
|
|
|
|
|
|
|
|
buff->dstPtrs = (void**)calloc(maxNbBlocks, sizeof(void*));
|
|
|
|
buff->dstCapacities = (size_t*)malloc(maxNbBlocks * sizeof(size_t));
|
|
|
|
buff->dstSizes = (size_t*)malloc(maxNbBlocks * sizeof(size_t));
|
|
|
|
|
|
|
|
buff->resPtrs = (void**)calloc(maxNbBlocks, sizeof(void*));
|
2018-08-22 01:19:27 +00:00
|
|
|
buff->resSizes = (size_t*)malloc(maxNbBlocks * sizeof(size_t));
|
2018-07-27 21:19:55 +00:00
|
|
|
|
|
|
|
if(!buff->srcPtrs || !buff->srcSizes || !buff->dstPtrs || !buff->dstCapacities || !buff->dstSizes || !buff->resPtrs || !buff->resSizes) {
|
|
|
|
DISPLAY("alloc error\n");
|
2018-08-09 17:42:35 +00:00
|
|
|
freeNonSrcBuffers(*buff);
|
2018-07-27 21:19:55 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-08-06 22:08:35 +00:00
|
|
|
buff->srcBuffer = srcBuffer;
|
2018-07-27 21:19:55 +00:00
|
|
|
buff->srcPtrs[0] = (const void*)buff->srcBuffer;
|
2018-08-06 22:08:35 +00:00
|
|
|
buff->dstPtrs[0] = malloc(ZSTD_compressBound(buff->srcSize) + (maxNbBlocks * 1024));
|
|
|
|
buff->resPtrs[0] = malloc(buff->srcSize);
|
2018-07-27 21:19:55 +00:00
|
|
|
|
2018-08-06 22:08:35 +00:00
|
|
|
if(!buff->dstPtrs[0] || !buff->resPtrs[0]) {
|
2018-07-27 21:19:55 +00:00
|
|
|
DISPLAY("alloc error\n");
|
2018-08-09 17:42:35 +00:00
|
|
|
freeNonSrcBuffers(*buff);
|
2018-07-27 21:19:55 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-08-06 22:08:35 +00:00
|
|
|
for(n = 0; n < nbFiles; n++) {
|
|
|
|
size_t pos_end = pos + fileSizes[n];
|
|
|
|
for(; pos < pos_end; blockNb++) {
|
|
|
|
buff->srcPtrs[blockNb] = (const void*)((char*)srcBuffer + pos);
|
|
|
|
buff->srcSizes[blockNb] = blockSize;
|
|
|
|
pos += blockSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(fileSizes[n] > 0) { buff->srcSizes[blockNb - 1] = ((fileSizes[n] - 1) % blockSize) + 1; }
|
|
|
|
pos = pos_end;
|
|
|
|
}
|
|
|
|
|
|
|
|
buff->dstCapacities[0] = ZSTD_compressBound(buff->srcSizes[0]);
|
|
|
|
buff->dstSizes[0] = buff->dstCapacities[0];
|
|
|
|
buff->resSizes[0] = buff->srcSizes[0];
|
2018-08-10 23:14:12 +00:00
|
|
|
buff->maxBlockSize = buff->srcSizes[0];
|
2018-08-06 22:08:35 +00:00
|
|
|
|
|
|
|
for(n = 1; n < blockNb; n++) {
|
|
|
|
buff->dstPtrs[n] = ((char*)buff->dstPtrs[n-1]) + buff->dstCapacities[n-1];
|
|
|
|
buff->resPtrs[n] = ((char*)buff->resPtrs[n-1]) + buff->resSizes[n-1];
|
|
|
|
buff->dstCapacities[n] = ZSTD_compressBound(buff->srcSizes[n]);
|
|
|
|
buff->dstSizes[n] = buff->dstCapacities[n];
|
|
|
|
buff->resSizes[n] = buff->srcSizes[n];
|
2018-08-10 23:14:12 +00:00
|
|
|
|
|
|
|
buff->maxBlockSize = MAX(buff->maxBlockSize, buff->srcSizes[n]);
|
2018-08-06 22:08:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
buff->nbBlocks = blockNb;
|
|
|
|
|
|
|
|
return 0;
|
2018-08-22 01:19:27 +00:00
|
|
|
}
|
2018-08-06 22:08:35 +00:00
|
|
|
|
2019-04-12 18:18:11 +00:00
|
|
|
/* allocates buffer's arguments. returns success / failure */
|
2018-08-22 01:19:27 +00:00
|
|
|
static int createBuffers(buffers_t* buff, const char* const * const fileNamesTable,
|
2018-08-06 22:08:35 +00:00
|
|
|
size_t nbFiles) {
|
|
|
|
size_t pos = 0;
|
|
|
|
size_t n;
|
2020-12-08 15:07:28 +00:00
|
|
|
size_t totalSizeToLoad = (size_t)UTIL_getTotalFileSize(fileNamesTable, (U32)nbFiles);
|
2018-08-06 22:08:35 +00:00
|
|
|
size_t benchedSize = MIN(BMK_findMaxMem(totalSizeToLoad * 3) / 3, totalSizeToLoad);
|
|
|
|
size_t* fileSizes = calloc(sizeof(size_t), nbFiles);
|
2018-08-22 01:19:27 +00:00
|
|
|
void* srcBuffer = NULL;
|
|
|
|
int ret = 0;
|
2018-08-06 22:08:35 +00:00
|
|
|
|
2018-08-09 17:42:35 +00:00
|
|
|
if(!totalSizeToLoad || !benchedSize) {
|
|
|
|
ret = 1;
|
|
|
|
DISPLAY("Nothing to Bench\n");
|
|
|
|
goto _cleanUp;
|
|
|
|
}
|
|
|
|
|
|
|
|
srcBuffer = malloc(benchedSize);
|
2018-08-06 22:08:35 +00:00
|
|
|
|
|
|
|
if(!fileSizes || !srcBuffer) {
|
2018-08-09 17:42:35 +00:00
|
|
|
ret = 1;
|
|
|
|
goto _cleanUp;
|
2018-08-06 22:08:35 +00:00
|
|
|
}
|
|
|
|
|
2018-07-27 21:19:55 +00:00
|
|
|
for(n = 0; n < nbFiles; n++) {
|
|
|
|
FILE* f;
|
|
|
|
U64 fileSize = UTIL_getFileSize(fileNamesTable[n]);
|
|
|
|
if (UTIL_isDirectory(fileNamesTable[n])) {
|
|
|
|
DISPLAY("Ignoring %s directory... \n", fileNamesTable[n]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (fileSize == UTIL_FILESIZE_UNKNOWN) {
|
|
|
|
DISPLAY("Cannot evaluate size of %s, ignoring ... \n", fileNamesTable[n]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
f = fopen(fileNamesTable[n], "rb");
|
|
|
|
if (f==NULL) {
|
|
|
|
DISPLAY("impossible to open file %s\n", fileNamesTable[n]);
|
|
|
|
fclose(f);
|
2018-08-09 17:42:35 +00:00
|
|
|
ret = 10;
|
|
|
|
goto _cleanUp;
|
2018-07-27 21:19:55 +00:00
|
|
|
}
|
|
|
|
|
2018-08-14 23:51:39 +00:00
|
|
|
DISPLAYLEVEL(2, "Loading %s... \r", fileNamesTable[n]);
|
2018-07-27 21:19:55 +00:00
|
|
|
|
2018-08-06 22:08:35 +00:00
|
|
|
if (fileSize + pos > benchedSize) fileSize = benchedSize - pos, nbFiles=n; /* buffer too small - stop after this file */
|
2018-07-27 21:19:55 +00:00
|
|
|
{
|
2018-08-22 01:19:27 +00:00
|
|
|
char* buffer = (char*)(srcBuffer);
|
2018-07-27 21:19:55 +00:00
|
|
|
size_t const readSize = fread((buffer)+pos, 1, (size_t)fileSize, f);
|
2018-08-09 17:42:35 +00:00
|
|
|
fclose(f);
|
2018-08-10 23:14:12 +00:00
|
|
|
if (readSize != (size_t)fileSize) {
|
2018-07-27 21:19:55 +00:00
|
|
|
DISPLAY("could not read %s", fileNamesTable[n]);
|
2018-08-09 17:42:35 +00:00
|
|
|
ret = 1;
|
|
|
|
goto _cleanUp;
|
2018-07-27 21:19:55 +00:00
|
|
|
}
|
|
|
|
|
2018-08-06 22:08:35 +00:00
|
|
|
fileSizes[n] = readSize;
|
2018-07-27 21:19:55 +00:00
|
|
|
pos += readSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-06 22:08:35 +00:00
|
|
|
ret = createBuffersFromMemory(buff, srcBuffer, nbFiles, fileSizes);
|
2018-08-09 17:42:35 +00:00
|
|
|
|
|
|
|
_cleanUp:
|
|
|
|
if(ret) { free(srcBuffer); }
|
2018-08-06 22:08:35 +00:00
|
|
|
free(fileSizes);
|
|
|
|
return ret;
|
2018-07-27 21:19:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void freeContexts(const contexts_t ctx) {
|
|
|
|
free(ctx.dictBuffer);
|
|
|
|
ZSTD_freeCCtx(ctx.cctx);
|
|
|
|
ZSTD_freeDCtx(ctx.dctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int createContexts(contexts_t* ctx, const char* dictFileName) {
|
|
|
|
FILE* f;
|
|
|
|
size_t readSize;
|
|
|
|
ctx->cctx = ZSTD_createCCtx();
|
|
|
|
ctx->dctx = ZSTD_createDCtx();
|
2018-09-22 01:23:32 +00:00
|
|
|
assert(ctx->cctx != NULL);
|
|
|
|
assert(ctx->dctx != NULL);
|
|
|
|
|
2018-07-27 21:19:55 +00:00
|
|
|
if(dictFileName == NULL) {
|
|
|
|
ctx->dictSize = 0;
|
|
|
|
ctx->dictBuffer = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
2018-09-22 01:23:32 +00:00
|
|
|
{ U64 const dictFileSize = UTIL_getFileSize(dictFileName);
|
|
|
|
assert(dictFileSize != UTIL_FILESIZE_UNKNOWN);
|
2020-12-08 15:07:28 +00:00
|
|
|
ctx->dictSize = (size_t)dictFileSize;
|
2018-09-22 01:23:32 +00:00
|
|
|
assert((U64)ctx->dictSize == dictFileSize); /* check overflow */
|
|
|
|
}
|
2018-07-27 21:19:55 +00:00
|
|
|
ctx->dictBuffer = malloc(ctx->dictSize);
|
|
|
|
|
|
|
|
f = fopen(dictFileName, "rb");
|
2018-08-22 01:19:27 +00:00
|
|
|
|
2018-09-22 01:23:32 +00:00
|
|
|
if (f==NULL) {
|
2018-07-27 21:19:55 +00:00
|
|
|
DISPLAY("unable to open file\n");
|
|
|
|
freeContexts(*ctx);
|
|
|
|
return 1;
|
|
|
|
}
|
2018-08-22 01:19:27 +00:00
|
|
|
|
2018-09-22 01:23:32 +00:00
|
|
|
if (ctx->dictSize > 64 MB || !(ctx->dictBuffer)) {
|
2018-08-15 21:57:10 +00:00
|
|
|
DISPLAY("dictionary too large\n");
|
|
|
|
fclose(f);
|
|
|
|
freeContexts(*ctx);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
readSize = fread(ctx->dictBuffer, 1, ctx->dictSize, f);
|
2018-09-22 01:23:32 +00:00
|
|
|
fclose(f);
|
|
|
|
if (readSize != ctx->dictSize) {
|
2018-08-15 21:57:10 +00:00
|
|
|
DISPLAY("unable to read file\n");
|
|
|
|
freeContexts(*ctx);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-************************************
|
2018-08-22 01:19:27 +00:00
|
|
|
* Optimizer Memoization Functions
|
2018-08-15 21:57:10 +00:00
|
|
|
**************************************/
|
|
|
|
|
|
|
|
/* return: new length */
|
|
|
|
/* keep old array, will need if iter over strategy. */
|
|
|
|
/* prunes useless params */
|
|
|
|
static size_t sanitizeVarArray(varInds_t* varNew, const size_t varLength, const varInds_t* varArray, const ZSTD_strategy strat) {
|
|
|
|
size_t i, j = 0;
|
|
|
|
for(i = 0; i < varLength; i++) {
|
|
|
|
if( !((varArray[i] == clog_ind && strat == ZSTD_fast)
|
|
|
|
|| (varArray[i] == slog_ind && strat == ZSTD_fast)
|
2018-08-22 01:19:27 +00:00
|
|
|
|| (varArray[i] == slog_ind && strat == ZSTD_dfast)
|
2018-12-06 23:00:52 +00:00
|
|
|
|| (varArray[i] == tlen_ind && strat < ZSTD_btopt && strat != ZSTD_fast))) {
|
2018-08-15 21:57:10 +00:00
|
|
|
varNew[j] = varArray[i];
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return j;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* res should be NUM_PARAMS size */
|
|
|
|
/* constructs varArray from paramValues_t style parameter */
|
|
|
|
/* pass in using dict. */
|
|
|
|
static size_t variableParams(const paramValues_t paramConstraints, varInds_t* res, const int usingDictionary) {
|
|
|
|
varInds_t i;
|
|
|
|
size_t j = 0;
|
|
|
|
for(i = 0; i < NUM_PARAMS; i++) {
|
|
|
|
if(paramConstraints.vals[i] == PARAM_UNSET) {
|
|
|
|
if(i == fadt_ind && !usingDictionary) continue; /* don't use fadt if no dictionary */
|
|
|
|
res[j] = i; j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return j;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* length of memo table given free variables */
|
|
|
|
static size_t memoTableLen(const varInds_t* varyParams, const size_t varyLen) {
|
|
|
|
size_t arrayLen = 1;
|
|
|
|
size_t i;
|
|
|
|
for(i = 0; i < varyLen; i++) {
|
|
|
|
if(varyParams[i] == strt_ind) continue; /* strategy separated by table */
|
|
|
|
arrayLen *= rangetable[varyParams[i]];
|
|
|
|
}
|
|
|
|
return arrayLen;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* returns unique index in memotable of compression parameters */
|
|
|
|
static unsigned memoTableIndDirect(const paramValues_t* ptr, const varInds_t* varyParams, const size_t varyLen) {
|
|
|
|
size_t i;
|
|
|
|
unsigned ind = 0;
|
|
|
|
for(i = 0; i < varyLen; i++) {
|
|
|
|
varInds_t v = varyParams[i];
|
|
|
|
if(v == strt_ind) continue; /* exclude strategy from memotable */
|
|
|
|
ind *= rangetable[v]; ind += (unsigned)invRangeMap(v, ptr->vals[v]);
|
|
|
|
}
|
|
|
|
return ind;
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t memoTableGet(const memoTable_t* memoTableArray, const paramValues_t p) {
|
|
|
|
const memoTable_t mt = memoTableArray[p.vals[strt_ind]];
|
|
|
|
switch(mt.tableType) {
|
|
|
|
case directMap:
|
|
|
|
return mt.table[memoTableIndDirect(&p, mt.varArray, mt.varLen)];
|
|
|
|
case xxhashMap:
|
|
|
|
return mt.table[(XXH64(&p.vals, sizeof(U32) * NUM_PARAMS, 0) >> 3) % mt.tableLen];
|
|
|
|
case noMemo:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 0; /* should never happen, stop compiler warnings */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void memoTableSet(const memoTable_t* memoTableArray, const paramValues_t p, const BYTE value) {
|
|
|
|
const memoTable_t mt = memoTableArray[p.vals[strt_ind]];
|
|
|
|
switch(mt.tableType) {
|
|
|
|
case directMap:
|
|
|
|
mt.table[memoTableIndDirect(&p, mt.varArray, mt.varLen)] = value; break;
|
|
|
|
case xxhashMap:
|
|
|
|
mt.table[(XXH64(&p.vals, sizeof(U32) * NUM_PARAMS, 0) >> 3) % mt.tableLen] = value; break;
|
|
|
|
case noMemo:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* frees all allocated memotables */
|
2018-12-06 23:00:52 +00:00
|
|
|
/* secret contract :
|
2018-12-07 00:16:16 +00:00
|
|
|
* mtAll is a table of (ZSTD_STRATEGY_MAX+1) memoTable_t */
|
2018-08-15 21:57:10 +00:00
|
|
|
static void freeMemoTableArray(memoTable_t* const mtAll) {
|
|
|
|
int i;
|
|
|
|
if(mtAll == NULL) { return; }
|
2018-12-07 00:16:16 +00:00
|
|
|
for(i = 1; i <= (int)ZSTD_STRATEGY_MAX; i++) {
|
2018-08-15 21:57:10 +00:00
|
|
|
free(mtAll[i].table);
|
|
|
|
}
|
|
|
|
free(mtAll);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* inits memotables for all (including mallocs), all strategies */
|
|
|
|
/* takes unsanitized varyParams */
|
2018-12-06 23:00:52 +00:00
|
|
|
static memoTable_t*
|
|
|
|
createMemoTableArray(const paramValues_t p,
|
|
|
|
const varInds_t* const varyParams,
|
|
|
|
const size_t varyLen,
|
|
|
|
const U32 memoTableLog)
|
|
|
|
{
|
2018-12-07 00:16:16 +00:00
|
|
|
memoTable_t* const mtAll = (memoTable_t*)calloc(sizeof(memoTable_t),(ZSTD_STRATEGY_MAX + 1));
|
|
|
|
ZSTD_strategy i, stratMin = ZSTD_STRATEGY_MIN, stratMax = ZSTD_STRATEGY_MAX;
|
2018-08-22 01:19:27 +00:00
|
|
|
|
2018-08-15 21:57:10 +00:00
|
|
|
if(mtAll == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-12-07 00:16:16 +00:00
|
|
|
for(i = 1; i <= (int)ZSTD_STRATEGY_MAX; i++) {
|
2018-08-15 21:57:10 +00:00
|
|
|
mtAll[i].varLen = sanitizeVarArray(mtAll[i].varArray, varyLen, varyParams, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* no memoization */
|
|
|
|
if(memoTableLog == 0) {
|
2018-12-07 00:16:16 +00:00
|
|
|
for(i = 1; i <= (int)ZSTD_STRATEGY_MAX; i++) {
|
2018-08-15 21:57:10 +00:00
|
|
|
mtAll[i].tableType = noMemo;
|
|
|
|
mtAll[i].table = NULL;
|
|
|
|
mtAll[i].tableLen = 0;
|
|
|
|
}
|
|
|
|
return mtAll;
|
|
|
|
}
|
|
|
|
|
2018-08-22 01:19:27 +00:00
|
|
|
|
2018-08-15 21:57:10 +00:00
|
|
|
if(p.vals[strt_ind] != PARAM_UNSET) {
|
|
|
|
stratMin = p.vals[strt_ind];
|
|
|
|
stratMax = p.vals[strt_ind];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for(i = stratMin; i <= stratMax; i++) {
|
|
|
|
size_t mtl = memoTableLen(mtAll[i].varArray, mtAll[i].varLen);
|
|
|
|
mtAll[i].tableType = directMap;
|
|
|
|
|
|
|
|
if(memoTableLog != PARAM_UNSET && mtl > (1ULL << memoTableLog)) { /* use hash table */ /* provide some option to only use hash tables? */
|
|
|
|
mtAll[i].tableType = xxhashMap;
|
2020-12-08 15:07:28 +00:00
|
|
|
mtl = ((size_t)1 << memoTableLog);
|
2018-08-15 21:57:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mtAll[i].table = (BYTE*)calloc(sizeof(BYTE), mtl);
|
|
|
|
mtAll[i].tableLen = mtl;
|
|
|
|
|
|
|
|
if(mtAll[i].table == NULL) {
|
|
|
|
freeMemoTableArray(mtAll);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2018-08-22 01:19:27 +00:00
|
|
|
|
2018-08-15 21:57:10 +00:00
|
|
|
return mtAll;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sets pc to random unmeasured set of parameters */
|
2019-04-12 18:18:11 +00:00
|
|
|
/* specify strategy */
|
2018-08-15 21:57:10 +00:00
|
|
|
static void randomConstrainedParams(paramValues_t* pc, const memoTable_t* memoTableArray, const ZSTD_strategy st)
|
|
|
|
{
|
|
|
|
size_t j;
|
|
|
|
const memoTable_t mt = memoTableArray[st];
|
|
|
|
pc->vals[strt_ind] = st;
|
|
|
|
for(j = 0; j < mt.tableLen; j++) {
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < NUM_PARAMS; i++) {
|
|
|
|
varInds_t v = mt.varArray[i];
|
2018-08-22 01:19:27 +00:00
|
|
|
if(v == strt_ind) continue;
|
2018-08-15 21:57:10 +00:00
|
|
|
pc->vals[v] = rangeMap(v, FUZ_rand(&g_rand) % rangetable[v]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!(memoTableGet(memoTableArray, *pc))) break; /* only pick unpicked params. */
|
2018-07-27 21:19:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-15 21:57:10 +00:00
|
|
|
/*-************************************
|
|
|
|
* Benchmarking Functions
|
|
|
|
**************************************/
|
|
|
|
|
2018-12-08 00:02:24 +00:00
|
|
|
static void display_params_tested(paramValues_t cParams)
|
|
|
|
{
|
|
|
|
varInds_t vi;
|
|
|
|
DISPLAYLEVEL(3, "\r testing :");
|
|
|
|
for (vi=0; vi < NUM_PARAMS; vi++) {
|
fix confusion between unsigned <-> U32
as suggested in #1441.
generally U32 and unsigned are the same thing,
except when they are not ...
case : 32-bit compilation for MIPS (uint32_t == unsigned long)
A vast majority of transformation consists in transforming U32 into unsigned.
In rare cases, it's the other way around (typically for internal code, such as seeds).
Among a few issues this patches solves :
- some parameters were declared with type `unsigned` in *.h,
but with type `U32` in their implementation *.c .
- some parameters have type unsigned*,
but the caller user a pointer to U32 instead.
These fixes are useful.
However, the bulk of changes is about %u formating,
which requires unsigned type,
but generally receives U32 values instead,
often just for brevity (U32 is shorter than unsigned).
These changes are generally minor, or even annoying.
As a consequence, the amount of code changed is larger than I would expect for such a patch.
Testing is also a pain :
it requires manually modifying `mem.h`,
in order to lie about `U32`
and force it to be an `unsigned long` typically.
On a 64-bit system, this will break the equivalence unsigned == U32.
Unfortunately, it will also break a few static_assert(), controlling structure sizes.
So it also requires modifying `debug.h` to make `static_assert()` a noop.
And then reverting these changes.
So it's inconvenient, and as a consequence,
this property is currently not checked during CI tests.
Therefore, these problems can emerge again in the future.
I wonder if it is worth ensuring proper distinction of U32 != unsigned in CI tests.
It's another restriction for coding, adding more frustration during merge tests,
since most platforms don't need this distinction (hence contributor will not see it),
and while this can matter in theory, the number of platforms impacted seems minimal.
Thoughts ?
2018-12-22 00:19:44 +00:00
|
|
|
DISPLAYLEVEL(3, "%3u,", (unsigned)cParams.vals[vi]);
|
2018-12-08 00:02:24 +00:00
|
|
|
}
|
|
|
|
DISPLAYLEVEL(3, "\b \r");
|
|
|
|
}
|
|
|
|
|
2018-08-09 18:38:09 +00:00
|
|
|
/* Replicate functionality of benchMemAdvanced, but with pre-split src / dst buffers */
|
|
|
|
/* The purpose is so that sufficient information is returned so that a decompression call to benchMemInvertible is possible */
|
2018-07-20 21:35:09 +00:00
|
|
|
/* BMK_benchMemAdvanced(srcBuffer,srcSize, dstBuffer, dstSize, fileSizes, nbFiles, 0, &cParams, dictBuffer, dictSize, ctx, dctx, 0, "File", &adv); */
|
2018-08-24 00:21:38 +00:00
|
|
|
/* nbSeconds used in same way as in BMK_advancedParams_t */
|
2018-08-15 22:01:03 +00:00
|
|
|
/* if in decodeOnly, then srcPtr's will be compressed blocks, and uncompressedBlocks will be written to dstPtrs */
|
2018-07-16 23:16:31 +00:00
|
|
|
/* dictionary nullable, nothing else though. */
|
2018-11-13 21:05:39 +00:00
|
|
|
/* note : it would be a lot better if this function was present in benchzstd.c,
|
|
|
|
* sharing code with benchMemAdvanced(), since it's technically a part of it */
|
2018-08-24 00:21:38 +00:00
|
|
|
static BMK_benchOutcome_t
|
|
|
|
BMK_benchMemInvertible( buffers_t buf, contexts_t ctx,
|
|
|
|
int cLevel, const paramValues_t* comprParams,
|
|
|
|
BMK_mode_t mode, unsigned nbSeconds)
|
|
|
|
{
|
2018-07-16 23:16:31 +00:00
|
|
|
U32 i;
|
2018-08-24 00:21:38 +00:00
|
|
|
BMK_benchResult_t bResult;
|
2018-07-20 21:35:09 +00:00
|
|
|
const void *const *const srcPtrs = (const void *const *const)buf.srcPtrs;
|
|
|
|
size_t const *const srcSizes = buf.srcSizes;
|
2018-08-09 18:38:09 +00:00
|
|
|
void** const dstPtrs = buf.dstPtrs;
|
|
|
|
size_t const *const dstCapacities = buf.dstCapacities;
|
|
|
|
size_t* const dstSizes = buf.dstSizes;
|
|
|
|
void** const resPtrs = buf.resPtrs;
|
|
|
|
size_t const *const resSizes = buf.resSizes;
|
2018-07-20 21:35:09 +00:00
|
|
|
const void* dictBuffer = ctx.dictBuffer;
|
|
|
|
const size_t dictBufferSize = ctx.dictSize;
|
|
|
|
const size_t nbBlocks = buf.nbBlocks;
|
|
|
|
const size_t srcSize = buf.srcSize;
|
|
|
|
ZSTD_CCtx* cctx = ctx.cctx;
|
|
|
|
ZSTD_DCtx* dctx = ctx.dctx;
|
2018-07-16 23:16:31 +00:00
|
|
|
|
2018-08-24 00:21:38 +00:00
|
|
|
/* init */
|
2018-12-08 00:02:24 +00:00
|
|
|
display_params_tested(*comprParams);
|
2018-08-24 00:21:38 +00:00
|
|
|
memset(&bResult, 0, sizeof(bResult));
|
|
|
|
|
2019-04-12 18:18:11 +00:00
|
|
|
/* warming up memory */
|
2018-08-24 00:21:38 +00:00
|
|
|
for (i = 0; i < buf.nbBlocks; i++) {
|
|
|
|
if (mode != BMK_decodeOnly) {
|
2018-07-20 21:35:09 +00:00
|
|
|
RDG_genBuffer(dstPtrs[i], dstCapacities[i], 0.10, 0.50, 1);
|
|
|
|
} else {
|
|
|
|
RDG_genBuffer(resPtrs[i], resSizes[i], 0.10, 0.50, 1);
|
|
|
|
}
|
2018-07-16 23:16:31 +00:00
|
|
|
}
|
|
|
|
|
2018-07-20 21:35:09 +00:00
|
|
|
/* Bench */
|
2018-07-16 23:16:31 +00:00
|
|
|
{
|
2018-07-20 21:35:09 +00:00
|
|
|
/* init args */
|
2018-08-24 00:21:38 +00:00
|
|
|
int compressionCompleted = (mode == BMK_decodeOnly);
|
|
|
|
int decompressionCompleted = (mode == BMK_compressOnly);
|
2018-08-28 18:21:09 +00:00
|
|
|
BMK_timedFnState_t* timeStateCompress = BMK_createTimedFnState(nbSeconds * 1000, 1000);
|
|
|
|
BMK_timedFnState_t* timeStateDecompress = BMK_createTimedFnState(nbSeconds * 1000, 1000);
|
2018-11-13 21:05:39 +00:00
|
|
|
BMK_benchParams_t cbp, dbp;
|
2018-07-20 21:35:09 +00:00
|
|
|
BMK_initCCtxArgs cctxprep;
|
|
|
|
BMK_initDCtxArgs dctxprep;
|
2018-11-13 21:05:39 +00:00
|
|
|
|
|
|
|
cbp.benchFn = local_defaultCompress;
|
|
|
|
cbp.benchPayload = cctx;
|
|
|
|
cbp.initFn = local_initCCtx;
|
|
|
|
cbp.initPayload = &cctxprep;
|
|
|
|
cbp.errorFn = ZSTD_isError;
|
|
|
|
cbp.blockCount = nbBlocks;
|
|
|
|
cbp.srcBuffers = srcPtrs;
|
|
|
|
cbp.srcSizes = srcSizes;
|
|
|
|
cbp.dstBuffers = dstPtrs;
|
|
|
|
cbp.dstCapacities = dstCapacities;
|
|
|
|
cbp.blockResults = dstSizes;
|
|
|
|
|
2018-08-24 00:21:38 +00:00
|
|
|
cctxprep.cctx = cctx;
|
2018-07-20 21:35:09 +00:00
|
|
|
cctxprep.dictBuffer = dictBuffer;
|
|
|
|
cctxprep.dictBufferSize = dictBufferSize;
|
|
|
|
cctxprep.cLevel = cLevel;
|
|
|
|
cctxprep.comprParams = comprParams;
|
2018-11-13 21:05:39 +00:00
|
|
|
|
|
|
|
dbp.benchFn = local_defaultDecompress;
|
|
|
|
dbp.benchPayload = dctx;
|
|
|
|
dbp.initFn = local_initDCtx;
|
|
|
|
dbp.initPayload = &dctxprep;
|
|
|
|
dbp.errorFn = ZSTD_isError;
|
|
|
|
dbp.blockCount = nbBlocks;
|
|
|
|
dbp.srcBuffers = (const void* const *) dstPtrs;
|
|
|
|
dbp.srcSizes = dstCapacities;
|
|
|
|
dbp.dstBuffers = resPtrs;
|
|
|
|
dbp.dstCapacities = resSizes;
|
|
|
|
dbp.blockResults = NULL;
|
|
|
|
|
2018-07-20 21:35:09 +00:00
|
|
|
dctxprep.dctx = dctx;
|
|
|
|
dctxprep.dictBuffer = dictBuffer;
|
|
|
|
dctxprep.dictBufferSize = dictBufferSize;
|
|
|
|
|
2018-08-28 18:21:09 +00:00
|
|
|
assert(timeStateCompress != NULL);
|
|
|
|
assert(timeStateDecompress != NULL);
|
2018-08-24 00:21:38 +00:00
|
|
|
while(!compressionCompleted) {
|
2018-11-13 21:05:39 +00:00
|
|
|
BMK_runOutcome_t const cOutcome = BMK_benchTimedFn(timeStateCompress, cbp);
|
2018-08-24 00:21:38 +00:00
|
|
|
|
2018-08-25 00:28:38 +00:00
|
|
|
if (!BMK_isSuccessful_runOutcome(cOutcome)) {
|
2018-08-24 00:21:38 +00:00
|
|
|
BMK_benchOutcome_t bOut;
|
2018-08-25 04:38:09 +00:00
|
|
|
memset(&bOut, 0, sizeof(bOut));
|
2018-08-24 00:21:38 +00:00
|
|
|
bOut.tag = 1; /* should rather be a function or a constant */
|
|
|
|
BMK_freeTimedFnState(timeStateCompress);
|
|
|
|
BMK_freeTimedFnState(timeStateDecompress);
|
|
|
|
return bOut;
|
2018-07-16 23:16:31 +00:00
|
|
|
}
|
2018-08-25 00:28:38 +00:00
|
|
|
{ BMK_runTime_t const rResult = BMK_extract_runTime(cOutcome);
|
2019-01-25 23:38:08 +00:00
|
|
|
bResult.cSpeed = (unsigned long long)((double)srcSize * TIMELOOP_NANOSEC / rResult.nanoSecPerRun);
|
2018-08-24 00:21:38 +00:00
|
|
|
bResult.cSize = rResult.sumOfReturn;
|
2018-07-16 23:16:31 +00:00
|
|
|
}
|
2018-08-27 04:30:18 +00:00
|
|
|
compressionCompleted = BMK_isCompleted_TimedFn(timeStateCompress);
|
2018-08-24 00:21:38 +00:00
|
|
|
}
|
2018-07-16 23:16:31 +00:00
|
|
|
|
2018-08-24 00:21:38 +00:00
|
|
|
while (!decompressionCompleted) {
|
2018-11-13 21:05:39 +00:00
|
|
|
BMK_runOutcome_t const dOutcome = BMK_benchTimedFn(timeStateDecompress, dbp);
|
2018-08-24 00:21:38 +00:00
|
|
|
|
2018-08-25 00:28:38 +00:00
|
|
|
if (!BMK_isSuccessful_runOutcome(dOutcome)) {
|
2018-08-24 00:21:38 +00:00
|
|
|
BMK_benchOutcome_t bOut;
|
2018-08-25 04:38:09 +00:00
|
|
|
memset(&bOut, 0, sizeof(bOut));
|
2018-08-24 00:21:38 +00:00
|
|
|
bOut.tag = 1; /* should rather be a function or a constant */
|
|
|
|
BMK_freeTimedFnState(timeStateCompress);
|
|
|
|
BMK_freeTimedFnState(timeStateDecompress);
|
|
|
|
return bOut;
|
2018-07-20 21:35:09 +00:00
|
|
|
}
|
2018-08-25 00:28:38 +00:00
|
|
|
{ BMK_runTime_t const rResult = BMK_extract_runTime(dOutcome);
|
2019-01-25 23:38:08 +00:00
|
|
|
bResult.dSpeed = (unsigned long long)((double)srcSize * TIMELOOP_NANOSEC / rResult.nanoSecPerRun);
|
2018-07-16 23:16:31 +00:00
|
|
|
}
|
2018-08-27 04:30:18 +00:00
|
|
|
decompressionCompleted = BMK_isCompleted_TimedFn(timeStateDecompress);
|
2018-07-16 23:16:31 +00:00
|
|
|
}
|
2018-08-24 00:21:38 +00:00
|
|
|
|
|
|
|
BMK_freeTimedFnState(timeStateCompress);
|
|
|
|
BMK_freeTimedFnState(timeStateDecompress);
|
2018-07-16 23:16:31 +00:00
|
|
|
}
|
2018-08-24 00:21:38 +00:00
|
|
|
|
2018-07-20 21:35:09 +00:00
|
|
|
/* Bench */
|
2020-12-08 15:07:28 +00:00
|
|
|
bResult.cMem = ((size_t)1 << (comprParams->vals[wlog_ind])) + ZSTD_sizeof_CCtx(cctx);
|
2018-08-24 00:21:38 +00:00
|
|
|
|
|
|
|
{ BMK_benchOutcome_t bOut;
|
|
|
|
bOut.tag = 0;
|
|
|
|
bOut.internal_never_use_directly = bResult; /* should be a function */
|
|
|
|
return bOut;
|
|
|
|
}
|
2018-07-16 23:16:31 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 00:02:24 +00:00
|
|
|
/* BMK_benchParam() :
|
|
|
|
* benchmark a set of `cParams` over sample `buf`,
|
|
|
|
* store the result in `resultPtr`.
|
|
|
|
* @return : 0 if success, 1 if error */
|
2018-08-24 00:21:38 +00:00
|
|
|
static int BMK_benchParam ( BMK_benchResult_t* resultPtr,
|
|
|
|
buffers_t buf, contexts_t ctx,
|
|
|
|
paramValues_t cParams)
|
|
|
|
{
|
|
|
|
BMK_benchOutcome_t const outcome = BMK_benchMemInvertible(buf, ctx,
|
|
|
|
BASE_CLEVEL, &cParams,
|
|
|
|
BMK_both, 3);
|
2018-12-08 00:02:24 +00:00
|
|
|
if (!BMK_isSuccessful_benchOutcome(outcome)) return 1;
|
2018-08-25 04:38:09 +00:00
|
|
|
*resultPtr = BMK_extract_benchResult(outcome);
|
|
|
|
return 0;
|
2018-07-31 00:42:46 +00:00
|
|
|
}
|
|
|
|
|
2018-07-25 00:26:21 +00:00
|
|
|
|
2018-08-15 21:57:10 +00:00
|
|
|
/* Benchmarking which stops when we are sufficiently sure the solution is infeasible / worse than the winner */
|
2018-08-22 01:19:27 +00:00
|
|
|
#define VARIANCE 1.2
|
2018-08-24 00:21:38 +00:00
|
|
|
static int allBench(BMK_benchResult_t* resultPtr,
|
2018-08-15 21:57:10 +00:00
|
|
|
const buffers_t buf, const contexts_t ctx,
|
|
|
|
const paramValues_t cParams,
|
|
|
|
const constraint_t target,
|
2018-08-24 00:21:38 +00:00
|
|
|
BMK_benchResult_t* winnerResult, int feas)
|
|
|
|
{
|
2018-08-28 02:07:17 +00:00
|
|
|
BMK_benchResult_t benchres;
|
2018-08-15 21:57:10 +00:00
|
|
|
double uncertaintyConstantC = 3., uncertaintyConstantD = 3.;
|
|
|
|
double winnerRS;
|
2018-08-28 00:52:04 +00:00
|
|
|
|
2018-10-04 21:27:13 +00:00
|
|
|
BMK_benchOutcome_t const outcome = BMK_benchMemInvertible(buf, ctx, BASE_CLEVEL, &cParams, BMK_both, 2);
|
|
|
|
if (!BMK_isSuccessful_benchOutcome(outcome)) {
|
|
|
|
DEBUGOUTPUT("Benchmarking failed \n");
|
|
|
|
return ERROR_RESULT;
|
|
|
|
}
|
|
|
|
benchres = BMK_extract_benchResult(outcome);
|
2018-07-25 00:26:21 +00:00
|
|
|
|
2018-08-15 21:57:10 +00:00
|
|
|
winnerRS = resultScore(*winnerResult, buf.srcSize, target);
|
2018-10-04 21:27:13 +00:00
|
|
|
DEBUGOUTPUT("WinnerScore: %f \n ", winnerRS);
|
2018-07-25 00:26:21 +00:00
|
|
|
|
2018-08-15 21:57:10 +00:00
|
|
|
*resultPtr = benchres;
|
2018-07-25 00:26:21 +00:00
|
|
|
|
2018-08-15 21:57:10 +00:00
|
|
|
/* anything with worse ratio in feas is definitely worse, discard */
|
|
|
|
if(feas && benchres.cSize < winnerResult->cSize && !g_optmode) {
|
|
|
|
return WORSE_RESULT;
|
2018-08-14 18:57:15 +00:00
|
|
|
}
|
2018-08-13 19:51:22 +00:00
|
|
|
|
2018-10-04 21:27:13 +00:00
|
|
|
/* calculate uncertainty in compression / decompression runs */
|
|
|
|
if (benchres.cSpeed) {
|
|
|
|
U64 const loopDurationC = (((U64)buf.srcSize * TIMELOOP_NANOSEC) / benchres.cSpeed);
|
|
|
|
uncertaintyConstantC = ((loopDurationC + (double)(2 * g_clockGranularity))/loopDurationC);
|
|
|
|
}
|
2018-08-28 00:52:04 +00:00
|
|
|
|
2018-10-04 21:27:13 +00:00
|
|
|
if (benchres.dSpeed) {
|
|
|
|
U64 const loopDurationD = (((U64)buf.srcSize * TIMELOOP_NANOSEC) / benchres.dSpeed);
|
|
|
|
uncertaintyConstantD = ((loopDurationD + (double)(2 * g_clockGranularity))/loopDurationD);
|
|
|
|
}
|
2018-07-25 18:37:20 +00:00
|
|
|
|
2018-08-15 21:57:10 +00:00
|
|
|
/* optimistic assumption of benchres */
|
2018-08-28 02:07:17 +00:00
|
|
|
{ BMK_benchResult_t resultMax = benchres;
|
2019-04-18 22:06:56 +00:00
|
|
|
resultMax.cSpeed = (unsigned long long)(resultMax.cSpeed * uncertaintyConstantC * VARIANCE);
|
|
|
|
resultMax.dSpeed = (unsigned long long)(resultMax.dSpeed * uncertaintyConstantD * VARIANCE);
|
2018-08-28 02:07:17 +00:00
|
|
|
|
|
|
|
/* disregard infeasible results in feas mode */
|
|
|
|
/* disregard if resultMax < winner in infeas mode */
|
|
|
|
if((feas && !feasible(resultMax, target)) ||
|
|
|
|
(!feas && (winnerRS > resultScore(resultMax, buf.srcSize, target)))) {
|
|
|
|
return WORSE_RESULT;
|
|
|
|
}
|
2018-08-15 21:57:10 +00:00
|
|
|
}
|
2018-07-25 18:55:09 +00:00
|
|
|
|
2018-08-15 21:57:10 +00:00
|
|
|
/* compare by resultScore when in infeas */
|
|
|
|
/* compare by compareResultLT when in feas */
|
2018-08-22 01:19:27 +00:00
|
|
|
if((!feas && (resultScore(benchres, buf.srcSize, target) > resultScore(*winnerResult, buf.srcSize, target))) ||
|
|
|
|
(feas && (compareResultLT(*winnerResult, benchres, target, buf.srcSize))) ) {
|
|
|
|
return BETTER_RESULT;
|
|
|
|
} else {
|
|
|
|
return WORSE_RESULT;
|
2018-07-25 18:37:20 +00:00
|
|
|
}
|
2018-07-13 00:30:39 +00:00
|
|
|
}
|
|
|
|
|
2018-08-28 02:07:17 +00:00
|
|
|
|
2018-08-15 21:57:10 +00:00
|
|
|
#define INFEASIBLE_THRESHOLD 200
|
|
|
|
/* Memoized benchmarking, won't benchmark anything which has already been benchmarked before. */
|
2018-08-24 00:21:38 +00:00
|
|
|
static int benchMemo(BMK_benchResult_t* resultPtr,
|
2018-08-22 01:19:27 +00:00
|
|
|
const buffers_t buf, const contexts_t ctx,
|
2018-08-15 21:57:10 +00:00
|
|
|
const paramValues_t cParams,
|
|
|
|
const constraint_t target,
|
2018-08-24 00:21:38 +00:00
|
|
|
BMK_benchResult_t* winnerResult, memoTable_t* const memoTableArray,
|
2018-08-15 21:57:10 +00:00
|
|
|
const int feas) {
|
|
|
|
static int bmcount = 0;
|
|
|
|
int res;
|
2015-10-25 23:06:36 +00:00
|
|
|
|
2018-10-04 21:27:13 +00:00
|
|
|
if ( memoTableGet(memoTableArray, cParams) >= INFEASIBLE_THRESHOLD
|
|
|
|
|| redundantParams(cParams, target, buf.maxBlockSize) ) {
|
|
|
|
return WORSE_RESULT;
|
|
|
|
}
|
2015-10-25 23:06:36 +00:00
|
|
|
|
2018-08-15 21:57:10 +00:00
|
|
|
res = allBench(resultPtr, buf, ctx, cParams, target, winnerResult, feas);
|
2015-10-25 23:06:36 +00:00
|
|
|
|
2018-08-15 21:57:10 +00:00
|
|
|
if(DEBUG && !(bmcount % 250)) {
|
|
|
|
DISPLAY("Count: %d\n", bmcount);
|
|
|
|
bmcount++;
|
|
|
|
}
|
|
|
|
BMK_printWinnerOpt(stdout, CUSTOM_LEVEL, *resultPtr, cParams, target, buf.srcSize);
|
2015-10-27 01:59:12 +00:00
|
|
|
|
2018-08-15 21:57:10 +00:00
|
|
|
if(res == BETTER_RESULT || feas) {
|
|
|
|
memoTableSet(memoTableArray, cParams, 255); /* what happens if collisions are frequent */
|
|
|
|
}
|
|
|
|
return res;
|
2015-10-27 01:59:12 +00:00
|
|
|
}
|
|
|
|
|
2018-08-28 02:07:17 +00:00
|
|
|
|
2018-05-12 02:43:08 +00:00
|
|
|
typedef struct {
|
2018-08-07 00:13:36 +00:00
|
|
|
U64 cSpeed_min;
|
|
|
|
U64 dSpeed_min;
|
2018-05-12 02:43:08 +00:00
|
|
|
U32 windowLog_max;
|
|
|
|
ZSTD_strategy strategy_max;
|
|
|
|
} level_constraints_t;
|
|
|
|
|
2018-05-14 00:25:53 +00:00
|
|
|
static level_constraints_t g_level_constraint[NB_LEVELS_TRACKED+1];
|
2018-05-12 02:43:08 +00:00
|
|
|
|
|
|
|
static void BMK_init_level_constraints(int bytePerSec_level1)
|
|
|
|
{
|
2018-05-14 00:25:53 +00:00
|
|
|
assert(NB_LEVELS_TRACKED >= ZSTD_maxCLevel());
|
2018-05-12 02:43:08 +00:00
|
|
|
memset(g_level_constraint, 0, sizeof(g_level_constraint));
|
|
|
|
g_level_constraint[1].cSpeed_min = bytePerSec_level1;
|
2020-12-03 15:36:45 +00:00
|
|
|
g_level_constraint[1].dSpeed_min = 0;
|
2018-05-12 02:43:08 +00:00
|
|
|
g_level_constraint[1].windowLog_max = 19;
|
|
|
|
g_level_constraint[1].strategy_max = ZSTD_fast;
|
|
|
|
|
|
|
|
/* establish speed objectives (relative to level 1) */
|
|
|
|
{ int l;
|
2018-05-14 00:25:53 +00:00
|
|
|
for (l=2; l<=NB_LEVELS_TRACKED; l++) {
|
2018-05-12 16:40:04 +00:00
|
|
|
g_level_constraint[l].cSpeed_min = (g_level_constraint[l-1].cSpeed_min * 49) / 64;
|
2020-12-03 15:36:45 +00:00
|
|
|
g_level_constraint[l].dSpeed_min = 0;
|
2018-05-12 16:40:04 +00:00
|
|
|
g_level_constraint[l].windowLog_max = (l<20) ? 23 : l+5; /* only --ultra levels >= 20 can use windowlog > 23 */
|
2018-12-07 00:16:16 +00:00
|
|
|
g_level_constraint[l].strategy_max = ZSTD_STRATEGY_MAX;
|
2018-05-12 02:43:08 +00:00
|
|
|
} }
|
|
|
|
}
|
|
|
|
|
2018-12-08 00:02:24 +00:00
|
|
|
static int BMK_seed(winnerInfo_t* winners,
|
|
|
|
const paramValues_t params,
|
|
|
|
const buffers_t buf,
|
|
|
|
const contexts_t ctx)
|
2015-10-25 23:06:36 +00:00
|
|
|
{
|
2018-08-24 00:21:38 +00:00
|
|
|
BMK_benchResult_t testResult;
|
2015-10-25 23:06:36 +00:00
|
|
|
int better = 0;
|
2016-07-27 13:09:11 +00:00
|
|
|
int cLevel;
|
2015-10-25 23:06:36 +00:00
|
|
|
|
2018-08-15 21:00:57 +00:00
|
|
|
BMK_benchParam(&testResult, buf, ctx, params);
|
2015-10-25 23:06:36 +00:00
|
|
|
|
2018-05-14 00:25:53 +00:00
|
|
|
for (cLevel = 1; cLevel <= NB_LEVELS_TRACKED; cLevel++) {
|
2018-12-07 22:07:54 +00:00
|
|
|
|
2018-05-12 02:43:08 +00:00
|
|
|
if (testResult.cSpeed < g_level_constraint[cLevel].cSpeed_min)
|
|
|
|
continue; /* not fast enough for this level */
|
|
|
|
if (testResult.dSpeed < g_level_constraint[cLevel].dSpeed_min)
|
2015-10-28 14:56:48 +00:00
|
|
|
continue; /* not fast enough for this level */
|
2018-08-15 21:00:57 +00:00
|
|
|
if (params.vals[wlog_ind] > g_level_constraint[cLevel].windowLog_max)
|
2018-05-12 02:43:08 +00:00
|
|
|
continue; /* too much memory for this level */
|
2020-12-03 15:36:45 +00:00
|
|
|
if (params.vals[strt_ind] > (U32)g_level_constraint[cLevel].strategy_max)
|
2018-05-12 02:43:08 +00:00
|
|
|
continue; /* forbidden strategy for this level */
|
2016-02-10 12:37:52 +00:00
|
|
|
if (winners[cLevel].result.cSize==0) {
|
2015-10-28 14:56:48 +00:00
|
|
|
/* first solution for this cLevel */
|
|
|
|
winners[cLevel].result = testResult;
|
|
|
|
winners[cLevel].params = params;
|
2018-12-07 22:07:54 +00:00
|
|
|
BMK_print_cLevelEntry(stdout, cLevel, params, testResult, buf.srcSize);
|
2015-10-28 14:56:48 +00:00
|
|
|
better = 1;
|
|
|
|
continue;
|
|
|
|
}
|
2015-10-28 11:32:25 +00:00
|
|
|
|
2016-02-10 12:37:52 +00:00
|
|
|
if ((double)testResult.cSize <= ((double)winners[cLevel].result.cSize * (1. + (0.02 / cLevel))) ) {
|
2015-10-28 11:32:25 +00:00
|
|
|
/* Validate solution is "good enough" */
|
2018-07-31 00:42:46 +00:00
|
|
|
double W_ratio = (double)buf.srcSize / testResult.cSize;
|
|
|
|
double O_ratio = (double)buf.srcSize / winners[cLevel].result.cSize;
|
2015-10-28 14:56:48 +00:00
|
|
|
double W_ratioNote = log (W_ratio);
|
|
|
|
double O_ratioNote = log (O_ratio);
|
2018-08-15 21:57:10 +00:00
|
|
|
size_t W_DMemUsed = (1 << params.vals[wlog_ind]) + (16 KB);
|
|
|
|
size_t O_DMemUsed = (1 << winners[cLevel].params.vals[wlog_ind]) + (16 KB);
|
|
|
|
double W_DMemUsed_note = W_ratioNote * ( 40 + 9*cLevel) - log((double)W_DMemUsed);
|
|
|
|
double O_DMemUsed_note = O_ratioNote * ( 40 + 9*cLevel) - log((double)O_DMemUsed);
|
2018-07-27 15:49:25 +00:00
|
|
|
|
2020-12-08 15:07:28 +00:00
|
|
|
size_t W_CMemUsed = ((size_t)1 << params.vals[wlog_ind]) + ZSTD_estimateCCtxSize_usingCParams(pvalsToCParams(params));
|
|
|
|
size_t O_CMemUsed = ((size_t)1 << winners[cLevel].params.vals[wlog_ind]) + ZSTD_estimateCCtxSize_usingCParams(pvalsToCParams(winners[cLevel].params));
|
2018-08-15 21:57:10 +00:00
|
|
|
double W_CMemUsed_note = W_ratioNote * ( 50 + 13*cLevel) - log((double)W_CMemUsed);
|
|
|
|
double O_CMemUsed_note = O_ratioNote * ( 50 + 13*cLevel) - log((double)O_CMemUsed);
|
2018-08-13 19:51:22 +00:00
|
|
|
|
2020-12-03 15:36:45 +00:00
|
|
|
double W_CSpeed_note = W_ratioNote * (double)( 30 + 10*cLevel) + log(testResult.cSpeed);
|
|
|
|
double O_CSpeed_note = O_ratioNote * (double)( 30 + 10*cLevel) + log(winners[cLevel].result.cSpeed);
|
2018-08-13 19:51:22 +00:00
|
|
|
|
2020-12-03 15:36:45 +00:00
|
|
|
double W_DSpeed_note = W_ratioNote * (double)( 20 + 2*cLevel) + log(testResult.dSpeed);
|
|
|
|
double O_DSpeed_note = O_ratioNote * (double)( 20 + 2*cLevel) + log(winners[cLevel].result.dSpeed);
|
2018-08-15 21:27:07 +00:00
|
|
|
|
2018-08-15 21:57:10 +00:00
|
|
|
if (W_DMemUsed_note < O_DMemUsed_note) {
|
|
|
|
/* uses too much Decompression memory for too little benefit */
|
|
|
|
if (W_ratio > O_ratio)
|
2018-12-08 00:02:24 +00:00
|
|
|
DISPLAYLEVEL(3, "Decompression Memory : %5.3f @ %4.1f MB vs %5.3f @ %4.1f MB : not enough for level %i\n",
|
2018-08-15 21:57:10 +00:00
|
|
|
W_ratio, (double)(W_DMemUsed) / 1024 / 1024,
|
|
|
|
O_ratio, (double)(O_DMemUsed) / 1024 / 1024, cLevel);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (W_CMemUsed_note < O_CMemUsed_note) {
|
|
|
|
/* uses too much memory for compression for too little benefit */
|
|
|
|
if (W_ratio > O_ratio)
|
2018-12-08 00:02:24 +00:00
|
|
|
DISPLAYLEVEL(3, "Compression Memory : %5.3f @ %4.1f MB vs %5.3f @ %4.1f MB : not enough for level %i\n",
|
2018-08-15 21:57:10 +00:00
|
|
|
W_ratio, (double)(W_CMemUsed) / 1024 / 1024,
|
2018-12-08 00:02:24 +00:00
|
|
|
O_ratio, (double)(O_CMemUsed) / 1024 / 1024,
|
|
|
|
cLevel);
|
2018-08-15 21:57:10 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (W_CSpeed_note < O_CSpeed_note ) {
|
|
|
|
/* too large compression speed difference for the compression benefit */
|
|
|
|
if (W_ratio > O_ratio)
|
2018-12-08 00:02:24 +00:00
|
|
|
DISPLAYLEVEL(3, "Compression Speed : %5.3f @ %4.1f MB/s vs %5.3f @ %4.1f MB/s : not enough for level %i\n",
|
2018-08-24 01:04:50 +00:00
|
|
|
W_ratio, (double)testResult.cSpeed / MB_UNIT,
|
2018-12-08 00:02:24 +00:00
|
|
|
O_ratio, (double)winners[cLevel].result.cSpeed / MB_UNIT,
|
|
|
|
cLevel);
|
2018-08-15 21:57:10 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (W_DSpeed_note < O_DSpeed_note ) {
|
|
|
|
/* too large decompression speed difference for the compression benefit */
|
|
|
|
if (W_ratio > O_ratio)
|
2018-12-08 00:02:24 +00:00
|
|
|
DISPLAYLEVEL(3, "Decompression Speed : %5.3f @ %4.1f MB/s vs %5.3f @ %4.1f MB/s : not enough for level %i\n",
|
2018-08-24 01:04:50 +00:00
|
|
|
W_ratio, (double)testResult.dSpeed / MB_UNIT,
|
2018-12-08 00:02:24 +00:00
|
|
|
O_ratio, (double)winners[cLevel].result.dSpeed / MB_UNIT,
|
|
|
|
cLevel);
|
2018-08-15 21:57:10 +00:00
|
|
|
continue;
|
|
|
|
}
|
2018-08-15 21:27:07 +00:00
|
|
|
|
2018-08-15 21:57:10 +00:00
|
|
|
if (W_ratio < O_ratio)
|
2018-12-08 00:02:24 +00:00
|
|
|
DISPLAYLEVEL(3, "Solution %4.3f selected over %4.3f at level %i, due to better secondary statistics \n",
|
|
|
|
W_ratio, O_ratio, cLevel);
|
2018-08-13 19:51:22 +00:00
|
|
|
|
2018-08-15 21:57:10 +00:00
|
|
|
winners[cLevel].result = testResult;
|
|
|
|
winners[cLevel].params = params;
|
2018-12-07 22:07:54 +00:00
|
|
|
BMK_print_cLevelEntry(stdout, cLevel, params, testResult, buf.srcSize);
|
2018-08-13 19:51:22 +00:00
|
|
|
|
2018-08-15 21:57:10 +00:00
|
|
|
better = 1;
|
|
|
|
} }
|
2018-08-13 19:51:22 +00:00
|
|
|
|
2018-08-15 21:57:10 +00:00
|
|
|
return better;
|
2018-07-13 00:30:39 +00:00
|
|
|
}
|
|
|
|
|
2018-08-15 21:57:10 +00:00
|
|
|
/*-************************************
|
|
|
|
* Compression Level Table Generation Functions
|
|
|
|
**************************************/
|
2018-07-31 00:42:46 +00:00
|
|
|
|
2015-11-09 10:39:48 +00:00
|
|
|
#define PARAMTABLELOG 25
|
|
|
|
#define PARAMTABLESIZE (1<<PARAMTABLELOG)
|
|
|
|
#define PARAMTABLEMASK (PARAMTABLESIZE-1)
|
|
|
|
static BYTE g_alreadyTested[PARAMTABLESIZE] = {0}; /* init to zero */
|
2015-10-25 23:06:36 +00:00
|
|
|
|
2018-12-07 22:07:54 +00:00
|
|
|
static BYTE* NB_TESTS_PLAYED(paramValues_t p)
|
|
|
|
{
|
|
|
|
ZSTD_compressionParameters const cParams = pvalsToCParams(sanitizeParams(p));
|
|
|
|
unsigned long long const h64 = XXH64(&cParams, sizeof(cParams), 0);
|
|
|
|
return &g_alreadyTested[(h64 >> 3) & PARAMTABLEMASK];
|
2018-06-18 18:59:45 +00:00
|
|
|
}
|
2015-10-25 23:06:36 +00:00
|
|
|
|
2018-12-07 22:07:54 +00:00
|
|
|
static void playAround(FILE* f,
|
|
|
|
winnerInfo_t* winners,
|
2018-08-15 21:00:57 +00:00
|
|
|
paramValues_t p,
|
2018-08-10 23:14:12 +00:00
|
|
|
const buffers_t buf, const contexts_t ctx)
|
2015-10-26 14:45:58 +00:00
|
|
|
{
|
2018-12-07 22:07:54 +00:00
|
|
|
int nbVariations = 0;
|
2017-11-30 03:11:12 +00:00
|
|
|
UTIL_time_t const clockStart = UTIL_getTime();
|
2015-10-27 12:12:25 +00:00
|
|
|
|
2017-11-30 03:11:12 +00:00
|
|
|
while (UTIL_clockSpanMicro(clockStart) < g_maxVariationTime) {
|
2015-11-27 16:46:14 +00:00
|
|
|
if (nbVariations++ > g_maxNbVariations) break;
|
2018-08-13 19:51:22 +00:00
|
|
|
|
2018-12-07 22:07:54 +00:00
|
|
|
do {
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < 4; i++) {
|
|
|
|
paramVaryOnce(FUZ_rand(&g_rand) % (strt_ind + 1),
|
|
|
|
((FUZ_rand(&g_rand) & 1) << 1) - 1,
|
|
|
|
&p);
|
|
|
|
}
|
2018-12-08 00:02:24 +00:00
|
|
|
} while (!paramValid(p));
|
2015-10-26 14:45:58 +00:00
|
|
|
|
|
|
|
/* exclude faster if already played params */
|
2018-08-15 21:00:57 +00:00
|
|
|
if (FUZ_rand(&g_rand) & ((1 << *NB_TESTS_PLAYED(p))-1))
|
2015-11-01 13:32:59 +00:00
|
|
|
continue;
|
2015-10-26 14:45:58 +00:00
|
|
|
|
|
|
|
/* test */
|
2018-12-07 22:07:54 +00:00
|
|
|
{ BYTE* const b = NB_TESTS_PLAYED(p);
|
|
|
|
(*b)++;
|
|
|
|
}
|
2018-08-15 21:00:57 +00:00
|
|
|
if (!BMK_seed(winners, p, buf, ctx)) continue;
|
2015-10-26 14:45:58 +00:00
|
|
|
|
|
|
|
/* improvement found => search more */
|
2018-12-07 22:07:54 +00:00
|
|
|
BMK_saveAndPrint_cLevelTable(f, winners, buf.srcSize);
|
2018-08-15 21:00:57 +00:00
|
|
|
playAround(f, winners, p, buf, ctx);
|
2015-10-25 23:06:36 +00:00
|
|
|
}
|
|
|
|
|
2015-10-26 14:45:58 +00:00
|
|
|
}
|
|
|
|
|
2018-12-07 22:07:54 +00:00
|
|
|
static void
|
2018-12-08 00:02:24 +00:00
|
|
|
BMK_selectRandomStart( FILE* f,
|
|
|
|
winnerInfo_t* winners,
|
2018-08-10 23:14:12 +00:00
|
|
|
const buffers_t buf, const contexts_t ctx)
|
2015-10-26 14:45:58 +00:00
|
|
|
{
|
2018-05-14 00:25:53 +00:00
|
|
|
U32 const id = FUZ_rand(&g_rand) % (NB_LEVELS_TRACKED+1);
|
2018-08-15 21:00:57 +00:00
|
|
|
if ((id==0) || (winners[id].params.vals[wlog_ind]==0)) {
|
2018-05-12 00:32:26 +00:00
|
|
|
/* use some random entry */
|
2018-08-15 21:00:57 +00:00
|
|
|
paramValues_t const p = adjustParams(cParamsToPVals(pvalsToCParams(randomParams())), /* defaults nonCompression parameters */
|
2018-12-07 22:07:54 +00:00
|
|
|
buf.srcSize, 0);
|
2018-07-31 00:42:46 +00:00
|
|
|
playAround(f, winners, p, buf, ctx);
|
2018-05-12 00:32:26 +00:00
|
|
|
} else {
|
2018-07-31 00:42:46 +00:00
|
|
|
playAround(f, winners, winners[id].params, buf, ctx);
|
2018-05-12 00:32:26 +00:00
|
|
|
}
|
2015-10-25 23:06:36 +00:00
|
|
|
}
|
|
|
|
|
2018-12-07 22:07:54 +00:00
|
|
|
|
|
|
|
/* BMK_generate_cLevelTable() :
|
|
|
|
* test a large number of configurations
|
2019-04-12 18:18:11 +00:00
|
|
|
* and distribute them across compression levels according to speed conditions.
|
2018-12-07 22:07:54 +00:00
|
|
|
* display and save all intermediate results into rfName = "grillResults.txt".
|
|
|
|
* the function automatically stops after g_timeLimit_s.
|
|
|
|
* this function cannot error, it directly exit() in case of problem.
|
|
|
|
*/
|
|
|
|
static void BMK_generate_cLevelTable(const buffers_t buf, const contexts_t ctx)
|
2015-10-25 23:06:36 +00:00
|
|
|
{
|
2018-08-15 21:00:57 +00:00
|
|
|
paramValues_t params;
|
|
|
|
winnerInfo_t winners[NB_LEVELS_TRACKED+1];
|
2016-07-13 14:45:24 +00:00
|
|
|
const char* const rfName = "grillResults.txt";
|
2016-07-12 11:42:10 +00:00
|
|
|
FILE* const f = fopen(rfName, "w");
|
2015-10-25 23:06:36 +00:00
|
|
|
|
2016-07-13 14:45:24 +00:00
|
|
|
/* init */
|
2018-05-12 02:43:08 +00:00
|
|
|
assert(g_singleRun==0);
|
2016-07-13 14:45:24 +00:00
|
|
|
memset(winners, 0, sizeof(winners));
|
|
|
|
if (f==NULL) { DISPLAY("error opening %s \n", rfName); exit(1); }
|
|
|
|
|
2018-05-12 00:32:26 +00:00
|
|
|
if (g_target) {
|
2018-08-24 01:04:50 +00:00
|
|
|
BMK_init_level_constraints(g_target * MB_UNIT);
|
2018-05-12 00:32:26 +00:00
|
|
|
} else {
|
2015-11-05 17:16:59 +00:00
|
|
|
/* baseline config for level 1 */
|
2018-08-15 21:00:57 +00:00
|
|
|
paramValues_t const l1params = cParamsToPVals(ZSTD_getCParams(1, buf.maxBlockSize, ctx.dictSize));
|
2018-08-24 00:21:38 +00:00
|
|
|
BMK_benchResult_t testResult;
|
2018-08-15 21:00:57 +00:00
|
|
|
BMK_benchParam(&testResult, buf, ctx, l1params);
|
2018-05-12 02:43:08 +00:00
|
|
|
BMK_init_level_constraints((int)((testResult.cSpeed * 31) / 32));
|
2016-07-13 14:45:24 +00:00
|
|
|
}
|
2015-10-26 14:45:58 +00:00
|
|
|
|
|
|
|
/* populate initial solution */
|
2016-07-12 11:42:10 +00:00
|
|
|
{ const int maxSeeds = g_noSeed ? 1 : ZSTD_maxCLevel();
|
|
|
|
int i;
|
|
|
|
for (i=0; i<=maxSeeds; i++) {
|
2018-08-15 21:00:57 +00:00
|
|
|
params = cParamsToPVals(ZSTD_getCParams(i, buf.maxBlockSize, 0));
|
2018-07-31 00:42:46 +00:00
|
|
|
BMK_seed(winners, params, buf, ctx);
|
2016-07-12 11:42:10 +00:00
|
|
|
} }
|
2018-12-07 22:07:54 +00:00
|
|
|
BMK_saveAndPrint_cLevelTable(f, winners, buf.srcSize);
|
2015-10-26 14:45:58 +00:00
|
|
|
|
|
|
|
/* start tests */
|
2018-08-06 23:52:17 +00:00
|
|
|
{ const UTIL_time_t grillStart = UTIL_getTime();
|
2016-02-10 12:37:52 +00:00
|
|
|
do {
|
2018-07-31 00:42:46 +00:00
|
|
|
BMK_selectRandomStart(f, winners, buf, ctx);
|
2018-12-07 22:07:54 +00:00
|
|
|
} while (BMK_timeSpan_s(grillStart) < g_timeLimit_s);
|
2015-10-25 23:06:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* end summary */
|
2018-12-07 22:07:54 +00:00
|
|
|
BMK_saveAndPrint_cLevelTable(f, winners, buf.srcSize);
|
2015-10-27 11:18:00 +00:00
|
|
|
DISPLAY("grillParams operations completed \n");
|
2015-10-25 23:06:36 +00:00
|
|
|
|
|
|
|
/* clean up*/
|
2015-10-26 14:45:58 +00:00
|
|
|
fclose(f);
|
2018-05-12 00:32:26 +00:00
|
|
|
}
|
|
|
|
|
2018-08-24 00:21:38 +00:00
|
|
|
|
2018-08-15 21:57:10 +00:00
|
|
|
/*-************************************
|
|
|
|
* Single Benchmark Functions
|
|
|
|
**************************************/
|
|
|
|
|
2018-12-07 22:07:54 +00:00
|
|
|
static int
|
|
|
|
benchOnce(const buffers_t buf, const contexts_t ctx, const int cLevel)
|
|
|
|
{
|
2018-08-24 00:21:38 +00:00
|
|
|
BMK_benchResult_t testResult;
|
2018-08-16 23:13:02 +00:00
|
|
|
g_params = adjustParams(overwriteParams(cParamsToPVals(ZSTD_getCParams(cLevel, buf.maxBlockSize, ctx.dictSize)), g_params), buf.maxBlockSize, ctx.dictSize);
|
2018-08-06 22:08:35 +00:00
|
|
|
|
2018-08-24 00:21:38 +00:00
|
|
|
if (BMK_benchParam(&testResult, buf, ctx, g_params)) {
|
2018-08-06 22:08:35 +00:00
|
|
|
DISPLAY("Error during benchmarking\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
BMK_printWinner(stdout, CUSTOM_LEVEL, testResult, g_params, buf.srcSize);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-08-16 23:13:02 +00:00
|
|
|
static int benchSample(double compressibility, int cLevel)
|
2015-10-25 23:06:36 +00:00
|
|
|
{
|
2018-05-12 00:32:26 +00:00
|
|
|
const char* const name = "Sample 10MB";
|
2018-07-27 21:19:55 +00:00
|
|
|
size_t const benchedSize = 10 MB;
|
2018-08-24 00:21:38 +00:00
|
|
|
void* const srcBuffer = malloc(benchedSize);
|
2018-08-06 22:08:35 +00:00
|
|
|
int ret = 0;
|
2015-10-25 23:06:36 +00:00
|
|
|
|
2018-07-31 00:42:46 +00:00
|
|
|
buffers_t buf;
|
|
|
|
contexts_t ctx;
|
2018-08-22 01:19:27 +00:00
|
|
|
|
2018-08-06 22:08:35 +00:00
|
|
|
if(srcBuffer == NULL) {
|
|
|
|
DISPLAY("Out of Memory\n");
|
|
|
|
return 2;
|
2018-07-31 00:42:46 +00:00
|
|
|
}
|
2015-10-25 23:06:36 +00:00
|
|
|
|
2018-08-15 21:00:57 +00:00
|
|
|
RDG_genBuffer(srcBuffer, benchedSize, compressibility, 0.0, 0);
|
2015-10-25 23:06:36 +00:00
|
|
|
|
2018-08-06 22:08:35 +00:00
|
|
|
if(createBuffersFromMemory(&buf, srcBuffer, 1, &benchedSize)) {
|
|
|
|
DISPLAY("Buffer Creation Error\n");
|
|
|
|
free(srcBuffer);
|
|
|
|
return 3;
|
2018-07-27 21:19:55 +00:00
|
|
|
}
|
|
|
|
|
2018-07-31 00:42:46 +00:00
|
|
|
if(createContexts(&ctx, NULL)) {
|
|
|
|
DISPLAY("Context Creation Error\n");
|
2018-07-27 21:19:55 +00:00
|
|
|
freeBuffers(buf);
|
2018-07-31 00:42:46 +00:00
|
|
|
return 1;
|
2018-07-27 21:19:55 +00:00
|
|
|
}
|
|
|
|
|
2018-07-31 00:42:46 +00:00
|
|
|
/* bench */
|
|
|
|
DISPLAY("\r%79s\r", "");
|
2018-08-15 21:00:57 +00:00
|
|
|
DISPLAY("using %s %i%%: \n", name, (int)(compressibility*100));
|
2018-07-31 00:42:46 +00:00
|
|
|
|
2018-08-06 22:08:35 +00:00
|
|
|
if(g_singleRun) {
|
2018-08-16 23:13:02 +00:00
|
|
|
ret = benchOnce(buf, ctx, cLevel);
|
2018-08-06 22:08:35 +00:00
|
|
|
} else {
|
2018-12-07 22:07:54 +00:00
|
|
|
BMK_generate_cLevelTable(buf, ctx);
|
2018-08-06 22:08:35 +00:00
|
|
|
}
|
2018-07-31 00:42:46 +00:00
|
|
|
|
|
|
|
freeBuffers(buf);
|
|
|
|
freeContexts(ctx);
|
|
|
|
|
2018-08-06 22:08:35 +00:00
|
|
|
return ret;
|
2018-07-27 21:19:55 +00:00
|
|
|
}
|
|
|
|
|
2018-05-12 00:32:26 +00:00
|
|
|
/* benchFiles() :
|
|
|
|
* note: while this function takes a table of filenames,
|
|
|
|
* in practice, only the first filename will be used */
|
2018-09-27 22:13:43 +00:00
|
|
|
static int benchFiles(const char** fileNamesTable, int nbFiles,
|
|
|
|
const char* dictFileName, int cLevel)
|
2015-10-25 23:06:36 +00:00
|
|
|
{
|
2018-07-31 00:42:46 +00:00
|
|
|
buffers_t buf;
|
|
|
|
contexts_t ctx;
|
|
|
|
int ret = 0;
|
2015-10-25 23:06:36 +00:00
|
|
|
|
2018-08-24 00:21:38 +00:00
|
|
|
if (createBuffers(&buf, fileNamesTable, nbFiles)) {
|
2018-07-31 00:42:46 +00:00
|
|
|
DISPLAY("unable to load files\n");
|
|
|
|
return 1;
|
2018-07-27 21:19:55 +00:00
|
|
|
}
|
|
|
|
|
2018-08-24 00:21:38 +00:00
|
|
|
if (createContexts(&ctx, dictFileName)) {
|
2018-07-31 00:42:46 +00:00
|
|
|
DISPLAY("unable to load dictionary\n");
|
|
|
|
freeBuffers(buf);
|
|
|
|
return 2;
|
|
|
|
}
|
2015-10-25 23:06:36 +00:00
|
|
|
|
2018-07-31 00:42:46 +00:00
|
|
|
DISPLAY("\r%79s\r", "");
|
2018-08-24 00:21:38 +00:00
|
|
|
if (nbFiles == 1) {
|
2018-07-31 00:42:46 +00:00
|
|
|
DISPLAY("using %s : \n", fileNamesTable[0]);
|
|
|
|
} else {
|
|
|
|
DISPLAY("using %d Files : \n", nbFiles);
|
|
|
|
}
|
2015-10-25 23:06:36 +00:00
|
|
|
|
2018-08-24 00:21:38 +00:00
|
|
|
if (g_singleRun) {
|
2018-08-16 23:13:02 +00:00
|
|
|
ret = benchOnce(buf, ctx, cLevel);
|
2018-07-31 00:42:46 +00:00
|
|
|
} else {
|
2018-12-07 22:07:54 +00:00
|
|
|
BMK_generate_cLevelTable(buf, ctx);
|
2015-10-25 23:06:36 +00:00
|
|
|
}
|
|
|
|
|
2018-07-31 00:42:46 +00:00
|
|
|
freeBuffers(buf);
|
|
|
|
freeContexts(ctx);
|
|
|
|
return ret;
|
2015-10-25 23:06:36 +00:00
|
|
|
}
|
|
|
|
|
2018-07-20 21:35:09 +00:00
|
|
|
|
2018-08-15 21:57:10 +00:00
|
|
|
/*-************************************
|
|
|
|
* Local Optimization Functions
|
|
|
|
**************************************/
|
2018-06-18 18:59:45 +00:00
|
|
|
|
2018-08-22 01:19:27 +00:00
|
|
|
/* One iteration of hill climbing. Specifically, it first tries all
|
2018-07-30 18:30:38 +00:00
|
|
|
* valid parameter configurations w/ manhattan distance 1 and picks the best one
|
|
|
|
* failing that, it progressively tries candidates further and further away (up to #dim + 2)
|
2018-08-22 01:19:27 +00:00
|
|
|
* if it finds a candidate exceeding winnerInfo, it will repeat. Otherwise, it will stop the
|
|
|
|
* current stage of hill climbing.
|
|
|
|
* Each iteration of hill climbing proceeds in 2 'phases'. Phase 1 climbs according to
|
2018-07-30 18:30:38 +00:00
|
|
|
* the resultScore function, which is effectively a linear increase in reward until it reaches
|
|
|
|
* the constraint-satisfying value, it which point any excess results in only logarithmic reward.
|
|
|
|
* This aims to find some constraint-satisfying point.
|
|
|
|
* Phase 2 optimizes in accordance with what the original function sets out to maximize, with
|
|
|
|
* all feasible solutions valued over all infeasible solutions.
|
|
|
|
*/
|
2018-07-25 18:37:20 +00:00
|
|
|
|
2018-08-22 01:19:27 +00:00
|
|
|
/* sanitize all params here.
|
2018-07-25 18:37:20 +00:00
|
|
|
* all generation after random should be sanitized. (maybe sanitize random)
|
|
|
|
*/
|
2018-08-22 01:19:27 +00:00
|
|
|
static winnerInfo_t climbOnce(const constraint_t target,
|
|
|
|
memoTable_t* mtAll,
|
2018-08-10 23:14:12 +00:00
|
|
|
const buffers_t buf, const contexts_t ctx,
|
2018-08-24 00:21:38 +00:00
|
|
|
const paramValues_t init)
|
|
|
|
{
|
2018-08-22 01:19:27 +00:00
|
|
|
/*
|
2018-07-30 18:30:38 +00:00
|
|
|
* cparam - currently considered 'center'
|
|
|
|
* candidate - params to benchmark/results
|
|
|
|
* winner - best option found so far.
|
|
|
|
*/
|
2018-08-09 17:42:35 +00:00
|
|
|
paramValues_t cparam = init;
|
2018-06-18 18:59:45 +00:00
|
|
|
winnerInfo_t candidateInfo, winnerInfo;
|
|
|
|
int better = 1;
|
2018-07-20 21:35:09 +00:00
|
|
|
int feas = 0;
|
2018-06-18 18:59:45 +00:00
|
|
|
|
2018-07-20 21:35:09 +00:00
|
|
|
winnerInfo = initWinnerInfo(init);
|
|
|
|
candidateInfo = winnerInfo;
|
2018-06-18 18:59:45 +00:00
|
|
|
|
2018-08-24 00:21:38 +00:00
|
|
|
{ winnerInfo_t bestFeasible1 = initWinnerInfo(cparam);
|
2018-07-25 18:55:09 +00:00
|
|
|
DEBUGOUTPUT("Climb Part 1\n");
|
2018-06-18 18:59:45 +00:00
|
|
|
while(better) {
|
2018-08-13 19:51:22 +00:00
|
|
|
int offset;
|
|
|
|
size_t i, dist;
|
|
|
|
const size_t varLen = mtAll[cparam.vals[strt_ind]].varLen;
|
2018-06-18 18:59:45 +00:00
|
|
|
better = 0;
|
2018-07-13 00:30:39 +00:00
|
|
|
DEBUGOUTPUT("Start\n");
|
2018-06-18 18:59:45 +00:00
|
|
|
cparam = winnerInfo.params;
|
|
|
|
candidateInfo.params = cparam;
|
2018-07-30 18:30:38 +00:00
|
|
|
/* all dist-1 candidates */
|
2018-08-24 00:21:38 +00:00
|
|
|
for (i = 0; i < varLen; i++) {
|
|
|
|
for (offset = -1; offset <= 1; offset += 2) {
|
2018-08-06 23:52:17 +00:00
|
|
|
CHECKTIME(winnerInfo);
|
2018-07-20 21:35:09 +00:00
|
|
|
candidateInfo.params = cparam;
|
2019-01-25 23:38:08 +00:00
|
|
|
paramVaryOnce(mtAll[cparam.vals[strt_ind]].varArray[i],
|
|
|
|
offset,
|
|
|
|
&candidateInfo.params);
|
2018-08-22 01:19:27 +00:00
|
|
|
|
2018-08-09 17:42:35 +00:00
|
|
|
if(paramValid(candidateInfo.params)) {
|
2018-07-31 18:13:44 +00:00
|
|
|
int res;
|
2018-08-06 23:52:17 +00:00
|
|
|
res = benchMemo(&candidateInfo.result, buf, ctx,
|
2018-08-13 19:51:22 +00:00
|
|
|
sanitizeParams(candidateInfo.params), target, &winnerInfo.result, mtAll, feas);
|
|
|
|
DEBUGOUTPUT("Res: %d\n", res);
|
2018-07-20 21:35:09 +00:00
|
|
|
if(res == BETTER_RESULT) { /* synonymous with better when called w/ infeasibleBM */
|
|
|
|
winnerInfo = candidateInfo;
|
|
|
|
better = 1;
|
|
|
|
if(compareResultLT(bestFeasible1.result, winnerInfo.result, target, buf.srcSize)) {
|
|
|
|
bestFeasible1 = winnerInfo;
|
|
|
|
}
|
2018-06-18 18:59:45 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-07 22:07:54 +00:00
|
|
|
} /* for (offset = -1; offset <= 1; offset += 2) */
|
2018-08-24 00:21:38 +00:00
|
|
|
} /* for (i = 0; i < varLen; i++) */
|
2018-06-18 18:59:45 +00:00
|
|
|
|
|
|
|
if(better) {
|
|
|
|
continue;
|
|
|
|
}
|
2018-07-20 21:35:09 +00:00
|
|
|
|
2018-12-07 22:07:54 +00:00
|
|
|
for (dist = 2; dist < varLen + 2; dist++) { /* varLen is # dimensions */
|
2020-12-03 15:36:45 +00:00
|
|
|
for (i = 0; i < (1ULL << varLen) / varLen + 2; i++) {
|
2018-06-18 18:59:45 +00:00
|
|
|
int res;
|
2018-08-06 23:52:17 +00:00
|
|
|
CHECKTIME(winnerInfo);
|
2018-06-18 18:59:45 +00:00
|
|
|
candidateInfo.params = cparam;
|
|
|
|
/* param error checking already done here */
|
2018-08-13 19:51:22 +00:00
|
|
|
paramVariation(&candidateInfo.params, mtAll, (U32)dist);
|
2018-07-31 18:13:44 +00:00
|
|
|
|
2018-08-24 00:21:38 +00:00
|
|
|
res = benchMemo(&candidateInfo.result,
|
|
|
|
buf, ctx,
|
|
|
|
sanitizeParams(candidateInfo.params), target,
|
|
|
|
&winnerInfo.result, mtAll, feas);
|
2018-08-13 19:51:22 +00:00
|
|
|
DEBUGOUTPUT("Res: %d\n", res);
|
2018-08-24 00:21:38 +00:00
|
|
|
if (res == BETTER_RESULT) { /* synonymous with better in this case*/
|
2018-06-18 18:59:45 +00:00
|
|
|
winnerInfo = candidateInfo;
|
|
|
|
better = 1;
|
2018-08-24 00:21:38 +00:00
|
|
|
if (compareResultLT(bestFeasible1.result, winnerInfo.result, target, buf.srcSize)) {
|
2018-07-13 00:30:39 +00:00
|
|
|
bestFeasible1 = winnerInfo;
|
2018-06-18 18:59:45 +00:00
|
|
|
}
|
2018-07-31 18:13:44 +00:00
|
|
|
break;
|
2018-06-18 18:59:45 +00:00
|
|
|
}
|
|
|
|
}
|
2018-08-24 00:21:38 +00:00
|
|
|
|
|
|
|
if (better) {
|
2018-07-20 21:35:09 +00:00
|
|
|
break;
|
2018-06-18 18:59:45 +00:00
|
|
|
}
|
2018-08-24 00:21:38 +00:00
|
|
|
} /* for(dist = 2; dist < varLen + 2; dist++) */
|
2018-06-18 18:59:45 +00:00
|
|
|
|
2018-08-24 00:21:38 +00:00
|
|
|
if (!better) { /* infeas -> feas -> stop */
|
|
|
|
if (feas) return winnerInfo;
|
2018-07-20 21:35:09 +00:00
|
|
|
feas = 1;
|
|
|
|
better = 1;
|
|
|
|
winnerInfo = bestFeasible1; /* note with change, bestFeasible may not necessarily be feasible, but if one has been benchmarked, it will be. */
|
2018-07-25 18:55:09 +00:00
|
|
|
DEBUGOUTPUT("Climb Part 2\n");
|
2018-06-18 18:59:45 +00:00
|
|
|
}
|
|
|
|
}
|
2018-07-20 21:35:09 +00:00
|
|
|
winnerInfo = bestFeasible1;
|
2018-06-18 18:59:45 +00:00
|
|
|
}
|
2018-07-16 23:16:31 +00:00
|
|
|
|
2018-06-18 18:59:45 +00:00
|
|
|
return winnerInfo;
|
|
|
|
}
|
|
|
|
|
2018-07-30 18:30:38 +00:00
|
|
|
/* Optimizes for a fixed strategy */
|
2018-06-18 18:59:45 +00:00
|
|
|
|
2019-04-12 18:18:11 +00:00
|
|
|
/* flexible parameters: iterations of failed climbing (or if we do non-random, maybe this is when everything is close to visited)
|
2018-07-30 18:30:38 +00:00
|
|
|
weight more on visit for bad results, less on good results/more on later results / ones with more failures.
|
2018-08-22 01:19:27 +00:00
|
|
|
allocate memoTable here.
|
2018-07-30 18:30:38 +00:00
|
|
|
*/
|
2018-12-07 22:07:54 +00:00
|
|
|
static winnerInfo_t
|
|
|
|
optimizeFixedStrategy(const buffers_t buf, const contexts_t ctx,
|
|
|
|
const constraint_t target, paramValues_t paramTarget,
|
|
|
|
const ZSTD_strategy strat,
|
|
|
|
memoTable_t* memoTableArray, const int tries)
|
|
|
|
{
|
2018-07-13 00:30:39 +00:00
|
|
|
int i = 0;
|
2018-07-31 18:13:44 +00:00
|
|
|
|
2018-08-09 17:42:35 +00:00
|
|
|
paramValues_t init;
|
2018-08-22 01:19:27 +00:00
|
|
|
winnerInfo_t winnerInfo, candidateInfo;
|
2018-07-20 21:35:09 +00:00
|
|
|
winnerInfo = initWinnerInfo(emptyParams());
|
2018-06-18 18:59:45 +00:00
|
|
|
/* so climb is given the right fixed strategy */
|
2018-08-09 17:42:35 +00:00
|
|
|
paramTarget.vals[strt_ind] = strat;
|
2018-06-18 18:59:45 +00:00
|
|
|
/* to pass ZSTD_checkCParams */
|
2018-08-09 17:42:35 +00:00
|
|
|
paramTarget = cParamUnsetMin(paramTarget);
|
2018-06-18 18:59:45 +00:00
|
|
|
|
|
|
|
init = paramTarget;
|
|
|
|
|
2018-08-13 19:51:22 +00:00
|
|
|
for(i = 0; i < tries; i++) {
|
2018-08-22 01:19:27 +00:00
|
|
|
DEBUGOUTPUT("Restart\n");
|
2018-12-07 22:07:54 +00:00
|
|
|
do {
|
|
|
|
randomConstrainedParams(&init, memoTableArray, strat);
|
|
|
|
} while(redundantParams(init, target, buf.maxBlockSize));
|
2018-08-13 19:51:22 +00:00
|
|
|
candidateInfo = climbOnce(target, memoTableArray, buf, ctx, init);
|
2018-12-07 22:07:54 +00:00
|
|
|
if (compareResultLT(winnerInfo.result, candidateInfo.result, target, buf.srcSize)) {
|
2018-06-18 18:59:45 +00:00
|
|
|
winnerInfo = candidateInfo;
|
2018-08-07 01:37:55 +00:00
|
|
|
BMK_printWinnerOpt(stdout, CUSTOM_LEVEL, winnerInfo.result, winnerInfo.params, target, buf.srcSize);
|
2018-07-10 01:37:54 +00:00
|
|
|
i = 0;
|
2018-08-13 19:51:22 +00:00
|
|
|
continue;
|
2018-06-18 18:59:45 +00:00
|
|
|
}
|
2018-08-06 23:52:17 +00:00
|
|
|
CHECKTIME(winnerInfo);
|
2018-06-18 18:59:45 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
return winnerInfo;
|
|
|
|
}
|
|
|
|
|
2018-07-30 18:30:38 +00:00
|
|
|
/* goes best, best-1, best+1, best-2, ... */
|
|
|
|
/* return 0 if nothing remaining */
|
2018-12-07 22:07:54 +00:00
|
|
|
static int nextStrategy(const int currentStrategy, const int bestStrategy)
|
|
|
|
{
|
2018-07-13 00:30:39 +00:00
|
|
|
if(bestStrategy <= currentStrategy) {
|
|
|
|
int candidate = 2 * bestStrategy - currentStrategy - 1;
|
|
|
|
if(candidate < 1) {
|
|
|
|
candidate = currentStrategy + 1;
|
2018-12-07 00:16:16 +00:00
|
|
|
if(candidate > (int)ZSTD_STRATEGY_MAX) {
|
2018-07-13 00:30:39 +00:00
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return candidate;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return candidate;
|
|
|
|
}
|
|
|
|
} else { /* bestStrategy >= currentStrategy */
|
|
|
|
int candidate = 2 * bestStrategy - currentStrategy;
|
2018-12-07 00:16:16 +00:00
|
|
|
if(candidate > (int)ZSTD_STRATEGY_MAX) {
|
2018-07-13 00:30:39 +00:00
|
|
|
candidate = currentStrategy - 1;
|
|
|
|
if(candidate < 1) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return candidate;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return candidate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-26 23:45:00 +00:00
|
|
|
/* experiment with playing with this and decay value */
|
2018-07-27 15:20:31 +00:00
|
|
|
|
2018-07-30 18:30:38 +00:00
|
|
|
/* main fn called when using --optimize */
|
|
|
|
/* Does strategy selection by benchmarking default compression levels
|
2018-08-22 01:19:27 +00:00
|
|
|
* then optimizes by strategy, starting with the best one and moving
|
2018-08-07 18:56:14 +00:00
|
|
|
* progressively moving further away by number
|
2018-08-22 01:19:27 +00:00
|
|
|
* args:
|
2018-08-07 18:56:14 +00:00
|
|
|
* fileNamesTable - list of files to benchmark
|
|
|
|
* nbFiles - length of fileNamesTable
|
|
|
|
* dictFileName - name of dictionary file if one, else NULL
|
|
|
|
* target - performance constraints (cSpeed, dSpeed, cMem)
|
|
|
|
* paramTarget - parameter constraints (i.e. restriction search space to where strategy = ZSTD_fast)
|
|
|
|
* cLevel - compression level to exceed (all solutions must be > lvl in cSpeed + ratio)
|
|
|
|
*/
|
2018-07-26 23:45:00 +00:00
|
|
|
|
2019-01-25 23:38:08 +00:00
|
|
|
static unsigned g_maxTries = 5;
|
2018-07-27 15:20:31 +00:00
|
|
|
#define TRY_DECAY 1
|
|
|
|
|
2018-12-07 22:07:54 +00:00
|
|
|
static int
|
|
|
|
optimizeForSize(const char* const * const fileNamesTable, const size_t nbFiles,
|
|
|
|
const char* dictFileName,
|
|
|
|
constraint_t target, paramValues_t paramTarget,
|
|
|
|
const int cLevelOpt, const int cLevelRun,
|
|
|
|
const U32 memoTableLog)
|
2018-06-18 18:59:45 +00:00
|
|
|
{
|
2018-07-20 21:35:09 +00:00
|
|
|
varInds_t varArray [NUM_PARAMS];
|
2018-07-13 00:30:39 +00:00
|
|
|
int ret = 0;
|
2018-08-13 19:51:22 +00:00
|
|
|
const size_t varLen = variableParams(paramTarget, varArray, dictFileName != NULL);
|
2018-07-20 21:35:09 +00:00
|
|
|
winnerInfo_t winner = initWinnerInfo(emptyParams());
|
2018-08-13 19:51:22 +00:00
|
|
|
memoTable_t* allMT = NULL;
|
2018-08-10 23:14:12 +00:00
|
|
|
paramValues_t paramBase;
|
2018-07-20 21:35:09 +00:00
|
|
|
contexts_t ctx;
|
|
|
|
buffers_t buf;
|
2018-08-06 23:52:17 +00:00
|
|
|
g_time = UTIL_getTime();
|
2018-07-20 21:35:09 +00:00
|
|
|
|
2018-12-07 22:07:54 +00:00
|
|
|
if (createBuffers(&buf, fileNamesTable, nbFiles)) {
|
2018-07-20 21:35:09 +00:00
|
|
|
DISPLAY("unable to load files\n");
|
|
|
|
return 1;
|
|
|
|
}
|
2018-07-13 00:30:39 +00:00
|
|
|
|
2018-12-07 22:07:54 +00:00
|
|
|
if (createContexts(&ctx, dictFileName)) {
|
2018-07-20 21:35:09 +00:00
|
|
|
DISPLAY("unable to load dictionary\n");
|
|
|
|
freeBuffers(buf);
|
|
|
|
return 2;
|
2018-06-18 18:59:45 +00:00
|
|
|
}
|
|
|
|
|
2018-12-07 22:07:54 +00:00
|
|
|
if (nbFiles == 1) {
|
2018-08-14 22:54:07 +00:00
|
|
|
DISPLAYLEVEL(2, "Loading %s... \r", fileNamesTable[0]);
|
2018-07-10 01:37:54 +00:00
|
|
|
} else {
|
2018-08-22 01:19:27 +00:00
|
|
|
DISPLAYLEVEL(2, "Loading %lu Files... \r", (unsigned long)nbFiles);
|
2018-06-18 18:59:45 +00:00
|
|
|
}
|
|
|
|
|
2018-08-10 23:14:12 +00:00
|
|
|
/* sanitize paramTarget */
|
|
|
|
optimizerAdjustInput(¶mTarget, buf.maxBlockSize);
|
|
|
|
paramBase = cParamUnsetMin(paramTarget);
|
2018-07-20 21:35:09 +00:00
|
|
|
|
2018-08-15 21:27:07 +00:00
|
|
|
allMT = createMemoTableArray(paramTarget, varArray, varLen, memoTableLog);
|
2018-07-20 21:35:09 +00:00
|
|
|
|
2018-08-24 00:21:38 +00:00
|
|
|
if (!allMT) {
|
2018-07-20 21:35:09 +00:00
|
|
|
DISPLAY("MemoTable Init Error\n");
|
2018-07-13 00:30:39 +00:00
|
|
|
ret = 2;
|
|
|
|
goto _cleanUp;
|
|
|
|
}
|
2018-08-09 17:42:35 +00:00
|
|
|
|
2018-08-13 19:51:22 +00:00
|
|
|
/* default strictnesses */
|
2018-08-24 00:21:38 +00:00
|
|
|
if (g_strictness == PARAM_UNSET) {
|
2018-07-27 18:47:14 +00:00
|
|
|
if(g_optmode) {
|
2018-08-13 19:51:22 +00:00
|
|
|
g_strictness = 100;
|
2018-07-27 15:20:31 +00:00
|
|
|
} else {
|
|
|
|
g_strictness = 90;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if(0 >= g_strictness || g_strictness > 100) {
|
|
|
|
DISPLAY("Strictness Outside of Bounds\n");
|
|
|
|
ret = 4;
|
|
|
|
goto _cleanUp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-25 00:26:21 +00:00
|
|
|
/* use level'ing mode instead of normal target mode */
|
2018-08-24 00:21:38 +00:00
|
|
|
if (g_optmode) {
|
2018-08-10 23:14:12 +00:00
|
|
|
winner.params = cParamsToPVals(ZSTD_getCParams(cLevelOpt, buf.maxBlockSize, ctx.dictSize));
|
2018-07-20 21:35:09 +00:00
|
|
|
if(BMK_benchParam(&winner.result, buf, ctx, winner.params)) {
|
2018-07-17 01:04:57 +00:00
|
|
|
ret = 3;
|
|
|
|
goto _cleanUp;
|
|
|
|
}
|
2018-08-22 01:19:27 +00:00
|
|
|
|
|
|
|
g_lvltarget = winner.result;
|
2019-04-18 22:06:56 +00:00
|
|
|
g_lvltarget.cSpeed = (g_lvltarget.cSpeed * g_strictness) / 100;
|
|
|
|
g_lvltarget.dSpeed = (g_lvltarget.dSpeed * g_strictness) / 100;
|
|
|
|
g_lvltarget.cSize = (g_lvltarget.cSize * 100) / g_strictness;
|
2018-07-27 23:49:33 +00:00
|
|
|
|
2018-08-22 01:19:27 +00:00
|
|
|
target.cSpeed = (U32)g_lvltarget.cSpeed;
|
|
|
|
target.dSpeed = (U32)g_lvltarget.dSpeed;
|
2018-07-25 00:26:21 +00:00
|
|
|
|
2018-08-09 17:42:35 +00:00
|
|
|
BMK_printWinnerOpt(stdout, cLevelOpt, winner.result, winner.params, target, buf.srcSize);
|
2018-07-17 01:04:57 +00:00
|
|
|
}
|
|
|
|
|
2018-08-06 22:08:35 +00:00
|
|
|
/* Don't want it to return anything worse than the best known result */
|
2018-08-24 00:21:38 +00:00
|
|
|
if (g_singleRun) {
|
|
|
|
BMK_benchResult_t res;
|
2018-08-10 23:14:12 +00:00
|
|
|
g_params = adjustParams(overwriteParams(cParamsToPVals(ZSTD_getCParams(cLevelRun, buf.maxBlockSize, ctx.dictSize)), g_params), buf.maxBlockSize, ctx.dictSize);
|
2018-08-24 00:21:38 +00:00
|
|
|
if (BMK_benchParam(&res, buf, ctx, g_params)) {
|
2018-08-01 01:47:27 +00:00
|
|
|
ret = 45;
|
|
|
|
goto _cleanUp;
|
|
|
|
}
|
|
|
|
if(compareResultLT(winner.result, res, relaxTarget(target), buf.srcSize)) {
|
|
|
|
winner.result = res;
|
|
|
|
winner.params = g_params;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-18 18:59:45 +00:00
|
|
|
/* bench */
|
2018-08-14 22:54:07 +00:00
|
|
|
DISPLAYLEVEL(2, "\r%79s\r", "");
|
2018-07-10 01:37:54 +00:00
|
|
|
if(nbFiles == 1) {
|
2018-08-14 22:54:07 +00:00
|
|
|
DISPLAYLEVEL(2, "optimizing for %s", fileNamesTable[0]);
|
2018-07-10 01:37:54 +00:00
|
|
|
} else {
|
2018-08-14 22:54:07 +00:00
|
|
|
DISPLAYLEVEL(2, "optimizing for %lu Files", (unsigned long)nbFiles);
|
2018-07-10 01:37:54 +00:00
|
|
|
}
|
2018-07-31 00:42:46 +00:00
|
|
|
|
fix confusion between unsigned <-> U32
as suggested in #1441.
generally U32 and unsigned are the same thing,
except when they are not ...
case : 32-bit compilation for MIPS (uint32_t == unsigned long)
A vast majority of transformation consists in transforming U32 into unsigned.
In rare cases, it's the other way around (typically for internal code, such as seeds).
Among a few issues this patches solves :
- some parameters were declared with type `unsigned` in *.h,
but with type `U32` in their implementation *.c .
- some parameters have type unsigned*,
but the caller user a pointer to U32 instead.
These fixes are useful.
However, the bulk of changes is about %u formating,
which requires unsigned type,
but generally receives U32 values instead,
often just for brevity (U32 is shorter than unsigned).
These changes are generally minor, or even annoying.
As a consequence, the amount of code changed is larger than I would expect for such a patch.
Testing is also a pain :
it requires manually modifying `mem.h`,
in order to lie about `U32`
and force it to be an `unsigned long` typically.
On a 64-bit system, this will break the equivalence unsigned == U32.
Unfortunately, it will also break a few static_assert(), controlling structure sizes.
So it also requires modifying `debug.h` to make `static_assert()` a noop.
And then reverting these changes.
So it's inconvenient, and as a consequence,
this property is currently not checked during CI tests.
Therefore, these problems can emerge again in the future.
I wonder if it is worth ensuring proper distinction of U32 != unsigned in CI tests.
It's another restriction for coding, adding more frustration during merge tests,
since most platforms don't need this distinction (hence contributor will not see it),
and while this can matter in theory, the number of platforms impacted seems minimal.
Thoughts ?
2018-12-22 00:19:44 +00:00
|
|
|
if(target.cSpeed != 0) { DISPLAYLEVEL(2," - limit compression speed %u MB/s", (unsigned)(target.cSpeed >> 20)); }
|
|
|
|
if(target.dSpeed != 0) { DISPLAYLEVEL(2, " - limit decompression speed %u MB/s", (unsigned)(target.dSpeed >> 20)); }
|
|
|
|
if(target.cMem != (U32)-1) { DISPLAYLEVEL(2, " - limit memory %u MB", (unsigned)(target.cMem >> 20)); }
|
2018-07-20 21:35:09 +00:00
|
|
|
|
2018-08-14 23:51:39 +00:00
|
|
|
DISPLAYLEVEL(2, "\n");
|
2018-12-07 22:07:54 +00:00
|
|
|
init_clockGranularity();
|
2018-06-18 18:59:45 +00:00
|
|
|
|
2018-08-24 00:21:38 +00:00
|
|
|
{ paramValues_t CParams;
|
2018-06-18 18:59:45 +00:00
|
|
|
|
|
|
|
/* find best solution from default params */
|
2018-12-07 22:07:54 +00:00
|
|
|
{ const int maxSeeds = g_noSeed ? 1 : ZSTD_maxCLevel();
|
2018-07-13 00:30:39 +00:00
|
|
|
DEBUGOUTPUT("Strategy Selection\n");
|
2018-12-07 22:07:54 +00:00
|
|
|
if (paramTarget.vals[strt_ind] == PARAM_UNSET) {
|
2018-08-24 00:21:38 +00:00
|
|
|
BMK_benchResult_t candidate;
|
2018-07-20 21:35:09 +00:00
|
|
|
int i;
|
2018-07-13 00:30:39 +00:00
|
|
|
for (i=1; i<=maxSeeds; i++) {
|
2018-07-20 21:35:09 +00:00
|
|
|
int ec;
|
2018-08-10 23:14:12 +00:00
|
|
|
CParams = overwriteParams(cParamsToPVals(ZSTD_getCParams(i, buf.maxBlockSize, ctx.dictSize)), paramTarget);
|
2018-07-20 21:35:09 +00:00
|
|
|
ec = BMK_benchParam(&candidate, buf, ctx, CParams);
|
2018-08-07 01:37:55 +00:00
|
|
|
BMK_printWinnerOpt(stdout, i, candidate, CParams, target, buf.srcSize);
|
2018-07-20 21:35:09 +00:00
|
|
|
|
|
|
|
if(!ec && compareResultLT(winner.result, candidate, relaxTarget(target), buf.srcSize)) {
|
|
|
|
winner.result = candidate;
|
|
|
|
winner.params = CParams;
|
2018-07-13 00:30:39 +00:00
|
|
|
}
|
2018-07-26 23:45:00 +00:00
|
|
|
|
2018-08-14 23:51:39 +00:00
|
|
|
CHECKTIMEGT(ret, 0, _displayCleanUp); /* if pass time limit, stop */
|
2018-07-26 23:45:00 +00:00
|
|
|
/* if the current params are too slow, just stop. */
|
2018-07-27 23:49:33 +00:00
|
|
|
if(target.cSpeed > candidate.cSpeed * 3 / 2) { break; }
|
2018-06-18 18:59:45 +00:00
|
|
|
}
|
2018-08-09 17:42:35 +00:00
|
|
|
|
|
|
|
BMK_printWinnerOpt(stdout, CUSTOM_LEVEL, winner.result, winner.params, target, buf.srcSize);
|
2018-07-13 00:30:39 +00:00
|
|
|
}
|
|
|
|
}
|
2018-06-18 18:59:45 +00:00
|
|
|
|
2018-07-13 00:30:39 +00:00
|
|
|
DEBUGOUTPUT("Real Opt\n");
|
2018-08-13 19:51:22 +00:00
|
|
|
/* start 'real' optimization */
|
2018-12-07 22:07:54 +00:00
|
|
|
{ int bestStrategy = (int)winner.params.vals[strt_ind];
|
|
|
|
if (paramTarget.vals[strt_ind] == PARAM_UNSET) {
|
2018-08-09 17:42:35 +00:00
|
|
|
int st = bestStrategy;
|
2018-07-27 23:49:33 +00:00
|
|
|
int tries = g_maxTries;
|
2018-07-13 00:30:39 +00:00
|
|
|
|
2018-12-07 22:07:54 +00:00
|
|
|
/* one iterations of hill climbing with the level-defined parameters. */
|
|
|
|
{ winnerInfo_t const w1 = climbOnce(target, allMT, buf, ctx, winner.params);
|
|
|
|
if (compareResultLT(winner.result, w1.result, target, buf.srcSize)) {
|
2018-07-13 00:30:39 +00:00
|
|
|
winner = w1;
|
|
|
|
}
|
2018-08-14 23:51:39 +00:00
|
|
|
CHECKTIMEGT(ret, 0, _displayCleanUp);
|
2018-07-13 00:30:39 +00:00
|
|
|
}
|
|
|
|
|
2018-07-27 15:20:31 +00:00
|
|
|
while(st && tries > 0) {
|
2018-07-27 21:19:55 +00:00
|
|
|
winnerInfo_t wc;
|
2018-07-25 18:55:09 +00:00
|
|
|
DEBUGOUTPUT("StrategySwitch: %s\n", g_stratName[st]);
|
2018-08-22 01:19:27 +00:00
|
|
|
|
2018-08-13 19:51:22 +00:00
|
|
|
wc = optimizeFixedStrategy(buf, ctx, target, paramBase, st, allMT, tries);
|
2018-07-27 15:20:31 +00:00
|
|
|
|
2018-07-20 21:35:09 +00:00
|
|
|
if(compareResultLT(winner.result, wc.result, target, buf.srcSize)) {
|
2018-06-18 18:59:45 +00:00
|
|
|
winner = wc;
|
2018-07-27 23:49:33 +00:00
|
|
|
tries = g_maxTries;
|
2018-07-27 15:20:31 +00:00
|
|
|
bestStrategy = st;
|
|
|
|
} else {
|
|
|
|
st = nextStrategy(st, bestStrategy);
|
|
|
|
tries -= TRY_DECAY;
|
2018-06-18 18:59:45 +00:00
|
|
|
}
|
2018-08-14 23:51:39 +00:00
|
|
|
CHECKTIMEGT(ret, 0, _displayCleanUp);
|
2018-06-18 18:59:45 +00:00
|
|
|
}
|
|
|
|
} else {
|
2018-08-13 19:51:22 +00:00
|
|
|
winner = optimizeFixedStrategy(buf, ctx, target, paramBase, paramTarget.vals[strt_ind], allMT, g_maxTries);
|
2018-06-18 18:59:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* no solution found */
|
|
|
|
if(winner.result.cSize == (size_t)-1) {
|
2018-07-20 21:35:09 +00:00
|
|
|
ret = 1;
|
2018-06-18 18:59:45 +00:00
|
|
|
DISPLAY("No feasible solution found\n");
|
2018-07-20 21:35:09 +00:00
|
|
|
goto _cleanUp;
|
2018-06-18 18:59:45 +00:00
|
|
|
}
|
2018-12-07 22:07:54 +00:00
|
|
|
|
2018-06-18 18:59:45 +00:00
|
|
|
/* end summary */
|
2018-08-22 01:19:27 +00:00
|
|
|
_displayCleanUp:
|
2018-12-07 22:07:54 +00:00
|
|
|
if (g_displayLevel >= 0) {
|
|
|
|
BMK_displayOneResult(stdout, winner, buf.srcSize);
|
|
|
|
}
|
|
|
|
BMK_paramValues_into_commandLine(stdout, winner.params);
|
2018-08-14 23:51:39 +00:00
|
|
|
DISPLAYLEVEL(1, "grillParams size - optimizer completed \n");
|
2018-07-13 00:30:39 +00:00
|
|
|
}
|
2018-12-07 22:07:54 +00:00
|
|
|
|
2018-08-14 23:51:39 +00:00
|
|
|
_cleanUp:
|
2018-07-20 21:35:09 +00:00
|
|
|
freeContexts(ctx);
|
|
|
|
freeBuffers(buf);
|
2018-08-07 01:37:55 +00:00
|
|
|
freeMemoTableArray(allMT);
|
2018-07-13 00:30:39 +00:00
|
|
|
return ret;
|
2015-11-27 16:46:14 +00:00
|
|
|
}
|
|
|
|
|
2018-08-15 21:57:10 +00:00
|
|
|
/*-************************************
|
|
|
|
* CLI parsing functions
|
|
|
|
**************************************/
|
|
|
|
|
|
|
|
/** longCommandWArg() :
|
|
|
|
* check if *stringPtr is the same as longCommand.
|
|
|
|
* If yes, @return 1 and advances *stringPtr to the position which immediately follows longCommand.
|
|
|
|
* @return 0 and doesn't modify *stringPtr otherwise.
|
|
|
|
* from zstdcli.c
|
|
|
|
*/
|
2019-01-25 23:38:08 +00:00
|
|
|
static int longCommandWArg(const char** stringPtr, const char* longCommand)
|
2018-08-15 21:57:10 +00:00
|
|
|
{
|
|
|
|
size_t const comSize = strlen(longCommand);
|
|
|
|
int const result = !strncmp(*stringPtr, longCommand, comSize);
|
|
|
|
if (result) *stringPtr += comSize;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-05-12 19:34:34 +00:00
|
|
|
static void errorOut(const char* msg)
|
|
|
|
{
|
|
|
|
DISPLAY("%s \n", msg); exit(1);
|
|
|
|
}
|
|
|
|
|
2018-05-12 00:32:26 +00:00
|
|
|
/*! readU32FromChar() :
|
|
|
|
* @return : unsigned integer value read from input in `char` format.
|
|
|
|
* allows and interprets K, KB, KiB, M, MB and MiB suffix.
|
|
|
|
* Will also modify `*stringPtr`, advancing it to position where it stopped reading.
|
|
|
|
* Note : function will exit() program if digit sequence overflows */
|
|
|
|
static unsigned readU32FromChar(const char** stringPtr)
|
|
|
|
{
|
2018-05-12 19:34:34 +00:00
|
|
|
const char errorMsg[] = "error: numeric value too large";
|
2018-08-09 17:42:35 +00:00
|
|
|
unsigned sign = 1;
|
2018-05-12 00:32:26 +00:00
|
|
|
unsigned result = 0;
|
2018-08-09 17:42:35 +00:00
|
|
|
if(**stringPtr == '-') { sign = (unsigned)-1; (*stringPtr)++; }
|
2018-05-12 00:32:26 +00:00
|
|
|
while ((**stringPtr >='0') && (**stringPtr <='9')) {
|
|
|
|
unsigned const max = (((unsigned)(-1)) / 10) - 1;
|
2018-05-12 19:34:34 +00:00
|
|
|
if (result > max) errorOut(errorMsg);
|
2019-01-25 23:38:08 +00:00
|
|
|
result *= 10;
|
|
|
|
assert(**stringPtr >= '0');
|
|
|
|
result += (unsigned)(**stringPtr - '0');
|
|
|
|
(*stringPtr)++ ;
|
2018-05-12 00:32:26 +00:00
|
|
|
}
|
|
|
|
if ((**stringPtr=='K') || (**stringPtr=='M')) {
|
|
|
|
unsigned const maxK = ((unsigned)(-1)) >> 10;
|
2018-05-12 19:34:34 +00:00
|
|
|
if (result > maxK) errorOut(errorMsg);
|
2018-05-12 00:32:26 +00:00
|
|
|
result <<= 10;
|
|
|
|
if (**stringPtr=='M') {
|
2018-05-12 19:34:34 +00:00
|
|
|
if (result > maxK) errorOut(errorMsg);
|
2018-05-12 00:32:26 +00:00
|
|
|
result <<= 10;
|
|
|
|
}
|
|
|
|
(*stringPtr)++; /* skip `K` or `M` */
|
|
|
|
if (**stringPtr=='i') (*stringPtr)++;
|
|
|
|
if (**stringPtr=='B') (*stringPtr)++;
|
|
|
|
}
|
2018-08-09 17:42:35 +00:00
|
|
|
return result * sign;
|
2018-05-12 00:32:26 +00:00
|
|
|
}
|
2015-11-27 16:46:14 +00:00
|
|
|
|
2018-08-13 19:51:22 +00:00
|
|
|
static double readDoubleFromChar(const char** stringPtr)
|
|
|
|
{
|
|
|
|
double result = 0, divide = 10;
|
|
|
|
while ((**stringPtr >='0') && (**stringPtr <='9')) {
|
|
|
|
result *= 10, result += **stringPtr - '0', (*stringPtr)++ ;
|
|
|
|
}
|
|
|
|
if(**stringPtr!='.') {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
(*stringPtr)++;
|
|
|
|
while ((**stringPtr >='0') && (**stringPtr <='9')) {
|
2018-08-22 01:19:27 +00:00
|
|
|
result += (double)(**stringPtr - '0') / divide, divide *= 10, (*stringPtr)++ ;
|
2018-08-13 19:51:22 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-07-12 11:42:10 +00:00
|
|
|
static int usage(const char* exename)
|
2015-10-25 23:06:36 +00:00
|
|
|
{
|
|
|
|
DISPLAY( "Usage :\n");
|
|
|
|
DISPLAY( " %s [arg] file\n", exename);
|
|
|
|
DISPLAY( "Arguments :\n");
|
2015-11-23 16:10:19 +00:00
|
|
|
DISPLAY( " file : path to the file used as reference (if none, generates a compressible sample)\n");
|
2015-10-25 23:06:36 +00:00
|
|
|
DISPLAY( " -H/-h : Help (this text + advanced options)\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-02-11 05:23:24 +00:00
|
|
|
static int usage_advanced(void)
|
2015-10-25 23:06:36 +00:00
|
|
|
{
|
|
|
|
DISPLAY( "\nAdvanced options :\n");
|
2018-07-20 21:35:09 +00:00
|
|
|
DISPLAY( " -T# : set level 1 speed objective \n");
|
|
|
|
DISPLAY( " -B# : cut input into blocks of size # (default : single block) \n");
|
|
|
|
DISPLAY( " --optimize= : same as -O with more verbose syntax (see README.md)\n");
|
|
|
|
DISPLAY( " -S : Single run \n");
|
|
|
|
DISPLAY( " --zstd : Single run, parameter selection same as zstdcli \n");
|
|
|
|
DISPLAY( " -P# : generated sample compressibility (default : %.1f%%) \n", COMPRESSIBILITY_DEFAULT * 100);
|
fix confusion between unsigned <-> U32
as suggested in #1441.
generally U32 and unsigned are the same thing,
except when they are not ...
case : 32-bit compilation for MIPS (uint32_t == unsigned long)
A vast majority of transformation consists in transforming U32 into unsigned.
In rare cases, it's the other way around (typically for internal code, such as seeds).
Among a few issues this patches solves :
- some parameters were declared with type `unsigned` in *.h,
but with type `U32` in their implementation *.c .
- some parameters have type unsigned*,
but the caller user a pointer to U32 instead.
These fixes are useful.
However, the bulk of changes is about %u formating,
which requires unsigned type,
but generally receives U32 values instead,
often just for brevity (U32 is shorter than unsigned).
These changes are generally minor, or even annoying.
As a consequence, the amount of code changed is larger than I would expect for such a patch.
Testing is also a pain :
it requires manually modifying `mem.h`,
in order to lie about `U32`
and force it to be an `unsigned long` typically.
On a 64-bit system, this will break the equivalence unsigned == U32.
Unfortunately, it will also break a few static_assert(), controlling structure sizes.
So it also requires modifying `debug.h` to make `static_assert()` a noop.
And then reverting these changes.
So it's inconvenient, and as a consequence,
this property is currently not checked during CI tests.
Therefore, these problems can emerge again in the future.
I wonder if it is worth ensuring proper distinction of U32 != unsigned in CI tests.
It's another restriction for coding, adding more frustration during merge tests,
since most platforms don't need this distinction (hence contributor will not see it),
and while this can matter in theory, the number of platforms impacted seems minimal.
Thoughts ?
2018-12-22 00:19:44 +00:00
|
|
|
DISPLAY( " -t# : Caps runtime of operation in seconds (default : %u seconds (%.1f hours)) \n",
|
|
|
|
(unsigned)g_timeLimit_s, (double)g_timeLimit_s / 3600);
|
2018-07-20 21:35:09 +00:00
|
|
|
DISPLAY( " -v : Prints Benchmarking output\n");
|
|
|
|
DISPLAY( " -D : Next argument dictionary file\n");
|
2018-07-31 00:42:46 +00:00
|
|
|
DISPLAY( " -s : Seperate Files\n");
|
2015-10-25 23:06:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-07-12 11:42:10 +00:00
|
|
|
static int badusage(const char* exename)
|
2015-10-25 23:06:36 +00:00
|
|
|
{
|
|
|
|
DISPLAY("Wrong parameters\n");
|
|
|
|
usage(exename);
|
2015-10-27 01:59:12 +00:00
|
|
|
return 1;
|
2015-10-25 23:06:36 +00:00
|
|
|
}
|
|
|
|
|
2018-12-07 22:07:54 +00:00
|
|
|
#define PARSE_SUB_ARGS(stringLong, stringShort, variable) { \
|
|
|
|
if ( longCommandWArg(&argument, stringLong) \
|
|
|
|
|| longCommandWArg(&argument, stringShort) ) { \
|
|
|
|
variable = readU32FromChar(&argument); \
|
|
|
|
if (argument[0]==',') { \
|
|
|
|
argument++; continue; \
|
|
|
|
} else break; \
|
|
|
|
} }
|
|
|
|
|
2018-08-10 23:14:12 +00:00
|
|
|
/* 1 if successful parse, 0 otherwise */
|
|
|
|
static int parse_params(const char** argptr, paramValues_t* pv) {
|
|
|
|
int matched = 0;
|
|
|
|
const char* argOrig = *argptr;
|
|
|
|
varInds_t v;
|
|
|
|
for(v = 0; v < NUM_PARAMS; v++) {
|
2018-12-07 22:07:54 +00:00
|
|
|
if ( longCommandWArg(argptr,g_shortParamNames[v])
|
|
|
|
|| longCommandWArg(argptr, g_paramNames[v]) ) {
|
2018-08-10 23:14:12 +00:00
|
|
|
if(**argptr == '=') {
|
|
|
|
(*argptr)++;
|
|
|
|
pv->vals[v] = readU32FromChar(argptr);
|
|
|
|
matched = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* reset and try again */
|
|
|
|
*argptr = argOrig;
|
|
|
|
}
|
|
|
|
return matched;
|
2018-08-07 18:56:14 +00:00
|
|
|
}
|
|
|
|
|
2018-08-15 21:57:10 +00:00
|
|
|
/*-************************************
|
|
|
|
* Main
|
|
|
|
**************************************/
|
|
|
|
|
2016-07-12 11:42:10 +00:00
|
|
|
int main(int argc, const char** argv)
|
2015-10-25 23:06:36 +00:00
|
|
|
{
|
|
|
|
int i,
|
|
|
|
filenamesStart=0,
|
|
|
|
result;
|
2016-07-12 11:42:10 +00:00
|
|
|
const char* exename=argv[0];
|
2018-07-20 21:35:09 +00:00
|
|
|
const char* input_filename = NULL;
|
|
|
|
const char* dictFileName = NULL;
|
2015-10-25 23:06:36 +00:00
|
|
|
U32 main_pause = 0;
|
2018-08-09 17:42:35 +00:00
|
|
|
int cLevelOpt = 0, cLevelRun = 0;
|
2018-07-31 00:42:46 +00:00
|
|
|
int seperateFiles = 0;
|
2018-08-15 21:00:57 +00:00
|
|
|
double compressibility = COMPRESSIBILITY_DEFAULT;
|
|
|
|
U32 memoTableLog = PARAM_UNSET;
|
2018-08-22 01:19:27 +00:00
|
|
|
constraint_t target = { 0, 0, (U32)-1 };
|
2018-07-25 00:26:21 +00:00
|
|
|
|
2018-08-09 17:42:35 +00:00
|
|
|
paramValues_t paramTarget = emptyParams();
|
2018-07-31 00:42:46 +00:00
|
|
|
g_params = emptyParams();
|
2018-07-13 00:30:39 +00:00
|
|
|
|
2018-07-27 23:49:33 +00:00
|
|
|
assert(argc>=1); /* for exename */
|
|
|
|
|
2016-04-08 00:02:12 +00:00
|
|
|
for(i=1; i<argc; i++) {
|
2016-07-12 11:42:10 +00:00
|
|
|
const char* argument = argv[i];
|
2018-08-09 17:42:35 +00:00
|
|
|
DEBUGOUTPUT("%d: %s\n", i, argument);
|
2018-05-12 00:32:26 +00:00
|
|
|
assert(argument != NULL);
|
2015-10-27 12:12:25 +00:00
|
|
|
|
|
|
|
if(!strcmp(argument,"--no-seed")) { g_noSeed = 1; continue; }
|
2015-10-25 23:06:36 +00:00
|
|
|
|
2018-06-06 23:19:09 +00:00
|
|
|
if (longCommandWArg(&argument, "--optimize=")) {
|
2018-07-27 21:19:55 +00:00
|
|
|
g_optimizer = 1;
|
2018-06-06 23:19:09 +00:00
|
|
|
for ( ; ;) {
|
2018-08-10 23:14:12 +00:00
|
|
|
if(parse_params(&argument, ¶mTarget)) { if(argument[0] == ',') { argument++; continue; } else break; }
|
2018-08-07 18:56:14 +00:00
|
|
|
PARSE_SUB_ARGS("compressionSpeed=" , "cSpeed=", target.cSpeed);
|
2018-08-22 01:19:27 +00:00
|
|
|
PARSE_SUB_ARGS("decompressionSpeed=", "dSpeed=", target.dSpeed);
|
2018-08-07 18:56:14 +00:00
|
|
|
PARSE_SUB_ARGS("compressionMemory=" , "cMem=", target.cMem);
|
2018-07-25 18:37:20 +00:00
|
|
|
PARSE_SUB_ARGS("strict=", "stc=", g_strictness);
|
2018-07-31 00:42:46 +00:00
|
|
|
PARSE_SUB_ARGS("maxTries=", "tries=", g_maxTries);
|
2018-08-15 21:00:57 +00:00
|
|
|
PARSE_SUB_ARGS("memoLimitLog=", "memLog=", memoTableLog);
|
2019-01-25 23:38:08 +00:00
|
|
|
if (longCommandWArg(&argument, "level=") || longCommandWArg(&argument, "lvl=")) { cLevelOpt = (int)readU32FromChar(&argument); g_optmode = 1; if (argument[0]==',') { argument++; continue; } else break; }
|
2018-08-13 19:51:22 +00:00
|
|
|
if (longCommandWArg(&argument, "speedForRatio=") || longCommandWArg(&argument, "speedRatio=")) { g_ratioMultiplier = readDoubleFromChar(&argument); if (argument[0]==',') { argument++; continue; } else break; }
|
2018-07-27 18:47:14 +00:00
|
|
|
|
2018-06-06 23:19:09 +00:00
|
|
|
DISPLAY("invalid optimization parameter \n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argument[0] != 0) {
|
|
|
|
DISPLAY("invalid --optimize= format\n");
|
|
|
|
return 1; /* check the end of string */
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
} else if (longCommandWArg(&argument, "--zstd=")) {
|
2015-10-26 14:45:58 +00:00
|
|
|
/* Decode command (note : aggregated commands are allowed) */
|
2018-06-01 19:39:39 +00:00
|
|
|
g_singleRun = 1;
|
|
|
|
for ( ; ;) {
|
2018-08-10 23:14:12 +00:00
|
|
|
if(parse_params(&argument, &g_params)) { if(argument[0] == ',') { argument++; continue; } else break; }
|
2019-01-25 23:38:08 +00:00
|
|
|
if (longCommandWArg(&argument, "level=") || longCommandWArg(&argument, "lvl=")) { cLevelRun = (int)readU32FromChar(&argument); g_params = emptyParams(); if (argument[0]==',') { argument++; continue; } else break; }
|
2018-07-31 00:42:46 +00:00
|
|
|
|
2018-06-01 19:39:39 +00:00
|
|
|
DISPLAY("invalid compression parameter \n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-06-01 20:54:08 +00:00
|
|
|
if (argument[0] != 0) {
|
2018-06-01 21:27:53 +00:00
|
|
|
DISPLAY("invalid --zstd= format\n");
|
2018-06-01 20:54:08 +00:00
|
|
|
return 1; /* check the end of string */
|
|
|
|
}
|
2018-06-06 23:19:09 +00:00
|
|
|
continue;
|
2018-06-04 23:32:37 +00:00
|
|
|
/* if not return, success */
|
2018-08-15 01:04:58 +00:00
|
|
|
|
|
|
|
} else if (longCommandWArg(&argument, "--display=")) {
|
|
|
|
/* Decode command (note : aggregated commands are allowed) */
|
|
|
|
memset(g_silenceParams, 1, sizeof(g_silenceParams));
|
|
|
|
for ( ; ;) {
|
|
|
|
int found = 0;
|
|
|
|
varInds_t v;
|
|
|
|
for(v = 0; v < NUM_PARAMS; v++) {
|
|
|
|
if(longCommandWArg(&argument, g_shortParamNames[v]) || longCommandWArg(&argument, g_paramNames[v])) {
|
|
|
|
g_silenceParams[v] = 0;
|
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(longCommandWArg(&argument, "compressionParameters") || longCommandWArg(&argument, "cParams")) {
|
|
|
|
for(v = 0; v <= strt_ind; v++) {
|
|
|
|
g_silenceParams[v] = 0;
|
|
|
|
}
|
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(found) {
|
|
|
|
if(argument[0]==',') {
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DISPLAY("invalid parameter name parameter \n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argument[0] != 0) {
|
|
|
|
DISPLAY("invalid --display format\n");
|
|
|
|
return 1; /* check the end of string */
|
|
|
|
}
|
|
|
|
continue;
|
2018-06-01 19:39:39 +00:00
|
|
|
} else if (argument[0]=='-') {
|
2015-10-27 01:59:12 +00:00
|
|
|
argument++;
|
|
|
|
|
2016-02-10 12:37:52 +00:00
|
|
|
while (argument[0]!=0) {
|
2015-10-25 23:06:36 +00:00
|
|
|
|
|
|
|
switch(argument[0])
|
|
|
|
{
|
|
|
|
/* Display help on usage */
|
|
|
|
case 'h' :
|
|
|
|
case 'H': usage(exename); usage_advanced(); return 0;
|
|
|
|
|
|
|
|
/* Pause at the end (hidden option) */
|
2015-10-27 01:59:12 +00:00
|
|
|
case 'p': main_pause = 1; argument++; break;
|
2015-10-25 23:06:36 +00:00
|
|
|
|
|
|
|
/* Sample compressibility (when no file provided) */
|
|
|
|
case 'P':
|
2015-10-27 01:59:12 +00:00
|
|
|
argument++;
|
2018-05-12 00:32:26 +00:00
|
|
|
{ U32 const proba32 = readU32FromChar(&argument);
|
2018-08-15 21:00:57 +00:00
|
|
|
compressibility = (double)proba32 / 100.;
|
2015-10-25 23:06:36 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2015-10-27 01:59:12 +00:00
|
|
|
/* Run Single conf */
|
|
|
|
case 'S':
|
2015-10-30 14:49:48 +00:00
|
|
|
g_singleRun = 1;
|
|
|
|
argument++;
|
2016-02-10 12:37:52 +00:00
|
|
|
for ( ; ; ) {
|
2015-10-30 14:49:48 +00:00
|
|
|
switch(*argument)
|
|
|
|
{
|
|
|
|
case 'w':
|
|
|
|
argument++;
|
2018-08-09 17:42:35 +00:00
|
|
|
g_params.vals[wlog_ind] = readU32FromChar(&argument);
|
2015-10-30 14:49:48 +00:00
|
|
|
continue;
|
|
|
|
case 'c':
|
|
|
|
argument++;
|
2018-08-09 17:42:35 +00:00
|
|
|
g_params.vals[clog_ind] = readU32FromChar(&argument);
|
2015-10-30 14:49:48 +00:00
|
|
|
continue;
|
|
|
|
case 'h':
|
|
|
|
argument++;
|
2018-08-09 17:42:35 +00:00
|
|
|
g_params.vals[hlog_ind] = readU32FromChar(&argument);
|
2015-10-30 14:49:48 +00:00
|
|
|
continue;
|
|
|
|
case 's':
|
|
|
|
argument++;
|
2018-08-09 17:42:35 +00:00
|
|
|
g_params.vals[slog_ind] = readU32FromChar(&argument);
|
2015-10-30 14:49:48 +00:00
|
|
|
continue;
|
2015-11-01 11:40:22 +00:00
|
|
|
case 'l': /* search length */
|
2015-10-30 14:49:48 +00:00
|
|
|
argument++;
|
2018-11-20 22:56:07 +00:00
|
|
|
g_params.vals[mml_ind] = readU32FromChar(&argument);
|
2015-10-30 14:49:48 +00:00
|
|
|
continue;
|
2016-02-11 05:23:24 +00:00
|
|
|
case 't': /* target length */
|
2015-11-01 11:40:22 +00:00
|
|
|
argument++;
|
2018-08-09 17:42:35 +00:00
|
|
|
g_params.vals[tlen_ind] = readU32FromChar(&argument);
|
2016-02-11 05:23:24 +00:00
|
|
|
continue;
|
|
|
|
case 'S': /* strategy */
|
|
|
|
argument++;
|
2018-08-09 17:42:35 +00:00
|
|
|
g_params.vals[strt_ind] = readU32FromChar(&argument);
|
|
|
|
continue;
|
|
|
|
case 'f': /* forceAttachDict */
|
|
|
|
argument++;
|
|
|
|
g_params.vals[fadt_ind] = readU32FromChar(&argument);
|
2015-11-01 11:40:22 +00:00
|
|
|
continue;
|
2015-10-30 14:49:48 +00:00
|
|
|
case 'L':
|
2018-08-13 23:15:34 +00:00
|
|
|
{ argument++;
|
2019-01-25 23:38:08 +00:00
|
|
|
cLevelRun = (int)readU32FromChar(&argument);
|
2018-07-31 00:42:46 +00:00
|
|
|
g_params = emptyParams();
|
2015-10-30 14:49:48 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
default : ;
|
|
|
|
}
|
2015-10-27 01:59:12 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-06-01 19:39:39 +00:00
|
|
|
|
2015-10-30 14:49:48 +00:00
|
|
|
break;
|
2015-10-27 01:59:12 +00:00
|
|
|
|
2015-11-05 17:16:59 +00:00
|
|
|
/* target level1 speed objective, in MB/s */
|
2015-10-27 11:18:00 +00:00
|
|
|
case 'T':
|
|
|
|
argument++;
|
2018-05-12 00:32:26 +00:00
|
|
|
g_target = readU32FromChar(&argument);
|
2015-10-27 11:18:00 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* cut input into blocks */
|
|
|
|
case 'B':
|
2016-04-08 00:02:12 +00:00
|
|
|
argument++;
|
2018-05-12 00:32:26 +00:00
|
|
|
g_blockSize = readU32FromChar(&argument);
|
fix confusion between unsigned <-> U32
as suggested in #1441.
generally U32 and unsigned are the same thing,
except when they are not ...
case : 32-bit compilation for MIPS (uint32_t == unsigned long)
A vast majority of transformation consists in transforming U32 into unsigned.
In rare cases, it's the other way around (typically for internal code, such as seeds).
Among a few issues this patches solves :
- some parameters were declared with type `unsigned` in *.h,
but with type `U32` in their implementation *.c .
- some parameters have type unsigned*,
but the caller user a pointer to U32 instead.
These fixes are useful.
However, the bulk of changes is about %u formating,
which requires unsigned type,
but generally receives U32 values instead,
often just for brevity (U32 is shorter than unsigned).
These changes are generally minor, or even annoying.
As a consequence, the amount of code changed is larger than I would expect for such a patch.
Testing is also a pain :
it requires manually modifying `mem.h`,
in order to lie about `U32`
and force it to be an `unsigned long` typically.
On a 64-bit system, this will break the equivalence unsigned == U32.
Unfortunately, it will also break a few static_assert(), controlling structure sizes.
So it also requires modifying `debug.h` to make `static_assert()` a noop.
And then reverting these changes.
So it's inconvenient, and as a consequence,
this property is currently not checked during CI tests.
Therefore, these problems can emerge again in the future.
I wonder if it is worth ensuring proper distinction of U32 != unsigned in CI tests.
It's another restriction for coding, adding more frustration during merge tests,
since most platforms don't need this distinction (hence contributor will not see it),
and while this can matter in theory, the number of platforms impacted seems minimal.
Thoughts ?
2018-12-22 00:19:44 +00:00
|
|
|
DISPLAY("using %u KB block size \n", (unsigned)(g_blockSize>>10));
|
2015-10-27 11:18:00 +00:00
|
|
|
break;
|
|
|
|
|
2018-06-04 23:32:37 +00:00
|
|
|
/* caps runtime (in seconds) */
|
|
|
|
case 't':
|
|
|
|
argument++;
|
2018-08-06 23:52:17 +00:00
|
|
|
g_timeLimit_s = readU32FromChar(&argument);
|
2018-06-04 23:32:37 +00:00
|
|
|
break;
|
|
|
|
|
2018-07-31 00:42:46 +00:00
|
|
|
case 's':
|
2018-08-13 19:51:22 +00:00
|
|
|
argument++;
|
2018-07-31 00:42:46 +00:00
|
|
|
seperateFiles = 1;
|
|
|
|
break;
|
|
|
|
|
2018-08-14 21:24:05 +00:00
|
|
|
case 'q':
|
2018-08-15 01:04:58 +00:00
|
|
|
while (argument[0] == 'q') { argument++; g_displayLevel--; }
|
2018-08-14 21:24:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'v':
|
2018-08-15 01:04:58 +00:00
|
|
|
while (argument[0] == 'v') { argument++; g_displayLevel++; }
|
2018-08-14 21:24:05 +00:00
|
|
|
break;
|
|
|
|
|
2018-07-10 01:37:54 +00:00
|
|
|
/* load dictionary file (only applicable for optimizer rn) */
|
|
|
|
case 'D':
|
2018-08-22 01:19:27 +00:00
|
|
|
if(i == argc - 1) { /* last argument, return error. */
|
2018-07-20 21:35:09 +00:00
|
|
|
DISPLAY("Dictionary file expected but not given : %d\n", i);
|
2018-07-10 01:37:54 +00:00
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
i++;
|
|
|
|
dictFileName = argv[i];
|
2018-07-20 21:35:09 +00:00
|
|
|
argument += strlen(argument);
|
2018-07-10 01:37:54 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2015-10-25 23:06:36 +00:00
|
|
|
/* Unknown command */
|
2015-10-27 01:59:12 +00:00
|
|
|
default : return badusage(exename);
|
2015-10-25 23:06:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
continue;
|
2016-04-08 00:02:12 +00:00
|
|
|
} /* if (argument[0]=='-') */
|
2015-10-25 23:06:36 +00:00
|
|
|
|
|
|
|
/* first provided filename is input */
|
|
|
|
if (!input_filename) { input_filename=argument; filenamesStart=i; continue; }
|
|
|
|
}
|
2018-08-06 23:52:17 +00:00
|
|
|
|
2018-08-14 23:51:39 +00:00
|
|
|
/* Welcome message */
|
|
|
|
DISPLAYLEVEL(2, WELCOME_MESSAGE);
|
|
|
|
|
2018-05-12 02:43:08 +00:00
|
|
|
if (filenamesStart==0) {
|
2018-07-27 21:19:55 +00:00
|
|
|
if (g_optimizer) {
|
2018-06-04 20:38:37 +00:00
|
|
|
DISPLAY("Optimizer Expects File\n");
|
2018-06-02 01:02:56 +00:00
|
|
|
return 1;
|
|
|
|
} else {
|
2018-08-16 23:13:02 +00:00
|
|
|
result = benchSample(compressibility, cLevelRun);
|
2018-06-02 01:02:56 +00:00
|
|
|
}
|
2018-05-12 02:43:08 +00:00
|
|
|
} else {
|
2018-07-31 00:42:46 +00:00
|
|
|
if(seperateFiles) {
|
|
|
|
for(i = 0; i < argc - filenamesStart; i++) {
|
|
|
|
if (g_optimizer) {
|
2018-08-15 21:00:57 +00:00
|
|
|
result = optimizeForSize(argv+filenamesStart + i, 1, dictFileName, target, paramTarget, cLevelOpt, cLevelRun, memoTableLog);
|
2018-07-31 00:42:46 +00:00
|
|
|
if(result) { DISPLAY("Error on File %d", i); return result; }
|
|
|
|
} else {
|
2018-08-09 17:42:35 +00:00
|
|
|
result = benchFiles(argv+filenamesStart + i, 1, dictFileName, cLevelRun);
|
2018-07-31 00:42:46 +00:00
|
|
|
if(result) { DISPLAY("Error on File %d", i); return result; }
|
|
|
|
}
|
|
|
|
}
|
2018-05-12 02:43:08 +00:00
|
|
|
} else {
|
2018-07-31 00:42:46 +00:00
|
|
|
if (g_optimizer) {
|
2019-01-25 23:38:08 +00:00
|
|
|
assert(filenamesStart < argc);
|
|
|
|
result = optimizeForSize(argv+filenamesStart, (size_t)(argc-filenamesStart), dictFileName, target, paramTarget, cLevelOpt, cLevelRun, memoTableLog);
|
2018-07-31 00:42:46 +00:00
|
|
|
} else {
|
2018-08-09 17:42:35 +00:00
|
|
|
result = benchFiles(argv+filenamesStart, argc-filenamesStart, dictFileName, cLevelRun);
|
2018-07-31 00:42:46 +00:00
|
|
|
}
|
2018-08-22 01:19:27 +00:00
|
|
|
}
|
2018-07-31 00:42:46 +00:00
|
|
|
}
|
2015-10-25 23:06:36 +00:00
|
|
|
|
|
|
|
if (main_pause) { int unused; printf("press enter...\n"); unused = getchar(); (void)unused; }
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|