[902] | 1 | #!/usr/bin/env python |
---|
[894] | 2 | |
---|
| 3 | import onerun |
---|
| 4 | import os |
---|
| 5 | import random |
---|
| 6 | from math import ceil |
---|
| 7 | from sys import exit |
---|
| 8 | |
---|
| 9 | class RunArguments: |
---|
| 10 | def __init__(self, name, x, y): |
---|
| 11 | self.path = os.getcwd() |
---|
| 12 | self.outpath = name |
---|
| 13 | self.x = x |
---|
| 14 | self.y = y |
---|
| 15 | self.nprocs = 4 |
---|
| 16 | self.compileonly = False |
---|
| 17 | self.batchmode = True |
---|
| 18 | self.faultyrouter = [] |
---|
| 19 | self.faultymask = 0xF |
---|
| 20 | self.faultycore = [] |
---|
| 21 | self.debug = None |
---|
| 22 | |
---|
| 23 | self.xmax = self.x - 1 |
---|
| 24 | self.ymax = self.y - 1 |
---|
| 25 | self.pmax = self.nprocs - 1 |
---|
| 26 | |
---|
| 27 | # init random number generator |
---|
| 28 | random.seed() |
---|
| 29 | |
---|
| 30 | def add_faultyrouter(self, x): |
---|
| 31 | if x in self.faultyrouter: |
---|
| 32 | return False |
---|
| 33 | |
---|
| 34 | self.faultyrouter.append(x) |
---|
| 35 | return True |
---|
| 36 | |
---|
| 37 | def add_faultycore(self, x): |
---|
| 38 | if x in self.faultycore: |
---|
| 39 | return False |
---|
| 40 | |
---|
| 41 | self.faultycore.append(x) |
---|
| 42 | return True |
---|
| 43 | |
---|
| 44 | def init_faultyrouter(self, x): |
---|
| 45 | if x == None: return |
---|
| 46 | self.faultyrouter = x |
---|
| 47 | |
---|
| 48 | def init_faultycore(self, x): |
---|
| 49 | if x == None: return |
---|
| 50 | self.faultycore = x |
---|
| 51 | |
---|
| 52 | def get_faultycount(self, total, pct): |
---|
| 53 | """ |
---|
| 54 | Returns the number of faulty elements in a population |
---|
| 55 | Arguments: |
---|
| 56 | total -- Total number of elements |
---|
| 57 | pct -- Percentage of faulty elements |
---|
| 58 | """ |
---|
| 59 | return int(ceil(total * float(pct)/100)) |
---|
| 60 | |
---|
| 61 | def get_faultycorecount(self, pct): |
---|
| 62 | """ |
---|
| 63 | Returns the number of faulty cores in the platform |
---|
| 64 | Arguments: |
---|
| 65 | pct -- Percentage of faulty cores |
---|
| 66 | """ |
---|
| 67 | return self.get_faultycount(self.get_totalcores(), pct) |
---|
| 68 | |
---|
| 69 | def get_faultyroutercount(self, pct): |
---|
| 70 | """ |
---|
| 71 | Returns the number of faulty routers in the platform |
---|
| 72 | Arguments: |
---|
| 73 | pct -- Percentage of faulty routers |
---|
| 74 | """ |
---|
| 75 | return self.get_faultycount(self.get_totalclusters(), pct) |
---|
| 76 | |
---|
| 77 | def get_totalclusters(self): |
---|
| 78 | return self.x * self.y |
---|
| 79 | |
---|
| 80 | def get_totalcores(self): |
---|
| 81 | return self.get_totalclusters() * self.nprocs |
---|
| 82 | |
---|
[902] | 83 | # activate the different kinds of simulation |
---|
| 84 | SIM_FAULTFREE = False |
---|
| 85 | SIM_FAULTCORES = False |
---|
[904] | 86 | SIM_FAULTROUTERS = True |
---|
| 87 | SIM_FAULTMIXED = False |
---|
[894] | 88 | |
---|
[902] | 89 | # probability of faulty router (for mixed simul) |
---|
| 90 | SIM_FAULTMIXED_PROBROUTER = 0.05 # 5% |
---|
| 91 | |
---|
[904] | 92 | # NoC index for faulty routers |
---|
| 93 | CMD = 0 |
---|
| 94 | RSP = 1 |
---|
| 95 | |
---|
[902] | 96 | for xsize, ysize in [(4, 4), (4, 8), (8, 8), (8, 16), (16, 16)]: |
---|
| 97 | if SIM_FAULTFREE: |
---|
| 98 | # --------------------------------------------------------------------- |
---|
| 99 | # simulation without faults |
---|
| 100 | # --------------------------------------------------------------------- |
---|
| 101 | cfgname = 'output_{0}_{1}'.format(xsize, ysize) |
---|
[894] | 102 | args = RunArguments(cfgname, xsize, ysize) |
---|
[902] | 103 | onerun.run(args) |
---|
[894] | 104 | |
---|
[902] | 105 | for pct in xrange(5, 60, 5): # 5, 10, ..., 55 |
---|
| 106 | if SIM_FAULTCORES: |
---|
| 107 | # ----------------------------------------------------------------- |
---|
| 108 | # simulation with random faulty cores |
---|
| 109 | # ----------------------------------------------------------------- |
---|
| 110 | cfgname = 'output_core_{0}_{1}_{2}'.format(xsize, ysize, pct) |
---|
| 111 | args = RunArguments(cfgname, xsize, ysize) |
---|
[894] | 112 | |
---|
[902] | 113 | faultycount = args.get_faultycorecount(pct) |
---|
| 114 | print "{0}/{1} faulty cores\n".\ |
---|
| 115 | format(faultycount, args.get_totalcores()) |
---|
[894] | 116 | |
---|
[902] | 117 | n = 0 |
---|
| 118 | while n < faultycount: |
---|
| 119 | cx = random.randint(0, args.xmax) |
---|
| 120 | cy = random.randint(0, args.ymax) |
---|
| 121 | cl = random.randint(0, args.pmax) |
---|
| 122 | if args.add_faultycore((cx, cy, cl)): n += 1 |
---|
[894] | 123 | |
---|
[902] | 124 | onerun.run(args) |
---|
[894] | 125 | |
---|
[902] | 126 | if SIM_FAULTROUTERS: |
---|
| 127 | # ----------------------------------------------------------------- |
---|
| 128 | # simulation with random faulty routers |
---|
| 129 | # ----------------------------------------------------------------- |
---|
| 130 | cfgname = 'output_router_{0}_{1}_{2}'.format(xsize, ysize, pct) |
---|
| 131 | args = RunArguments(cfgname, xsize, ysize) |
---|
[894] | 132 | |
---|
[902] | 133 | faultycount = args.get_faultyroutercount(pct) |
---|
| 134 | print "{0}/{1} faulty routers\n".\ |
---|
| 135 | format(faultycount, args.get_totalclusters()) |
---|
[894] | 136 | |
---|
[902] | 137 | n = 0 |
---|
| 138 | while n < faultycount: |
---|
| 139 | cx = random.randint(0, args.xmax) |
---|
| 140 | cy = random.randint(0, args.ymax) |
---|
[904] | 141 | if args.add_faultyrouter((CMD, cx, cy)): n += 1 |
---|
[894] | 142 | |
---|
[902] | 143 | onerun.run(args) |
---|
[894] | 144 | |
---|
[902] | 145 | if SIM_FAULTMIXED: |
---|
| 146 | # ----------------------------------------------------------------- |
---|
| 147 | # simulation with random faulty routers and cores |
---|
| 148 | # ----------------------------------------------------------------- |
---|
| 149 | cfgname = 'output_mixed_{0}_{1}_{2}'.format(xsize, ysize, pct) |
---|
| 150 | args = RunArguments(cfgname, xsize, ysize) |
---|
[894] | 151 | |
---|
[902] | 152 | total = args.get_totalclusters() + args.get_totalcores() |
---|
| 153 | faultycount = args.get_faultycount(total, pct) |
---|
[894] | 154 | |
---|
[902] | 155 | print "\nprobability of faulty routers: {0}".\ |
---|
| 156 | format(SIM_FAULTMIXED_PROBROUTER) |
---|
| 157 | fr = 0 |
---|
| 158 | fc = 0 |
---|
| 159 | while (fr + fc) < faultycount: |
---|
| 160 | cx = random.randint(0, args.xmax) |
---|
| 161 | cy = random.randint(0, args.ymax) |
---|
| 162 | if (random.random() < SIM_FAULTMIXED_PROBROUTER): |
---|
| 163 | # add faulty router |
---|
| 164 | fr += 1 |
---|
[904] | 165 | while not args.add_faultyrouter((CMD, cx, cy)): |
---|
[902] | 166 | cx = random.randint(0, args.xmax) |
---|
| 167 | cy = random.randint(0, args.ymax) |
---|
[894] | 168 | |
---|
[902] | 169 | else: |
---|
| 170 | # add faulty core |
---|
| 171 | fc += 1 |
---|
| 172 | cl = random.randint(0, args.pmax) |
---|
| 173 | while not args.add_faultycore((cx, cy, cl)): |
---|
| 174 | cx = random.randint(0, args.xmax) |
---|
| 175 | cy = random.randint(0, args.ymax) |
---|
| 176 | cl = random.randint(0, args.pmax) |
---|
[894] | 177 | |
---|
[902] | 178 | print "faulty routers / faulty cores = {0} / {1}".format(fr, fc) |
---|
| 179 | onerun.run(args) |
---|
[894] | 180 | |
---|
[902] | 181 | # vim: ts=4 : sts=4 : sw=4 : et |
---|