LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
solver_nc_cache_analyzer.m
1function [QN,UN,RN,TN,CN,XN,lG,pij,runtime,method] = solver_nc_cache_analyzer(sn, options)
2% [Q,U,R,T,C,X,LG,PIJ,RUNTIME] = SOLVER_NC_CACHE_ANALYZER(QN, OPTIONS)
3
4% Copyright (c) 2012-2026, Imperial College London
5% All rights reserved.
6
7T0=tic;
8QN = []; UN = [];
9RN = []; TN = [];
10CN = [];
11XN = zeros(1,sn.nclasses);
12lG = NaN;
13iter = NaN;
14
15line_debug('NC cache analyzer starting: method=%s, nclasses=%d', options.method, sn.nclasses);
16
17source_ist = sn.nodeToStation(sn.nodetype == NodeType.Source);
18sourceRate = sn.rates(source_ist,:);
19sourceRate(isnan(sourceRate)) = 0;
20TN(source_ist,:) = sourceRate;
21
22ch = sn.nodeparam{sn.nodetype == NodeType.Cache};
23
24m = ch.itemcap;
25n = ch.nitems;
26
27if n<m+2
28 line_error(mfilename,'NC requires the number of items to exceed the cache capacity at least by 2.');
29end
30
31h = length(m);
32u = sn.nclasses;
33lambda = zeros(u,n,h);
34
35for v=1:u
36 for k=1:n
37 for l=1:(h+1)
38 if ~isnan(ch.pread{v})
39 lambda(v,k,l) = sourceRate(v) * ch.pread{v}(k);
40 end
41 end
42 end
43end
44
45R = ch.accost;
46gamma = cache_gamma_lp(lambda,R);
47switch options.method
48 case 'exact'
49 line_debug('Using exact method, calling cache_prob_erec');
50 [pij] = cache_prob_erec(gamma, m);
51 missRate = zeros(1,u);
52 for v=1:u
53 missRate(v) = lambda(v,:,1)*pij(:,1);
54 end
55 method='exact';
56 case 'sampling'
57 line_debug('Using sampling method, calling cache_miss_is');
58 [~,missRate,~,~,lE] = cache_miss_is(gamma, m, lambda, options.samples);
59 pij = cache_prob_is(gamma, m, options.samples);
60 method='sampling';
61 otherwise
62 line_debug('Default method: using SPM approximation method\n');
63 line_debug('Using SPM approximation method, calling cache_miss_spm');
64 [~,missRate,~,~,lE] = cache_miss_spm(gamma, m, lambda);
65 pij = cache_prob_spm(gamma, m, lE);
66 method='spm';
67end
68
69for r = 1:sn.nclasses
70 if length(ch.hitclass)>=r && ch.missclass(r)>0 && ch.hitclass(r)>0
71 XN(ch.missclass(r)) = XN(ch.missclass(r)) + missRate(r);
72 XN(ch.hitclass(r)) = XN(ch.hitclass(r)) + (sourceRate(r) - missRate(r));
73 end
74end
75runtime=toc(T0);
76end