LINE Solver (C++)
Templated C++ port of the LINE queueing solver
Loading...
Searching...
No Matches
solver_mva_cacheqn.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012-2026, QORE Lab, Imperial College London
3 * All rights reserved.
4 */
5#ifndef LINE_SOLVERS_MVA_SOLVER_MVA_CACHEQN_H
6#define LINE_SOLVERS_MVA_SOLVER_MVA_CACHEQN_H
7
8/**
9 * @file
10 * @ingroup line_solvers
11 * Integrated caching-queueing analyzer, a port of
12 * matlab/src/solvers/MVA/solver_mva_cacheqn_analyzer.m.
13 *
14 * Delegates to the decomposition-aggregation driver `da_cacheqn`, supplying the
15 * isolated-cache miss algorithm (exact `cache_mva` or the FPI approximation) and
16 * a network solver. The surrounding queueing network is solved by
17 * `solver_mva_analyzer` (or the load-dependent analyzer when the model carries
18 * scaling), matching the reference's `netsolve`.
19 *
20 * ARITHMETIC: transcendental. The fixed-point driver stops on a tolerance and
21 * the FPI miss path evaluates the cache access factors, so this refuses under
22 * Rational by name.
23 */
24
25#include <limits>
26#include <vector>
27
33
34namespace line {
35namespace mva {
36
37/**
38 * The cache half of the reference's return list: the (ncaches x nclasses) hit
39 * and miss split, plus the per-item occupancy the reference writes straight onto
40 * each Cache node with `setResultItemProb`.
41 */
42template <class T>
44 Matrix<T> hitprob; ///< (ncaches x nclasses)
45 Matrix<T> missprob; ///< (ncaches x nclasses)
46 std::vector<Matrix<T> > itemprob; ///< per cache, (n x h+1); EMPTY = not computed
47};
48
49template <class T>
51 qn::NetworkStruct<T>* refreshed_out = nullptr,
52 MvaCacheqnCacheOutputs<T>* cache_out = nullptr) {
53 if constexpr (!num_traits<T>::has_transcendental) {
54 throw UnsupportedError(
55 "solver_mva_cacheqn_analyzer: the integrated caching-queueing decomposition needs "
56 "transcendental arithmetic; rerun with --arith double or --arith real");
57 } else {
58 const MvaOptions netopt = opt;
59 std::function<MvaSolution<T>(const qn::NetworkStruct<T>&)> netfun =
60 [netopt](const qn::NetworkStruct<T>& snit) -> MvaSolution<T> {
61 bool has_scaling = false;
62 for (const auto& st : snit.stations)
63 if (!st.lldscaling.empty() || st.cdscaling) has_scaling = true;
64 MvaOptions o = netopt;
65 if (has_scaling) return solver_mvald_analyzer(snit, o, Matrix<T>()).sol;
66 return solver_mva_analyzer(snit, o, Matrix<T>());
67 };
68 const bool exact = (opt.method == "exact");
69 const da::CacheqnResult<T> r = da::da_cacheqn<T>(L, exact, opt, netfun);
70 // Hand the runner a struct whose cache self-switch carries the ACTUAL
71 // (converged) hit/miss split rather than the offered 1/2-1/2, so ArvR and
72 // ResidT match MATLAB's setResultHitProb -> getStruct round trip. Unlike
73 // da_cacheqn's over-routed inner struct, the self-switch is normalized
74 // (no pass-through inflation), so it is correct whether the cache fans out
75 // to one downstream node (cache_replc_routing) or several (gallery).
76 if (refreshed_out) {
77 *refreshed_out = L;
79 }
80 if (cache_out) {
81 cache_out->hitprob = r.hitprob;
82 cache_out->missprob = r.missprob;
83 // Per-item occupancy from the CONVERGED access factors; SolverNC reads
84 // the same law off its own fixed point.
85 cache_out->itemprob = da::da_cacheqn_itemprob(r.info);
86 }
87 return r.res;
88 }
89}
90
91} // namespace mva
92} // namespace line
93
94#endif // LINE_SOLVERS_MVA_SOLVER_MVA_CACHEQN_H
Exact per-item hit and miss probabilities of a multi-list cache.
TTL (characteristic-time) approximation of an LRU cache whose lists form an arbitrary access graph.
UnsupportedError(const std::string &what)
Definition error.h:51
A network plus its refreshed NetworkStruct.
void refresh_cacheqn_actual_visits(const Matrix< T > &hitprob, const Matrix< T > &missprob)
Re-resolve the cache read self-switch from the offered 1/2-1/2 to the ACTUAL hit/miss probabilities t...
Decomposition-aggregation driver for integrated cache-queueing models, a port of matlab/src/api/da/da...
The option and result types every MVA analyzer shares.
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 > &)> &missfun=nullptr)
Decomposition-aggregation driver for integrated cache-queueing models, a port of matlab/src/api/da/da...
Definition da_cacheqn.h:133
std::vector< Matrix< T > > da_cacheqn_itemprob(const CacheqnInfo< T > &info)
Per-item occupancy of every cache from the CONVERGED access factors.
Definition da_cacheqn.h:82
MvaSolution< T > solver_mva_cacheqn_analyzer(const qn::NetworkStruct< T > &L, const MvaOptions &opt, qn::NetworkStruct< T > *refreshed_out=nullptr, MvaCacheqnCacheOutputs< T > *cache_out=nullptr)
DispatchResult< T > solver_mvald_analyzer(const qn::NetworkStruct< T > &L, const MvaOptions &opt, const Matrix< T > &init_sol)
Port of solver_mvald_analyzer.m: the load-dependent branch.
MvaSolution< T > solver_mva_analyzer(const qn::NetworkStruct< T > &L, const MvaOptions &opt, const Matrix< T > &init_sol)
Port of solver_mva_analyzer.m, default and the explicit method names.
SolverMVA over a SolverLN layer.
Matrix< T > missprob
(ncaches x nclasses)
Definition da_cacheqn.h:61
Matrix< T > hitprob
(ncaches x nclasses)
Definition da_cacheqn.h:60
CacheqnInfo< T > info
Definition da_cacheqn.h:63
mva::MvaSolution< T > res
Definition da_cacheqn.h:59
The cache half of the reference's return list: the (ncaches x nclasses) hit and miss split,...
Matrix< T > missprob
(ncaches x nclasses)
Matrix< T > hitprob
(ncaches x nclasses)
std::vector< Matrix< T > > itemprob
per cache, (n x h+1); EMPTY = not computed
The options SolverMVA reads.
Definition mva_types.h:31
Class-level results, the [Q,U,R,T,C,X] of the MATLAB analyzers.
Definition mva_types.h:96