Skip to content
This repository has been archived by the owner on Jan 7, 2023. It is now read-only.

Commit

Permalink
update code to support multithreading
Browse files Browse the repository at this point in the history
  • Loading branch information
dfangshuo committed Apr 25, 2020
1 parent d5e8c1e commit 4742ae3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
14 changes: 12 additions & 2 deletions envs/neurovec.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,24 @@ def __init__(self, env_config):

if self.compile:
# stores the runtimes of O3 to compute the RL reward and compared to -O3.
self.O3_runtimes=get_O3_runtimes(self.new_rundir,self.new_testfiles)
self.O3_runtimes = get_O3_runtimes(self.new_rundir, self.new_testfiles)
runtimes_with_pid = {}
for key in self.O3_runtimes:
value = self.O3_runtimes[key]

# assumes keys are of the format ./dirname/...
key_components = key[2:].split('/') # removes the `./` prefix
key_components[0] = self.new_rundir
key = '/'.join(key_components)
runtimes_with_pid[key] = value
self.O3_runtimes = runtimes_with_pid

def init_from_env_config(self,env_config):
'''Receives env_config and initalizes all config parameters.'''
# dirpath is the path to the train data.
self.dirpath = env_config.get('dirpath')
# new_rundir is the directory to create and copy the train data to.
self.new_rundir = env_config.get('new_rundir')
self.new_rundir = env_config.get('new_rundir') + str(os.getpid())
# whether or not in inference mode
self.inference_mode = env_config.get('inference_mode', False)
if self.inference_mode:
Expand Down
9 changes: 5 additions & 4 deletions utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

#the maximum number of leafs in the LLVM abstract sytnax tree
MAX_LEAF_NODES = 320
TEST_SHELL_COMMAND_TIMEOUT = '50s'
# pragma line injected for each loop
pragma_line = '#pragma clang loop vectorize_width({0}) interleave_count({1})\n'

Expand Down Expand Up @@ -168,8 +169,8 @@ def get_encodings_from_local(rundir):
def run_llvm_test_shell_command(rundir,filename):
'''runs the file after the pragma is injected
and returns runtime.'''
full_path_header = os.path.join(rundir,'header.c')
cmd1 = 'timeout 4s '+ os.environ['CLANG_BIN_PATH'] + ' -O3 -lm '+full_path_header \
full_path_header = os.path.join(rundir, 'header.c')
cmd1 = 'timeout ' + TEST_SHELL_COMMAND_TIMEOUT + ' ' + os.environ['CLANG_BIN_PATH'] + ' -O3 -lm '+full_path_header \
+' ' +filename+' -o ' +filename[:-1]+'o'
cmd2 = filename[:-1]+'o '
os.system(cmd1)
Expand All @@ -179,8 +180,8 @@ def run_llvm_test_shell_command(rundir,filename):
runtime = None #None if fails
logger.warning('Could not compile ' + filename +
' due to time out. Setting runtime to: ' +
str(runtime)+'. Considering increasing the timeout,'+
' which is currently set to 4 seconds.')
str(runtime)+'. Considering increasing the TEST_SHELL_COMMAND_TIMEOUT,'+
' which is currently set to ' + TEST_SHELL_COMMAND_TIMEOUT)
return runtime

def get_runtime(rundir,new_code,current_filename):
Expand Down

0 comments on commit 4742ae3

Please sign in to comment.