Skip to content
Snippets Groups Projects
Commit 802c501f authored by Hashim Sharif's avatar Hashim Sharif
Browse files

Fixing polling thread issues in devtuner

parent 43f6d609
No related branches found
No related tags found
No related merge requests found
...@@ -93,6 +93,7 @@ class DevTuner(MeasurementInterface): ...@@ -93,6 +93,7 @@ class DevTuner(MeasurementInterface):
self.process = subprocess.Popen([run_cmd, str(runs)], stdout = FNULL) self.process = subprocess.Popen([run_cmd, str(runs)], stdout = FNULL)
def signalPipe(self): def signalPipe(self):
fifo = open("/tmp/opentuner_fifo", "w") fifo = open("/tmp/opentuner_fifo", "w")
...@@ -102,20 +103,24 @@ class DevTuner(MeasurementInterface): ...@@ -102,20 +103,24 @@ class DevTuner(MeasurementInterface):
def pollOnProcess(self, self2): def pollOnProcess(self, self2):
print (" self.piped_execution = ", self.piped_execution, "*** \n") print (" self.piped_execution = ", self.piped_execution, "*** \n")
sleep(5) sleep(5)
while (1): while (not self.escape_poll_thread):
poll = self.process.poll() poll = self.process.poll()
#print ("POLLING") #print ("POLLING")
if poll is not None: # If process aborted, invoke another instance if poll is not None: # If process aborted, invoke another instance
self.corrupted_run = True sleep(6)
self.invokeBinary(100000)
self.signalPipe() poll = self.process.poll()
if not utils.check_pid(self.process.pid) and poll is not None: # Second check for process existence
self.corrupted_run = True
utils.process_kill(self.process.pid) # Kill existing process if exists
self.invokeBinary(100000)
self.signalPipe()
...@@ -145,6 +150,7 @@ class DevTuner(MeasurementInterface): ...@@ -145,6 +150,7 @@ class DevTuner(MeasurementInterface):
# Adding knob to use piped execution instead # Adding knob to use piped execution instead
self.piped_execution = True self.piped_execution = True
self.corrupted_run = False self.corrupted_run = False
self.escape_poll_thread = False
objective = ThresholdAccuracyMinimizeTime(self.tunerData.accuracy_threshold) objective = ThresholdAccuracyMinimizeTime(self.tunerData.accuracy_threshold)
input_manager = FixedInputManager(size=self.tunerData.num_layers) input_manager = FixedInputManager(size=self.tunerData.num_layers)
...@@ -251,6 +257,8 @@ class DevTuner(MeasurementInterface): ...@@ -251,6 +257,8 @@ class DevTuner(MeasurementInterface):
def save_final_config(self, configuration): def save_final_config(self, configuration):
# Indication to terminate polling thread
self.escape_poll_thread = True
if self.piped_execution: if self.piped_execution:
#self.stopProcess() #self.stopProcess()
...@@ -260,7 +268,7 @@ class DevTuner(MeasurementInterface): ...@@ -260,7 +268,7 @@ class DevTuner(MeasurementInterface):
print "Final configuration", configuration.data print "Final configuration", configuration.data
print "Done with Autotuning Run \n" print "Done with Autotuning Run \n"
sleep(6) sleep(4)
return return
......
import psutil import psutil
from time import sleep
import os
def readCostFile(cost_file_path): def readCostFile(cost_file_path):
...@@ -119,11 +122,36 @@ def addInfoToOutFile(f_path, accuracy, total_runs, total_comps, speedup): ...@@ -119,11 +122,36 @@ def addInfoToOutFile(f_path, accuracy, total_runs, total_comps, speedup):
def check_pid(pid):
""" Check For the existence of a unix pid. """
try:
os.kill(pid, 0)
except OSError:
return False
else:
return True
def process_kill(proc_pid): def process_kill(proc_pid):
if not check_pid(proc_pid):
return # Return if process does not exist
process = psutil.Process(proc_pid) process = psutil.Process(proc_pid)
for proc in process.children(recursive=True):
proc.kill() try:
process.kill() for proc in process.children(recursive=True):
proc.kill()
process.kill()
print ("\n\n\n\n\n\ %%%%% Killed Process \n\n\n\n")
except:
print ("\n\n\n\n PROCESS NOT KILLED ------- \n\n\n\n\n\n\n")
#sleep(20)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment