Commit 38ce8128 authored by PATUREL Joseph's avatar PATUREL Joseph

Added missing files and miscellaneous tools

parent 02ac94a0
......@@ -142,7 +142,7 @@ void pluslongdespluscourts(Graphe* graphe)
Sommet* sommets = malloc(graphe->nSommets*sizeof(Sommet));
for(i = 0; i < graphe->nSommets; ++i)
{
printf("%d\n", i+1);
//printf("%d\n", i+1);
for(j = 0; j < graphe->nSommets; ++j)
{
if(i == j)
......@@ -174,13 +174,13 @@ void pluslongdespluscourts(Graphe* graphe)
}
}
}
printf("Plus long chemin entre 2 sommets de %s a %s : %d en %d sauts\n",
sommets[k+1].nom, sommets[0].nom, sommets[0].poids, k+1);
for(; k >= 0; --k)
{
printf("De %s a %s : %d\n", sommets[k+1].nom, sommets[k].nom,
sommets[k].poids-sommets[k+1].poids);
}
//printf("Plus long chemin entre 2 sommets de %s a %s : %d en %d sauts\n",
// sommets[k+1].nom, sommets[0].nom, sommets[0].poids, k+1);
//for(; k >= 0; --k)
//{
//printf("De %s a %s : %d\n", sommets[k+1].nom, sommets[k].nom,
// sommets[k].poids-sommets[k+1].poids);
//}
free(sommets);
}
......
......@@ -5,7 +5,7 @@ CFLAGS=-Wno-overflow
BUILDDIR=build
RESDIR=res
TYPES = schar uchar short ushort int uint int64 uint64 float
size = 10 100 # 300 takes around 6 hours...
size = 10 60 100 # 300 takes around 6 hours...
all: dijkstra.riscv$(XLEN)
......
XLEN?=32
CC=riscv$(XLEN)-unknown-elf-gcc
PATHTOCC=~/Thesis/toolchains/rv32im/bin
CC=$(PATHTOCC)/riscv$(XLEN)-unknown-elf-gcc
CCDUMP=riscv$(XLEN)-unknown-elf-objdump
CFLAGS=-Wno-overflow
BUILDDIR=build
RESDIR=res
TYPES = schar uchar short ushort int uint int64 uint64 float
size = 4 8 16 32
size = 4 8 16 32
all: matmul.riscv$(XLEN)
matmul.riscv$(XLEN): matmul.c matmul.h
all: dupmatmul.riscv$(XLEN)
dupmatmul.riscv$(XLEN): dupmatmul.c matmul.h
mkdir -p $(BUILDDIR) $(RESDIR)
$(foreach size, $(size), $(foreach type, $(TYPES), $(CC) matmul.c $(CFLAGS) -o $(BUILDDIR)/matmul_$(type)_$(size).riscv$(XLEN) -DSIZE=$(size) -DTYPE=$(type);))
$(foreach size, $(size), $(foreach type, $(TYPES), gcc matmul.c $(CFLAGS) -o $(BUILDDIR)/matmul_$(type)_$(size).x86 -DSIZE=$(size) -DTYPE=$(type);))
$(CC) matmul.c -o $(BUILDDIR)/matmul.riscv$(XLEN) -D__HLS__ -Wl,-Ttext,4
$(CC) matmul.c -o matmul.riscv$(XLEN) -D__HLS__ -Wl,-Ttext,4
$(foreach size, $(size), $(foreach type, $(TYPES), $(CC) dupmatmul.c $(CFLAGS) -o $(BUILDDIR)/matmul_$(type)_$(size).riscv$(XLEN) -DSIZE=$(size) -DTYPE=$(type);))
$(foreach size, $(size), $(foreach type, $(TYPES), gcc dupmatmul.c $(CFLAGS) -o $(BUILDDIR)/matmul_$(type)_$(size).x86 -DSIZE=$(size) -DTYPE=$(type);))
$(CC) dupmatmul.c -o $(BUILDDIR)/matmul.riscv$(XLEN) -D__HLS__ -Wl,-Ttext,4
$(CC) dupmatmul.c -S -o matmul.riscv$(XLEN).s -D__HLS__ -Wl,-Ttext,4
$(foreach size, $(size), $(foreach type, $(TYPES), $(BUILDDIR)/matmul_$(type)_$(size).x86 > $(RESDIR)/matmul_$(type)_$(size);))
$(foreach size, $(size), $(foreach type, $(TYPES), $(CCDUMP) -D $(BUILDDIR)/matmul_$(type)_$(size).riscv$(XLEN) > $(BUILDDIR)/matmul_$(type)_$(size).dump;))
......@@ -22,5 +23,3 @@ clean:
rm -rf $(BUILDDIR) $(RESDIR) *.riscv32 *.riscv64 *.x86
.PHONY: all clean
......@@ -43,7 +43,7 @@ int main()
#ifndef __HLS__
#define STR1(X) #X
#define STR(X) STR1(X)
for(i = 0; i < SIZE; ++i)
/* for(i = 0; i < SIZE; ++i)
{
if(strcmp(STR(TYPE), "float") == 0)
printf("%f\n", A[i]);
......@@ -51,6 +51,6 @@ int main()
printf("%lld\n", A[i]);
else
printf("%d\n", A[i]);
}
} */
#endif
}
......@@ -55,10 +55,12 @@ registerInfo = {
coreAreas_names = ['sequential', 'comb_pipeline', 'comb_other'] #comb_other -> coreCtrl, cache control
#coreAreas_probas = [0.338581382365307417, 0.49667440581689906891, 0.16474421181779351409]
coreAreas_probas = [0.302387984, 0.647612016, 0.05]
coreAreas_probas = [0.458482514622009, 0.496674405816899, 0.044843079561092]
pipelineAreas_names = ['FToDC', 'DCToEX', 'EXToMEM', 'MEMToWB', 'WriteBack']
pipelineAreas_probas = [0.065232138, 0.145714051, 0.690445829, 0.049792418, 0.048815564]
pipelineAreas_probas = [0.035113474644918, 0.064444610787967, 0.207362746102595, 0.029803011039869, 0.247958952877368]
#pipelineAreas_probas = [0.065232138, 0.145714051, 0.690445829, 0.049792418, 0.048815564]
def getRegisterList():
......@@ -162,12 +164,28 @@ def getPattern(registerName, errorBase):
def selectRegion():
region = np.random.choice(coreAreas_names, p=coreAreas_probas)
if region == 'comb_pipeline':
region = np.random.choice(pipelineAreas_names, p=pipelineAreas_probas)
#normalize the probas so their sum equates to 1
sumProb = 0
for p in pipelineAreas_probas:
sumProb += p
pipelineAreas_probas_temp = np.true_divide(pipelineAreas_probas, sumProb)
region = np.random.choice(pipelineAreas_names, p=pipelineAreas_probas_temp)
return region
def selectRegister():
return random.choice(list(registerInfo))
def getUniformRandomBit():
bit = random.randrange(0, getTotalWidth()-1)
#find out which bit it is
total = 0
for reg in registerInfo:
if bit < registerInfo[reg]['width']: #bit is in register
return (reg, bit)
else:
total += registerInfo[reg]['width']
bit -= registerInfo[reg]['width']
def selectRFRegister():
return 'RF' + str(random.randint(0,31))
......
......@@ -5,6 +5,7 @@ import matplotlib.pyplot as plt
def buildHistogram_bits(patternList):
#define a list of the different bit counters
pdb.set_trace()
bitCounters = [0]*len(patternList[0][0])
for p, c in zip(patternList[0], patternList[1]): #pattern per pattern
for bitPosition in range(len(p)):
......@@ -34,6 +35,8 @@ def main():
#load the patterns data
patterns = pickle.load(open(args.inputFile, 'rb'))
pdb.set_trace()
#build histgrams per region
for region in patterns.keys():
hist_bits = buildHistogram_bits(patterns[region])
......
......@@ -7,9 +7,9 @@ import numpy as np
import FIRegInfo as ri #register informations and useful functions
nBitPerInj = 3
#nBitPerInj = 5
PartialResult = collections.namedtuple('PartialResult', ['endType', 'cycle', 'runNumber'])
PartialResult = collections.namedtuple('PartialResult', ['endType', 'cycle', 'runNumber', 'execCyclesDiff'])
################################################################################
# Injection support
......@@ -49,6 +49,7 @@ def doInjectionRun(runNumber, benchmarkPath, referenceCycles, patterns, verbosit
#pick a cycle
injectionCycle = random.randint(0, referenceCycles)
#pdb.set_trace()
#select a zone to inject in
place = ri.selectRegion()
......@@ -70,15 +71,57 @@ def doInjectionRun(runNumber, benchmarkPath, referenceCycles, patterns, verbosit
#bitPositions = ri.getrandomBitsinRegister(place, random.randint(1,31))
bitPositions = ri.getrandomBitsinRegister(place, 1)
#only inject 1 bit if a pipeline stage comb logic is hit
else: #selected region is a pipeline stage's combinational logic
bitPositions = ri.patternToBitPositions(ri.getPattern(place, patterns)) #select a pattern to inject
'''
place, bit = ri.getUniformRandomBit()
bitPositions = [bit]
'''
'''
#select a zone to inject in
place = ri.selectRegion()
if place=='sequential': #choose a random FF and flip it
#choose a register
place = ri.selectRegister() #only place where the PC can be hit
#select a random FF inside
bitPositions = ri.getrandomBitsinRegister(place, 1)
elif place == 'comb_other': #inject in one of the core ctrl FFs
place = 'CoreCtrl'
bitPositions = ri.getrandomBitsinRegister(place, 1)
elif place == 'WriteBack': #inject in the register file
#see faultInjection.md for further details on the fault model
#select a random register (can be the one selected in the WB stage)
place = ri.selectRFRegister()
#fill it with a random number of errors
#bitPositions = ri.getrandomBitsinRegister(place, random.randint(1,31))
bitPositions = ri.getrandomBitsinRegister(place, 1)
else: #selected region is a pipeline stage's combinational logic
bitPositions = ri.patternToBitPositions(ri.getPattern(place, patterns)) #select a pattern to inject
'''
'''
else:
bitPositions = ri.getrandomBitsinRegister(place, nBitPerInj)
bitPositions = ri.getrandomBitsinRegister(place, 1)
''' USE THIS IF YOU WANT TO INJECT ERROR PATTERNS
else: #selected region is a pipeline stage's combinational logic
bitPositions = ri.patternToBitPositions(ri.getPattern(place, patterns)) #select a pattern to inject
else:
nBitPerInj = len(ri.getPattern(place, patterns)) #select a pattern to inject, get it's number of erronous bits
bitPositions = ri.getrandomBitsinRegister(place, nBitPerInj)
#only inject 1 bit if a pipeline stage comb logic is hit
else:
bitPositions = ri.getrandomBitsinRegister(place, nBitPerInj)
'''
if verbosity > 0:
print("Injection cycle : " + str(injectionCycle) + ", place : " + place + ", bitPositions : " + ' ' + '"' + ' '.join(map(str, bitPositions)) + '"')
#run the simulator
......@@ -87,6 +130,14 @@ def doInjectionRun(runNumber, benchmarkPath, referenceCycles, patterns, verbosit
runStdOut = executeSimulation(benchmarkPath, ['-o', '/tmp/injectionRunStdout_'+str(runNumber), '-D', '/tmp/injectionRunMemory_'+str(runNumber), '-I', str(maxAllowedCycles), str(injectionCycle), str(placeId), ' '.join(map(str, bitPositions))])
#capture the end type
endType = re.findall('EndType : (.*)', runStdOut)
#capture the number of executed cycles
execCycles = re.findall('Successfully executed .* in (.*) cycles', runStdOut)
# print(execCycles)
if (endType[0] == 'Hang') or (endType[0] == 'Crash'):
cyclesDiff = 'not applicable'
else:
cyclesDiff = int(execCycles[0]) - referenceCycles
#declare the result dict
resDict = {place : dict(dict())}
......@@ -119,7 +170,7 @@ def doInjectionRun(runNumber, benchmarkPath, referenceCycles, patterns, verbosit
print("endType : " + endType[0])
for bit in bitPositions:
nt = PartialResult(endType[0], injectionCycle, runNumber)
nt = PartialResult(endType[0], injectionCycle, runNumber, cyclesDiff)
resDict[place][bit] = nt
if verbosity > 1:
......@@ -143,6 +194,7 @@ def initResults(dic):
dic[key].append({}) #create a dict for each bit in the selected place
dic[key][bit]["cycles"] = []
dic[key][bit]["runNumber"] = []
dic[key][bit]["execCyclesDiff"] = []
dic[key][bit]["nbInj"] = 0 #init the selected bit's stats
dic[key][bit]["Masked"] = 0
dic[key][bit]["ISM"] = 0
......@@ -219,9 +271,11 @@ def saveResults(path, results_bitwise, results_runwise):
pickle.dump(results_runwise, of)
def getNumberOfNeededRuns(workloadCycles, numberOfInjectionPoints):
N = workloadCycles*numberOfInjectionPoints
div = 1+( ((0.01**2)*(N-1)) / (0.25*(3.0902**2)) )
return math.ceil(N/div)
#N = workloadCycles*numberOfInjectionPoints
#div = 1+( ((0.01**2)*(N-1)) / (0.25*(3.0902**2)) )
#return math.ceil(N/div)
# Considering infinite population
return math.ceil((0.25*(3.0902**2))/(0.01**2))
......@@ -265,7 +319,6 @@ def main():
patterns = pickle.load(open(patternsPath, 'rb'))
#normalize the pattern histograms
ri.unifyPatternProbas(patterns)
pool = Pool()
if verbosity > 1:
......@@ -286,10 +339,11 @@ def main():
results_bitwise[place][bit]['nbInj'] += 1
results_bitwise[place][bit]['cycles'].append(res[place][bit].cycle)
results_bitwise[place][bit]['runNumber'].append(res[place][bit].runNumber)
results_bitwise[place][bit]['execCyclesDiff'].append(res[place][bit].execCyclesDiff)
results_bitwise[place][bit][res[place][bit].endType] += 1
if firstBit:
#log per run
results_runwise.append([place, res[place][bit].endType])
results_runwise.append([place, res[place][bit].endType, res[place][bit].execCyclesDiff])
firstBit = False
showFinalStats_runwise(results_runwise)
......
......@@ -2,8 +2,9 @@
import pickle, argparse, pdb
import matplotlib.pyplot as plt
import numpy as np
fs = 20
'''
......@@ -48,10 +49,16 @@ def createHistogram_zones(runs):
zoneCounters = {}
for run in runs:
if run[0] not in zoneCounters:
zoneCounters[run[0]] = 1
else :
zoneCounters[run[0]] += 1
if 'RF' in run[0]:
if 'RF' not in zoneCounters:
zoneCounters['RF'] = 1
else:
zoneCounters['RF'] += 1
else:
if run[0] not in zoneCounters:
zoneCounters[run[0]] = 1
else :
zoneCounters[run[0]] += 1
names = []
counters = []
......@@ -67,8 +74,21 @@ def createHistogram_AVF(runs):
zoneCounters = {}
for run in runs:
if ('RF' in run[0]) and ('RF' not in zoneCounters): #name of the zone, group RF
zoneCounters['RF'] = [0, 0]
if (run[0] not in zoneCounters) and ('RF' not in run[0]) and (run[0] != 'CoreCtrl'): #name of the zone
zoneCounters[run[0]] = [0, 0]
if 'RF'in run[0]:
zoneCounters['RF'][0] += 1 #Add new inj to total
#pdb.set_trace()
if run[1] in ['AOM', 'Crash', 'Hang', 'ISM & AOM']:
zoneCounters['RF'][1] += 1 #Add new ACE fault
if ('RF' not in run[0]) and (run[0] != 'CoreCtrl'):
zoneCounters[run[0]][0] += 1 #Add new inj to total
#pdb.set_trace()
......@@ -79,9 +99,139 @@ def createHistogram_AVF(runs):
for k in zoneCounters:
names.append(k)
avfs.append(zoneCounters[k][1]/numRuns)
#avfs.append(zoneCounters[k][1])
print('Total faults ACE : ' + str(sum(avfs*numRuns)))
return names, avfs
def createHistogram_NuAVF(runs):
numRuns = len(runs)
zoneCounters = {}
for run in runs:
if (run[0] not in zoneCounters) and ('RF' not in run[0]) and (run[0] != 'CoreCtrl'): #name of the zone
zoneCounters[run[0]] = [0, 0]
if ('RF' not in run[0]) and (run[0] != 'CoreCtrl'):
zoneCounters[run[0]][0] += 1 #Add new inj to total
#pdb.set_trace()
if run[1] in ['AOM', 'Crash', 'Hang', 'ISM & AOM']:
zoneCounters[run[0]][1] += 1 #Add new ACE fault
names = []
avfs = []
for k in zoneCounters:
names.append(k)
avfs.append(zoneCounters[k][1]/numRuns)
#avfs.append(zoneCounters[k][1])
print('Total faults ACE : ' + str(sum(avfs*numRuns)))
return names, avfs
def createHistogram_participation(runs):
numRuns = len(runs)
zoneCounters = {}
CCounter = 0
HCounter = 0
ACounter = 0
AllCounter = 0
# a zoneCounters entry is a injectable register, it contains two counters in a list, the first ojne contains the number of times injected, the other one the number of ccritical errors triggered
#runs[0] is an injectable register
for run in runs:
if ('RF' in run[0]) and ('RF' not in zoneCounters): #name of the zone, group RF
zoneCounters['RF'] = [0, 0]
if (run[0] not in zoneCounters) and ('RF' not in run[0]) and (run[0] != 'CoreCtrl'): #name of the zone
zoneCounters[run[0]] = [0, 0]
if 'RF'in run[0]:
zoneCounters['RF'][0] += 1 #Add new inj to total
#pdb.set_trace()
if run[1] in ['AOM', 'Crash', 'Hang', 'ISM & AOM']:
zoneCounters['RF'][1] += 1 #Add new ACE fault
if ('RF' not in run[0]) and (run[0] != 'CoreCtrl'):
zoneCounters[run[0]][0] += 1 #Add new inj to total
#pdb.set_trace()
if run[1] in ['AOM', 'Crash', 'Hang', 'ISM & AOM']:
zoneCounters[run[0]][1] += 1 #Add new ACE fault
if 'extomem' in run[0].lower():
AllCounter += 1
if 'Crash' in run[1]:
CCounter += 1
if 'Hang' in run[1]:
HCounter += 1
if 'AOM' in run[1]:
ACounter += 1
#if run[1] != 'Masked':
#pdb.set_trace()
# pdb.set_trace()()
totalCritErrors=0
for k in zoneCounters:
totalCritErrors += zoneCounters[k][1]
names = []
critPart = []
for k in zoneCounters:
names.append(k)
critPart.append((zoneCounters[k][1]/totalCritErrors)*100)
#avfs.append(zoneCounters[k][1])
return names, critPart
def createHistogram_RFparticipation(runs):
numRuns = len(runs)
zoneCounters = {}
# a zoneCounters entry is a injectable register, it contains two counters in a list, the forst ojne contains the number of times injected, the other one the number of ccritical errors triggered
#runs[0] is an injectable register
for run in runs:
if ('RF' in run[0]) and (run[0] not in zoneCounters) and (run[0] != 'CoreCtrl'): #name of the zone
zoneCounters[run[0]] = [0, 0]
if ('RF' in run[0]) and (run[0] != 'CoreCtrl'):
zoneCounters[run[0]][0] += 1 #Add new inj to total
#pdb.set_trace()
if run[1] in ['AOM', 'Crash', 'Hang', 'ISM & AOM']:
zoneCounters[run[0]][1] += 1 #Add new ACE fault
totalCritErrors=0
for k in zoneCounters:
totalCritErrors += zoneCounters[k][1]
names = []
critPart = []
for k in zoneCounters:
names.append(k)
critPart.append((zoneCounters[k][1]/totalCritErrors)*100)
# pdb.set_trace()
names, critPart = zip(*sorted(zip(names, critPart), key=lambda t:int(t[0][2:]))) #please see Simon and Davide for this shit
print(names)
return names, critPart
def createHistogram_cycleDifferences(runs):
numRuns = len(runs)
#create a list containing only the cycle differences
cycleDifferences = []
for run in runs:
if (run[2] != 'not applicable') and (run[2] != 0):
cycleDifferences.append(run[2])
# pdb.set_trace()()
minDiff = min(cycleDifferences)
maxDiff = max(cycleDifferences)
meanDiff = sum(cycleDifferences)/len(cycleDifferences)
print('Min diff: ', str(minDiff))
print('Max diff: ', str(maxDiff))
print('Mean diff: ', str(meanDiff))
plt.figure()
plt.hist(cycleDifferences, bins=100)
plt.title('Cycle diffs')
plt.xlabel('num cycles')
plt.show()
################################################################################
def main():
......@@ -92,16 +242,38 @@ def main():
#load the patterns data
runs = pickle.load(open(args.inputFile, 'rb'))
# pdb.set_trace()()
numRuns = len(runs)
print('Num runs : ' + str(numRuns))
############################################################################
# Cycles difference
############################################################################
createHistogram_cycleDifferences(runs)
# pdb.set_trace()()
names, hist = createHistogram_ends(runs)
plt.figure()
plt.bar(names, hist)
plt.title('Error occurences, matmul_int_8, ' + str(numRuns) + ' injections, area aware')
plt.xlabel('Error class')
plt.ylabel('Error occurence probability')
names = np.array(names)
hist = np.array(hist)
inds = names.argsort()
# pdb.set_trace()
plt.bar(names[inds], hist[inds])
# pdb.set_trace()
#plt.bar(names, hist)
plt.title('Error occurences, ' + str(numRuns) + ' injections', fontsize=fs)
plt.xlabel('Error class', fontsize=fs)
plt.ylabel('Error occurence probability', fontsize=fs)
plt.ylim(0, 1)
plt.grid(color='k', linestyle=':', linewidth=0.5)
plt.xticks(fontsize=fs-4)
plt.yticks(fontsize=fs-4)
# print population proportions
for ftype in range(len(names)):
print('{0}: {1:.2f}%'.format(names[ftype], hist[ftype]*100))
names, hist = createHistogram_zones(runs)
plt.figure()
......@@ -110,12 +282,56 @@ def main():
names, hist = createHistogram_AVF(runs)
plt.figure()
#plt.bar(names, hist)
names = np.array(names)
hist = np.array(hist)
inds = names.argsort()
# pdb.set_trace()
plt.bar(names[inds], hist[inds])
plt.title('Pipeline registers AVF, matmul_int_8, ' + str(numRuns) + ' injections', fontsize=fs)
plt.xlabel('Register name', fontsize=fs)
plt.ylabel('AVF', fontsize=fs)
plt.xticks(fontsize=fs-4)
plt.yticks(fontsize=fs-4)
#plt.ylim(0, 1)
plt.grid(color='k', linestyle=':', linewidth=0.5)
#participation of each pipeline stage in critical errors
names, hist = createHistogram_participation(runs)
plt.figure()
#plt.bar(names, hist)
names = np.array(names)
hist = np.array(hist)
inds = names.argsort()
# pdb.set_trace()
plt.bar(names[inds], hist[inds])
plt.title('Registers participation in critical faults apparition', fontsize=fs+10)
plt.xlabel('Register name', fontsize=fs+5)
plt.ylabel('Participation (%)', fontsize=fs+5)
plt.xticks(fontsize=fs-4)
plt.yticks(fontsize=fs-4)
#plt.ylim(0, 1)
plt.grid(color='k', linestyle=':', linewidth=0.5)
#participation of each pipeline stage in critical errors
names, hist = createHistogram_RFparticipation(runs)
plt.figure()
#plt.bar(names, hist)
names = np.array(names)
hist = np.array(hist)
# pdb.set_trace()
plt.bar(names, hist)
plt.title('Pipeline registers AVF, matmul_int_8, ' + str(numRuns) + ' injections, area aware')
plt.xlabel('Register name')
plt.ylabel('AVF')
plt.title('Register file participation in critical faults apparition', fontsize=fs+10)
plt.xlabel('Register name', fontsize=fs+5)
plt.ylabel('Participation (%)', fontsize=fs+5)
plt.xticks(fontsize=fs-4, rotation='vertical')
plt.yticks(fontsize=fs-4)
#plt.ylim(0, 1)
plt.grid(color='k', linestyle=':', linewidth=0.5)
plt.show()
# pdb.set_trace()()
if __name__ == "__main__":
main()
File mode changed from 100644 to 100755
#!/usr/bin/env python3
import pickle, argparse, pdb
import matplotlib.pyplot as plt
import numpy as np