Skip to content

TensorFI: Add state space based random sampling #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion TensorFI/fiConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,11 @@ def __str__(self):
res.append(" }")
return "\n".join(res)

def __init__(self,fiParams):
def __init__(self, fiParams, opProbabilities):
"Configure the initial fault injection parameters from the fiParams Dictionary"
# First configure the Scalar fault type
# Default value of fault is NoFault
self.opProbabilities = opProbabilities
if fiParams.has_key(Fields.ScalarFaultType.value):
faultTypeScalar = fiParams[Fields.ScalarFaultType.value]
else:
Expand Down
6 changes: 3 additions & 3 deletions TensorFI/injectFault.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# and is called from TensorFI.py's constructor

# NOTE: This has to be in this module or else fiConf won't be accessible
def initFIConfig(fiParams):
def initFIConfig(fiParams, opProbabilities = []):
"Initialize the global variable fiConf with the params"
global fiConf
global count
Expand All @@ -36,7 +36,7 @@ def initFIConfig(fiParams):
# which op to be injected in the whole run
global injectedOp

fiConf = FIConfig(fiParams)
fiConf = FIConfig(fiParams, opProbabilities)
logging.debug("Initialized config file : " + str(fiConf))

# Setup the random seed for the fault injector if one is specified
Expand Down Expand Up @@ -234,7 +234,7 @@ def condPerturb(op, res):
totalVistedOp += 1
# select one random op to be injected in the whole run
if(injectedOp == 0):
injectedOp = np.random.randint(low=1, high=totalInstance+1)
injectedOp = np.random.choice(totalInstance, 1, fiConf.opProbabilities) + 1
# inject fault at the output of the operation
if(totalVistedOp == injectedOp):
res = perturb(res)
Expand Down
19 changes: 18 additions & 1 deletion TensorFI/tensorFI.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,17 @@ def printInjectMap(self):
print "\t", tensor.name, " : ", fiTensor.name
print "Done fiMap"

def setProbability(self):
"Set the probabilities for FI in operators based on the output state space"
opProbability = []
totalStateSpace = 0.
for (tensor, fiTensor) in self.fiMap.iteritems():
opShape = tensor.shape.num_elements()
opProbability.append(opShape)
totalStateSpace += opShape
opProbability[:] = [x / totalStateSpace for x in opProbability]
return opProbability

# These are all functions that can be called externally for interacting with the injector

def turnOffInjections(self):
Expand Down Expand Up @@ -193,7 +204,13 @@ def __init__(self, s, # This is the session from tensorFlow
# Configure the fault injection parameters for the injection functions
# fiConf is a global variable as it needs to be accessible to the FI functions
logging.info("Initializing the fault injection parameters")
initFIConfig(fiParams)

# Random sampling across state space distribution for one fault per run
if fiParams["InjectMode"] == "oneFaultPerRun":
opProbabilities = self.setProbability()
initFIConfig(fiParams, opProbabilities)
else:
initFIConfig(fiParams)

# Initialize the default fault log - this may be overridden by the launch method later
# This is in case the run method is called directly without going through the launch
Expand Down