Scheduler-test: binary search working

- Result found in typically 6-7 steps;
- running 20 instead of 30 samples seems sufficient

Breaking point in this example at stress-Factor 0.47 with run-time 39ms
This commit is contained in:
Fischlurch 2024-01-03 23:53:44 +01:00
parent bf1eac02dd
commit bdc1b089d7
2 changed files with 14 additions and 61 deletions

View file

@ -291,74 +291,23 @@ SHOW_EXPR(micros);
search_breaking_point()
{
MARK_TEST_FUN
TestChainLoad testLoad{64};
testLoad.configureShape_chain_loadBursts()
.buildTopology()
// .printTopologyDOT()
// .printTopologyStatistics()
;
// Adapted Schedule----------
TRANSIENTLY(work::Config::COMPUTATION_CAPACITY) = 4;
auto LOAD_BASE = 500us;
uint concurrency = 4;
// Build-Performance-test-setup--------
BlockFlowAlloc bFlow;
EngineObserver watch;
Scheduler scheduler{bFlow, watch};
auto testSetup =
testLoad.setupSchedule(scheduler)
.withLoadTimeBase(LOAD_BASE)
.withJobDeadline(50ms)
.withUpfrontPlanning();
auto sqr = [](auto n){ return n*n; };
_Fmt pointFmt{"....·%-2d: t=%4.1f %s Δ=%4.1f %s"};
_Fmt rowFmt {"%4.2f| : ∅=%4.1f ±%4.2f ∅Δ=%4.1f %%%3.1f -- expect:%4.1fms"};
double refTime = testLoad.calcRuntimeReference(LOAD_BASE);
SHOW_EXPR(refTime);
const uint REPETITIONS{30};
for (double stress=0.2; stress < 0.7; stress+=0.03)
{
testSetup.withAdaptedSchedule(stress, concurrency);
array<double, REPETITIONS> runTime;
array<double, REPETITIONS> delta;
for (uint i=0; i<REPETITIONS; ++i)
{
runTime[i] = testSetup.launch_and_wait();
}
double expTime = testSetup.getExpectedEndTime();
double avg = lib::explore(runTime).resultSum() / REPETITIONS;
double avgd = fabs (avg-expTime);
double sdev{0};
uint misses{0};
for (uint i=0; i<REPETITIONS; ++i)
{
sdev += sqr (runTime[i] - avg);
delta[i] = fabs (runTime[i] - expTime);
if (delta[i] > 2000)
++misses;
cout << pointFmt % i % (runTime[i]/1000) % (runTime[i]>avg?"+":"-") % (delta[i]/1000) % (delta[i] > 2000? "":"") <<endl;
}
sdev = sqrt (sdev/REPETITIONS);
cout << rowFmt % stress % (avg/1000) % (sdev/1000) % (avgd/1000) % (double(misses)/REPETITIONS) % (expTime/1000) <<endl;
}
///////////////////////////////////////////////////////////////////////////////////////////////////WIP : draft for testbench-DSL
struct Setup : StressRig
{
usec LOAD_BASE = 500us;
uint CONCURRENCY = 4;
bool showRuns = true;
auto testLoad() { return TestChainLoad<>{64}.configureShape_chain_loadBursts(); }
};
auto [stress,delta,time] = StressRig::with<Setup>().searchBreakingPoint();
///////////////////////////////////////////////////////////////////////////////////////////////////WIP : draft for testbench-DSL
auto [stress,delta,time] = StressRig::with<Setup>().searchBreakingPoint();
SHOW_EXPR(stress)
SHOW_EXPR(delta)
SHOW_EXPR(time)
CHECK (delta > 4.0);
CHECK (0.55 > stress and stress > 0.4);
}

View file

@ -159,13 +159,14 @@ namespace test {
REQUIRE (lower <= upper);
while ((upper-lower) >= epsilon)
{
PAR div = (upper-lower) / 2;
PAR div = lower + (upper-lower) / 2;
results.emplace_back (fun(div));
bool hit = results.back().first;
if (hit)
upper = div;
else
lower = div;
cout<<"##################LOOP lower="<<lower<<" div="<<div<<" upper="<<upper<<" hit="<<hit<<endl;
}
return results;
}
@ -251,6 +252,7 @@ namespace test {
++ pf;
showRun(i, delta, runTime[i], runTime[i] > avgT, fail);
}
pf /= CONF::REPETITIONS;
sdev = sqrt (sdev/CONF::REPETITIONS);
showStep(res);
return res;
@ -300,7 +302,7 @@ namespace test {
}
_Fmt fmtRun_ {"....·%-2d: Δ=%4.1f t=%4.1f %s %s"}; // i % Δ % t % t>avg? % fail?
_Fmt fmtRun_ {"....·%-2d: Δ=%4.1f t=%4.1f %s %s"}; // i % Δ % t % t>avg? % fail?
_Fmt fmtStep_{ "%4.2f| : ∅Δ=%4.1f±%-4.2f ∅t=%4.1f %%%3.1f -- expect:%4.1fms"}; // stress % ∅Δ % σ % ∅t % fail % t-expect
_Fmt fmtResSDv_{"%9s= %5.2f ±%4.2f%s"};
_Fmt fmtResVal_{"%9s: %5.2f%s"};
@ -328,14 +330,14 @@ namespace test {
{
cout << fmtResVal_ % "stresFac" % res.stressFac % "" <<endl;
cout << fmtResVal_ % "fail" %(res.percentOff * 100) % '%' <<endl;
cout << fmtResSDv_ % "∅Δ" % res.avgDelta % res.stdDev % "ms"<<endl;
cout << fmtResSDv_ % "delta" % res.avgDelta % res.stdDev % "ms"<<endl;
cout << fmtResVal_ % "runTime" % res.avgTime % "ms"<<endl;
cout << fmtResVal_ % "expected" % res.expTime % "ms"<<endl;
}
}
void
showRef(TestLoad testLoad)
showRef(TestLoad& testLoad)
{
if (CONF::showRef)
cout << fmtResVal_ % "refTime"
@ -366,6 +368,8 @@ namespace test {
};
Res res = conductBinarySearch (move (performEvaluation));
showRes (res);
showRef (testLoad);
return make_tuple (res.stressFac, res.avgDelta, res.avgTime);
}
};
@ -394,7 +398,7 @@ namespace test {
bool showRes = true; ///< print result data
bool showRef = true; ///< calculate single threaded reference time
static uint constexpr REPETITIONS{30};
static uint constexpr REPETITIONS{20};
BlockFlowAlloc bFlow{};
EngineObserver watch{};