def runs_l3(self, nr_pipelets=12, nr_ways=12, other_nf_types=['mlc', 'real', 'syn'], utilizations=[100], isolated=False, best=None, is_done=None): assert (all(mix in set(['mlc', 'real', 'syn']) for mix in other_nf_types)) cbms = [ways_to_cbm(nr_ways)] * nr_pipelets if isolated: cbms = [config.cat['cbm_min']] + \ [ways_to_cbm(nr_ways - config.cat['nr_ways_min'], config.cat['nr_ways_min'])] * (nr_pipelets - 1) l = [] for mix in other_nf_types: for other_nf in NFManager().list(real='real' == mix, mlc='mlc' == mix, syn='syn' == mix): #utilizations = [100] #config.utilizations if mix != 'mlc' else [100] for utilization in utilizations: l += list( Run(pipelets=[self.pipelet] + [other_nf] * (nr_pipelets - 1), cbms=cbms, traffics=[self.traffic] * nr_pipelets, utilizations=[utilization] + [100] * (nr_pipelets - 1)).selector(best=best, is_done=is_done)) return l
def optimal_calloc(self, nr_ways, policy): def neighbors(): # per class min and max for number of ways nr_ways_min = config.cat['nr_ways_min'] nr_ways_max = nr_ways - nr_ways_min * len(self.pipelets) e = self.copy(pipelets=self.pipelets[1:], cbms=self.cbms[1:], traffics=self.traffics[1:], utilizations=self.utilizations[1:]) neighbors = [] for nr_ways_first in range(nr_ways_min, nr_ways_max + 1): e_opt = e.optimal_calloc(nr_ways - nr_ways_first, policy) cbms = [ways_to_cbm(nr_ways_first)] nr_ways_used = nr_ways_first for cbm in e_opt.cbms: nr_ways_this = cbm_to_ways(cbm) cbms.append( ways_to_cbm(nr_ways_this, nr_ways_used=nr_ways_used)) nr_ways_used += nr_ways_this neighbors.append(self.copy(cbms=tuple(cbms))) return neighbors # this is the max pps for incomplete cbms # note that this is definitely an overestimate def heuristic(nr_ways, policy): return objective_func(policy, self.pps_solos_full_cbm) def objective_func(policy, l): def eval_func(e): v = 100 - e.pps_predict_cat_normalized_full_cbm if policy == 'minmax': return max(v) elif policy == 'minsum': return sum(v) return min(l, key=eval_func) if policy == 'equal': assert (nr_ways % self.nr_pipelets == 0) cbms = [] nr_ways_used = 0 for i in range(self.nr_pipelets): nr_ways_this = int(nr_ways / self.nr_pipelets) cbms.append( ways_to_cbm(nr_ways_this, nr_ways_used=nr_ways_used)) nr_ways_used += nr_ways_this return self.copy(cbms=tuple(cbms)) # base case if self.nr_pipelets == 1: return self.copy(cbms=(ways_to_cbm(nr_ways), )) return objective_func(policy, neighbors())
def rtt_to_utilization(self, rtt): u_list = [] all_cbms = \ filter(lambda e: e.is_done, [self.copy(cbms=tuple([ways_to_cbm(nr_ways)] + list(self.cbms[1:]))) for nr_ways in [config.cat['nr_ways_min'], config.cat['nr_ways_max']]]) for e in all_cbms: e_u = e.all_utils if len(e_u) <= 1: continue rtt_l = np.array([e.rtt_95[0] for e in e_u]) e_u_select = e_u[rtt_l < rtt] if len(e_u_select) == 0: print(rtt_l) return None import heapq u = min(heapq.nlargest(1, [e.utilizations[0] for e in e_u_select])) #if u == 98: # u = 95 #if e.pipelets[0] == 'mon': # u = 90 u_list.append(u) if len(u_list) == 0: return None return min(u_list)
def all_cbms(self): f = filter(lambda e: e.is_done, [ self.copy(cbms=tuple([ways_to_cbm(nr_ways)] + list(self.cbms[1:]))) for nr_ways in range(config.cat['nr_ways_min'], config.cat['nr_ways_max'] + 1) ]) return np.array(list(f))
def solos_same_cbm(self): l = [] for pipelet, nr_ways, traffic_spec, utilization in \ zip(self.pipelets, self.l3_ways, self.traffics, self.utilizations): e = Run(pipelets=(pipelet, ), cbms=(ways_to_cbm(nr_ways), ), run_number=self.run_number, traffics=(traffic_spec, ), utilizations=(utilization, )) l.append(e) return np.array(l)
def neighbors(): # per class min and max for number of ways nr_ways_min = config.cat['nr_ways_min'] nr_ways_max = nr_ways - nr_ways_min * len(self.pipelets) e = self.copy(pipelets=self.pipelets[1:], cbms=self.cbms[1:], traffics=self.traffics[1:], utilizations=self.utilizations[1:]) neighbors = [] for nr_ways_first in range(nr_ways_min, nr_ways_max + 1): e_opt = e.optimal_calloc(nr_ways - nr_ways_first, policy) cbms = [ways_to_cbm(nr_ways_first)] nr_ways_used = nr_ways_first for cbm in e_opt.cbms: nr_ways_this = cbm_to_ways(cbm) cbms.append( ways_to_cbm(nr_ways_this, nr_ways_used=nr_ways_used)) nr_ways_used += nr_ways_this neighbors.append(self.copy(cbms=tuple(cbms))) return neighbors
def runs_chain(self): nr_ways_min = config.cat['nr_ways_min'] nr_ways_max = config.cat['nr_ways_max'] chain_length_max = nr_ways_max / nr_ways_min cbms = [ ways_to_cbm(nr_ways_min, nr_ways_min * i) for i in range(chain_length_max) ] l = [ Run(pipelets=[[self.pipelet] * chain_length], cbms=[cbms[0:chain_length]], traffics=[self.traffic], utilizations=[100], run_number=run_number) for run_number in config.run_numbers for traffic in config.traffics.keys() for chain_length in range(2, chain_length_max + 1, 2) ] return l
def _runs(self, cbms=None, utilizations=None, best=None, is_done=None): if not cbms: nr_ways_min = config.cat['nr_ways_min'] nr_ways_max = config.cat['nr_ways_max'] cbms = [ ways_to_cbm(n) for n in range(nr_ways_min, nr_ways_max + 1) ] if not utilizations: utilizations = config.utilizations l = [] for utilization in utilizations: for cbm in cbms: l += list( Run(pipelets=[self.pipelet], cbms=[cbm], traffics=[self.traffic], utilizations=[utilization]).selector(best=best, is_done=is_done)) return l