forked from vtsynergy/OpenDwarfs
-
Notifications
You must be signed in to change notification settings - Fork 2
/
opendwarf_miner_utils.py
76 lines (65 loc) · 3.24 KB
/
opendwarf_miner_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import os #to get directory name of the calling script
import subprocess #for exec
import glob #for wildcards
import shutil #to move files
def DMError(error_string):
print("*"*80)
print(" DwarfMiner Error: "+error_string)
print("*"*80)
def GenerateDeviceParameters(platform_id,device_id,type_id):
assert type(platform_id) is int, DMError("platform_id is not of type \'int\'")
assert type(device_id) is int, DMError("device_id is not of type \'int\'")
assert type(type_id) is int, DMError("type_id is not of type \'int\'")
return(" -p {} -d {} -t {} -- ".format(platform_id,device_id,type_id))
def GeneratePAPIParameters(papi1,papi2):
assert type(papi1) is str, DMError("papi1 is not of type \'str\'")
assert type(papi2) is str, DMError("papi1 is not of type \'str\'")
return("LSB_PAPI1="+papi1+' LSB_PAPI2='+papi2+" ")
def StoreRun(application,directory):
assert type(directory) is str, DMError("directory is not of type \'str\'")
i = 0
while os.path.exists(directory+".{}".format(i)):
i += 1
numbered_directory = directory+".{}".format(i)
os.makedirs(numbered_directory)
run_name = application['alias']
for run in glob.glob('lsb.'+run_name+'.'+'*'):
shutil.move(run,numbered_directory)
#def GenerateWorkgroupParameters(one_dimension,two_dimension_x=0,two_dimension_y=0):
# assert type(one_dimension) is int, DMError("one_dimension is not of type \'int\'")
# assert type(two_dimension_x) is int, DMError("two_dimension_x is not of type \'int\'")
# assert type(two_dimension_y) is int, DMError("two_dimension_y is not of type \'int\'")
# return("--workgroups \"-local1D {} -local2D {} {}\" ".format(one_dimension,two_dimension_x,two_dimension_y))
def RunApplicationWithArguments(application,arguments,parameters,repeats=1,papi_env=None):
command = './'+application['name']+parameters+arguments
if papi_env is not None:
command = papi_env + command
print('Running {}'.format(command))
for i in range(0,repeats):
if repeats != 1:
print('iteration {}'.format(i))
#process = subprocess.Popen(command,
# shell=True,
# stdout=subprocess.PIPE,
# stderr=subprocess.PIPE)
#
#process.wait()
#if process.returncode != 0:
# DMError('Application {} failed with {}'.format(application['name'],
# process.stderr.readlines()))
try:
output = subprocess.check_output(command,shell=True)
except subprocess.CalledProcessError as e:
DMError('Application {} failed with {}'.format(application['name'], e.output))
return False
return True
def RunApplication(application,parameters,repeats=1,papi_env=None):
return RunApplicationWithArguments(application,
application['default'],
parameters,
repeats,
papi_env)
def RunDwarf(dwarf,parameters):
assert type(dwarf) is list, DMError('dwarf is not of type \'list\'')
for application in dwarf:
RunApplication(application,parameters)