5#ifndef LINE_API_DA_DA_CACHEQN_H
6#define LINE_API_DA_DA_CACHEQN_H
55 std::vector<std::vector<std::vector<Matrix<T> > > >
Rcost;
56 std::vector<lang::ReplacementStrategy>
strat;
88 for (std::size_t ci = 0; ci < info.
gamma.size(); ++ci) {
89 if (info.
gamma[ci].rows() == 0)
continue;
90 const std::size_t ni = info.
gamma[ci].rows();
91 const std::size_t hi = info.
itemcap[ci].size();
93 std::vector<T> mT(hi);
94 for (std::size_t l = 0; l < hi; ++l)
102 std::numeric_limits<double>::quiet_NaN()));
141 const std::function<std::vector<T>(
const Matrix<T>&,
142 const std::vector<int>&,
145 const std::vector<int>&)>&
148 const std::size_t I =
sn.nodes.size(), K =
sn.nclasses;
150 std::vector<std::size_t> caches;
151 for (std::size_t nd = 0; nd < I; ++nd)
152 if (
sn.nodes[nd].nodetype == qn::NodeType::Cache) caches.push_back(nd);
153 const std::size_t ncaches = caches.size();
157 for (std::size_t a : caches) {
159 for (std::size_t b : caches) {
160 if (a == b)
continue;
161 for (std::size_t r = 0; r < ca.
hitclass.size(); ++r) {
163 for (std::size_t o : outs) {
164 if (o == 0)
continue;
165 for (std::size_t s = 0; s < K; ++s)
166 if (
sn.rtnodes(a * K + (o - 1), b * K + s) > zero)
168 "The cache fixed point does not support a cache network in which cache " +
169 sn.nodes[a].name +
" feeds cache " +
sn.nodes[b].name +
"; use CTMC, SSA or LDES.");
177 std::vector<std::vector<bool> > conn(I, std::vector<bool>(I,
false));
178 for (std::size_t a = 0; a < I; ++a)
179 for (std::size_t b = 0; b < I; ++b) {
180 if (a == b)
continue;
181 for (std::size_t r = 0; r < K && !conn[a][b]; ++r)
182 for (std::size_t s = 0; s < K && !conn[a][b]; ++s)
183 if (
sn.rtnodes(a * K + r, b * K + s) > zero) conn[a][b] =
true;
189 outr.
info.gamma.resize(ncaches);
190 outr.
info.itemcap.resize(ncaches);
191 outr.
info.lambda_cache.resize(ncaches);
192 outr.
info.Rcost.resize(ncaches);
193 outr.
info.strat.resize(ncaches);
194 outr.
info.itemsize.resize(ncaches);
195 outr.
info.costcap.resize(ncaches);
198 std::vector<T> lambda0(K, zero);
199 for (std::size_t ci = 0; ci < ncaches; ++ci) {
201 for (std::size_t r = 0; r < ch.
hitclass.size(); ++r)
204 sn.nodes[caches[ci]].nodetype = qn::NodeType::ClassSwitch;
216 auto sweep = [&](
const std::vector<T>& x,
217 std::size_t) -> std::pair<std::vector<T>, std::vector<T> > {
218 std::vector<T> lambda = x;
219 for (std::size_t ci = 0; ci < ncaches; ++ci) {
220 const std::size_t ind = caches[ci];
238 std::vector<T> missrate(K, zero);
241 for (std::size_t v = 0; v < mr.size() && v < K; ++v) missrate[v] = mr[v];
247 "MVA does not support exact solution of the specified cache replacement policy.");
249 const std::size_t n = cm.pij.rows(), h = cm.pij.cols();
250 std::vector<T> pmiss(n, zero);
251 for (std::size_t k = 0; k < n; ++k) {
253 for (std::size_t l = 0; l < h; ++l) s = T(s + cm.pij(k, l));
254 pmiss[k] = T(one - s);
256 for (std::size_t v = 0; v < iso.
lambda_cache.size() && v < K; ++v) {
258 for (std::size_t k = 0; k < n; ++k)
265 const std::size_t n = ch.
nitems;
267 for (std::size_t v = 0; v < u; ++v)
268 for (std::size_t k = 0; k < n; ++k) lam_un(v, k) = iso.
lambda_cache[v](k, 0);
273 for (std::size_t v = 0; v < mr.
MU.size() && v < K; ++v) missrate[v] = mr.
MU[v];
278 std::vector<T> mT(ch.
itemcap.size());
279 for (std::size_t l = 0; l < ch.
itemcap.size(); ++l)
288 "MVA does not support approximate solution of the specified cache replacement policy.");
290 for (std::size_t v = 0; v < u && v < K; ++v) {
292 for (std::size_t k = 0; k < n; ++k)
293 acc = T(acc + lam_un(v, k) * pij(k, 0));
299 for (std::size_t r = 0; r < K; ++r) {
300 if (lambda[r] > zero) {
301 outr.
missprob(ci, r) = T(missrate[r] / lambda[r]);
315 for (std::size_t r = 0; r < ch.
hitclass.size(); ++r) {
318 for (std::size_t col = 0; col < I * K; ++col)
sn.rtnodes(ind * K + r, col) = zero;
319 for (std::size_t jnd = 0; jnd < I; ++jnd) {
320 if (!conn[ind][jnd])
continue;
321 sn.rtnodes(ind * K + r, jnd * K + hc) = outr.
hitprob(ci, r);
322 sn.rtnodes(ind * K + r, jnd * K +
mc) = outr.
missprob(ci, r);
332 for (std::size_t i = 0; i < I; ++i) {
333 if (
sn.nodes[i].nodetype == qn::NodeType::Cache ||
334 sn.nodes[i].nodetype == qn::NodeType::ClassSwitch)
336 std::size_t nsucc = 0;
337 for (std::size_t j = 0; j < I; ++j)
338 if (conn[i][j]) ++nsucc;
339 if (nsucc == 0)
continue;
341 for (std::size_t s = 0; s < K; ++s) {
343 for (std::size_t col = 0; col < I * K; ++col) rowsum = T(rowsum +
sn.rtnodes(i * K + s, col));
344 if (rowsum > zero)
continue;
345 for (std::size_t j = 0; j < I; ++j)
346 if (conn[i][j])
sn.rtnodes(i * K + s, j * K + s) = share;
349 sn.da_recompute_visits_from_rtnodes();
351 lastres = netfun(
sn);
355 for (std::size_t c = 0; c <
sn.nchains; ++c)
356 for (std::size_t a = 0; a < I; ++a)
357 for (std::size_t r = 0; r < K; ++r) nv(a, r) = T(nv(a, r) +
sn.nodevisits[c](a, r));
360 for (std::size_t ci = 0; ci < ncaches; ++ci) {
361 const std::size_t ind = caches[ci];
363 for (std::size_t r = 0; r < ch.
hitclass.size(); ++r) {
366 std::size_t c =
sn.nchains;
367 for (std::size_t cc = 0; cc <
sn.nchains; ++cc)
368 if (
sn.chains[cc][r]) { c = cc;
break; }
369 if (c ==
sn.nchains)
continue;
371 for (std::size_t k :
sn.inchain[c]) xsum = T(xsum + lastres.
X[k - 1]);
372 const std::size_t rstat =
sn.classes[r].refstat;
373 const std::size_t refnode =
sn.station_to_node[rstat - 1] - 1;
374 const std::size_t refcls =
375 (
sn.refclass[c] > 0) ?
sn.refclass[c] - 1 : r;
376 const T denom = nv(refnode, refcls);
377 if (denom > zero) lambda[r] = T(xsum * nv(ind, r) / denom);
380 return std::make_pair(lambda, x);
Cache miss rates from the fixed-point multipliers.
Exact mean value analysis of a multi-list cache.
Exact per-item hit and miss probabilities of a multi-list cache.
TTL (characteristic-time) approximation of an h-LRU / LRU(m) cache.
TTL (characteristic-time) approximation of an LRU cache whose lists form an arbitrary access graph.
UnsupportedError(const std::string &what)
A network plus its refreshed NetworkStruct.
Isolated-cache input construction for the decomposition methods.
Damped fixed-point iteration, the shared driver of the decomposition algorithms.
The exception types the port throws.
Dense matrix and non-owning view.
The option and result types every MVA analyzer shares.
CacheMvaResult< T > cache_mva(const Matrix< T > &gamma, const std::vector< int > &m)
Exact mean value analysis of a multi-list cache.
CacheMissResult< T > cache_miss_fpi(const Matrix< T > &gamma, const std::vector< int > &m, const Matrix< T > &lambda)
Cache miss rates from the fixed-point multipliers.
Matrix< T > cache_prob_erec(const Matrix< T > &gamma, const std::vector< int > &m, const std::vector< int > &sigma, const std::vector< int > &k)
Per-item hit and miss probabilities under per-list storage cost caps, pi_ij = m_j gamma(i,...
Matrix< T > cache_ttl_hlru(const Matrix< T > &lambda, const std::vector< int > &m)
TTL (characteristic-time) approximation of an h-LRU / LRU(m) cache.
Matrix< T > cache_ttl_lrua(const Matrix< T > &lambda, const std::vector< Matrix< T > > &R, const std::vector< T > &m, const T &tol, unsigned maxswp=200)
TTL (characteristic-time) approximation of an LRU cache whose lists form an arbitrary access graph.
std::vector< Matrix< T > > da_cacheqn_itemprob(const CacheqnInfo< T > &info)
Per-item occupancy of every cache from the CONVERGED access factors.
CacheqnResult< T > da_cacheqn(qn::NetworkStruct< T > sn, bool exact, const mva::MvaOptions &opt, const std::function< mva::MvaSolution< T >(const qn::NetworkStruct< T > &)> &netfun, const std::function< std::vector< T >(const Matrix< T > &, const std::vector< int > &, const std::vector< Matrix< T > > &, const qn::CacheParam< T > &, const std::vector< int > &)> &missfun=nullptr)
Decomposition-aggregation driver for integrated cache-queueing models, a port of matlab/src/api/da/da...
FpiResult< T > da_fpi(const std::function< std::pair< std::vector< T >, std::vector< T > >(const std::vector< T > &, std::size_t)> &iterfun, const std::vector< T > &x0, const FpiOptions &options=FpiOptions())
Damped fixed-point iteration, the shared driver of the decomposition algorithms.
CacheIsolateResult< T > da_cache_isolate(const CacheParam< T > &ch, const std::vector< T > &lambda)
Isolated-cache input construction for the decomposition methods.
@ HLRU
h-LRU / LRU(m): h lists, promote i -> i+1 on a hit
@ FIFO
first in, first out
Conservation laws of a layered queueing network, enumerated from its structure.
A queueing network and its refreshed NetworkStruct.
The <kind> part of a LINE:<category>:<kind> identifier (see _kb/17-error-vocabulary....
Return value of cache_miss, mirroring [M,MU,MI,pi0].
std::vector< T > MU
(u) per-user miss rate; empty when no lambda given
Return value of cache_mva, mirroring [pi,pi0,pij,x,u,E].
Return value of da_cache_isolate, mirroring [gamma,lambda_cache,Rcost].
std::vector< Matrix< T > > lambda_cache
(u) matrices of size n x (h+1)
Matrix< T > gamma
(n x h) access factors
std::vector< int > parent
list tree of cache_gamma_lp, as its parent
std::vector< std::vector< Matrix< T > > > Rcost
(u x n) of (h+1)x(h+1)
The fields of sn.nodeparam{cache} that da_cache_isolate reads.
std::vector< int > itemcap
(h) list capacities
std::vector< std::vector< Matrix< T > > > accost
(u) x (n) of (h+1)x(h+1), or empty
std::vector< std::vector< T > > pread
(u) x (n), empty row = NaN
The converged isolated-cache inputs, kept for per-item occupancy reporting.
std::vector< std::vector< int > > itemsize
per cache, EMPTY without item sizes
std::vector< std::vector< int > > costcap
per cache, EMPTY without cost caps
std::vector< lang::ReplacementStrategy > strat
std::vector< std::vector< std::vector< Matrix< T > > > > Rcost
std::vector< Matrix< T > > gamma
per cache: (n x h)
std::vector< std::vector< int > > itemcap
per cache
std::vector< std::vector< Matrix< T > > > lambda_cache
per cache: (u) of n x (h+1)
Matrix< T > missprob
(ncaches x nclasses)
Matrix< T > hitprob
(ncaches x nclasses)
mva::MvaSolution< T > res
Options mirroring the fields MATLAB reads off the options struct.
static constexpr double FineTol
The options SolverMVA reads.
Class-level results, the [Q,U,R,T,C,X] of the MATLAB analyzers.
The parameters of a Cache node, MATLAB's sn.nodeparam{ind} for a Cache.
std::vector< int > itemsize
Per-item storage cost (size) and per-list cap on the total cost of the resident items (ton21cache Sec...
std::vector< int > costcap
std::vector< std::vector< Matrix< T > > > accost
(u) x (n) of (h+1)x(h+1), or empty
std::vector< int > itemcap
std::vector< std::size_t > missclass
std::vector< std::size_t > hitclass
lang::ReplacementStrategy replacestrat
std::vector< std::vector< T > > pread
(u) x (n), empty row = NaN