Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hpvm-release
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
llvm
hpvm-release
Commits
182c4a05
Commit
182c4a05
authored
5 years ago
by
Elizabeth
Browse files
Options
Downloads
Patches
Plain Diff
Added computations for relative speedup
parent
b6c24f71
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
llvm/projects/soc_simulator/src/driver_new_config.py
+102
-54
102 additions, 54 deletions
llvm/projects/soc_simulator/src/driver_new_config.py
with
102 additions
and
54 deletions
llvm/projects/soc_simulator/src/driver_new_config.py
+
102
−
54
View file @
182c4a05
...
...
@@ -34,9 +34,8 @@ class Driver:
# Operation names need to be stored in order of insertion
self
.
__tensor_table
=
defaultdict
(
lambda
:
list
(
defaultdict
(
str
)))
# [Time/Energy][config name] = time/energy
self
.
__aggregate_results
=
defaultdict
(
lambda
:
defaultdict
(
float
))
self
.
__config_count
=
0
self
.
__conf_results
=
[]
# indexed
#self.__conf_results = {} # {conf name: (first line, [[layer value if promise], [tensor vals if gpu]])}
@staticmethod
...
...
@@ -79,7 +78,6 @@ class Driver:
if
not
os
.
path
.
isfile
(
self
.
__layer_filename
):
print
(
"
ERROR: %s was not found.
"
%
self
.
__layer_filename
)
exit
(
1
)
layer_file
=
open
(
self
.
__layer_filename
,
"
r
"
)
for
line
in
layer_file
:
layer_data
=
line
.
strip
().
split
(
'
,
'
)
...
...
@@ -141,14 +139,14 @@ class Driver:
operation_data
[
"
Name
"
]
=
op_name
# Number of data items (#s) needs to match up with the # of cols
#
print(len(op_data) - 1, len(col_names))
#
print(op_data)
#
print(col_names)
print
(
len
(
op_data
)
-
1
,
len
(
col_names
))
print
(
op_data
)
print
(
col_names
)
#
assert(len(op_data) - 1 == len(col_names))
assert
(
len
(
op_data
)
-
1
==
len
(
col_names
))
# Go through all data items (each col element) per operation
for
i
in
range
(
len
(
col_names
)):
#
print(col_names[i], float(op_data[i + 1]))
print
(
col_names
[
i
],
float
(
op_data
[
i
+
1
]))
operation_data
[
col_names
[
i
]]
=
float
(
op_data
[
i
+
1
])
layer_operations
.
append
(
operation_data
)
...
...
@@ -173,11 +171,14 @@ class Driver:
while
line
:
assert
(
line
==
"
+++++
"
)
print
(
"
CONFIGURATION
"
)
curr_conf_results
=
[]
prev_layer
=
Driver
.
PrecisionTypes
.
FP32
curr_layer
=
None
line
=
config_file
.
readline
().
strip
()
first_line
=
line
conf_name
=
line
.
split
(
'
'
)[
0
]
assert
(
conf_name
.
startswith
(
"
conf
"
))
line
=
config_file
.
readline
().
strip
()
...
...
@@ -193,6 +194,7 @@ class Driver:
layer_table_data
=
self
.
__tensor_layers
[
layer_ind
]
layer_name
=
layer_table_data
[
"
Name
"
]
layer_results
=
[]
if
Driver
.
is_promise
(
layer_as_lst
[
1
]):
print
(
"
Running layer %s on PROMISE
"
%
layer_name
)
curr_layer
=
Driver
.
PrecisionTypes
.
PROMISE
...
...
@@ -207,17 +209,11 @@ class Driver:
time
,
energy
=
self
.
__run_promise_simulation
(
param_val
,
layer_table_data
)
total_time
+=
time
total_energy
+=
energy
self
.
__aggregate_results
[
Driver
.
results_time_key
][
conf_name
]
+=
total_time
self
.
__aggregate_results
[
Driver
.
results_energy_key
][
conf_name
]
+=
total_energy
print
(
total_time
,
total_energy
)
#print("AGGREGATE RESULTS: ", self.__aggregate_results)
layer_results
.
append
((
total_time
,
total_energy
,
'
'
.
join
(
layer_as_lst
[
1
:])))
elif
Driver
.
is_gpu
(
layer_as_lst
[
1
]):
print
(
"
Running layer %s on the GPU
"
%
layer_name
)
total_time
=
0
total_energy
=
0
tensor_count
=
0
# 3 elements per tensor operation
...
...
@@ -246,20 +242,16 @@ class Driver:
tensor_count
,
layer_table_data
)
conv_time
,
conv_energy
=
self
.
__run_gpu_simulation
(
curr_layer
,
layer_name
,
\
tensor_count
,
approx_type
,
op_number
)
total_time
+=
quant_time
+
conv_time
total_energy
+=
quant_energy
+
conv_energy
layer_results
.
append
((
quant_time
+
conv_time
,
quant_energy
+
conv_energy
,
'
'
.
join
(
layer_as_lst
[
i
:
i
+
3
])))
prev_layer
=
curr_layer
tensor_count
+=
1
print
(
total_time
,
total_energy
)
self
.
__aggregate_results
[
Driver
.
results_time_key
][
conf_name
]
+=
total_time
self
.
__aggregate_results
[
Driver
.
results_energy_key
][
conf_name
]
+=
total_energy
print
(
Driver
.
results_energy_key
,
conf_name
)
#print("AGGREGATE RESULTS", self.__aggregate_results)
line
=
config_file
.
readline
().
strip
()
prev_layer
=
curr_layer
curr_conf_results
.
append
(
layer_results
)
#self.__conf_results[conf_name] = (first_line, curr_conf_results)
self
.
__conf_results
.
append
(
(
first_line
,
curr_conf_results
)
)
line
=
config_file
.
readline
().
strip
()
config_file
.
close
()
#print("AGGREGATE RESULTS", self.__aggregate_results)
...
...
@@ -307,7 +299,7 @@ class Driver:
elif
Driver
.
is_fc
(
layer_name
):
rows_a
=
layer_data
[
"
RA
"
]
cols_a
=
layer_data
[
"
CA
"
]
rows_b
=
cols_
a
rows_b
=
cols_
cols_b
=
layer_data
[
"
CB
"
]
else
:
print
(
"
PROMISE can
'
t run whatever this layer is.
"
)
...
...
@@ -356,48 +348,104 @@ class Driver:
elif
curr_layer
==
Driver
.
PrecisionTypes
.
FP16
:
time_key
=
"
fp16_time
"
energy_key
=
"
fp16_energy
"
#
print(time_key, energy_key)
print
(
time_key
,
energy_key
)
conversion_time
=
tensor_info
[
time_key
]
conversion_energy
=
tensor_info
[
energy_key
]
#
print(conversion_time, conversion_energy)
print
(
conversion_time
,
conversion_energy
)
print
(
"
GPU: (%f, %f)
"
%
(
conversion_time
,
conversion_energy
))
return
conversion_time
,
conversion_energy
def
__write_output
(
self
):
# Need to write the time/energy pairs to the configuration file
results_file
=
open
(
self
.
__results_filename
,
"
w
"
)
# Layout is based off the configuration filename
config_file
=
open
(
self
.
__config_filename
,
"
r
"
)
baseline_time
=
baseline_energy
=
None
results_file
=
open
(
self
.
__results_filename
,
"
w
"
)
def
write_conf_to_file
(
conf_name
,
final_conf
,
time_speedup
,
energy_speedup
):
# conf = [layer value if promise], [tensor vals if gpu]]
conf_str
=
[
"
+++++
"
]
# process the first line
first_line
,
layers
=
final_conf
first_line_lst
=
first_line
.
split
(
'
'
)
assert
first_line_lst
[
0
]
==
conf_name
new_header
=
[
conf_name
]
new_header
.
append
(
repr
(
time_speedup
))
new_header
.
append
(
repr
(
energy_speedup
))
new_header
.
append
(
first_line_lst
[
-
1
])
new_header
.
append
(
first_line_lst
[
-
2
])
conf_str
.
append
(
'
'
.
join
(
new_header
))
for
ind
,
layer
in
enumerate
(
layers
):
layer_lst
=
[
str
(
ind
+
1
)]
for
op_time
,
op_energy
,
tensor_op
in
layer
:
layer_lst
.
append
(
tensor_op
)
conf_str
.
append
(
'
'
.
join
(
layer_lst
))
conf_str
.
append
(
"
-----
\n
"
)
results_file
.
write
(
'
\n
'
.
join
(
conf_str
))
baseline_conf
=
None
baseline_total_time
=
baseline_total_energy
=
0
def
get_baseline_times_enegies
():
curr_time
=
curr_energy
=
0
for
layer
in
baseline_conf
[
1
]:
for
op_time
,
op_energy
,
tensor_op
in
layer
:
curr_time
+=
op_time
curr_energy
+=
op_energy
return
curr_time
,
curr_energy
def
get_final_times_energies_conf
(
curr_conf
):
final_time
=
final_energy
=
0
final_conf
=
[]
# List (conf) of lists (layers) of tuples (operation data)
for
layer_ind
,
layer
in
enumerate
(
curr_conf
[
1
]):
final_conf_layer
=
[]
for
tensor_ind
,
(
op_time
,
op_energy
,
tensor_op
)
in
enumerate
(
layer
):
baseline_time
,
baseline_energy
,
baseline_op
=
baseline_conf
[
1
][
layer_ind
][
tensor_ind
]
final_tensor_op
=
tensor_op
if
op_time
>
baseline_time
:
final_time
+=
baseline_time
final_tensor_op
=
baseline_op
else
:
final_time
+=
op_time
# Ignoring bigger energies for now
'''
if op_energy > baseline_energy:
print(
"
BIGGER ENERGY
"
)
final_energy += baseline_energy
final_tensor_op = baseline_op
else:
final_energy += op_energy
'''
final_energy
+=
op_energy
final_conf_layer
.
append
((
None
,
None
,
final_tensor_op
))
# Don't care about the times and energies when writing
final_conf
.
append
(
final_conf_layer
)
return
final_time
,
final_energy
,
(
curr_conf
[
0
],
final_conf
)
conf_index
=
0
for
line
in
config_file
:
if
line
.
startswith
(
"
conf
"
):
# Write in the time and energy
if
line
.
startswith
(
"
conf
"
):
orig_line_lst
=
line
.
split
(
'
'
)
conf_header
=
[]
conf_name
=
orig_line_lst
[
0
]
if
not
baseline_time
:
baseline_time
=
self
.
__aggregate_results
[
Driver
.
results_time_key
][
conf_name
]
if
not
baseline_energy
:
baseline_energy
=
self
.
__aggregate_results
[
Driver
.
results_energy_key
][
conf_name
]
print
(
"
FP32 Baseline time is %f and baseline energy is %f
"
%
(
baseline_time
,
baseline_energy
))
print
(
conf_name
,
self
.
__aggregate_results
[
Driver
.
results_time_key
][
conf_name
],
self
.
__aggregate_results
[
Driver
.
results_energy_key
][
conf_name
])
conf_header
.
append
(
conf_name
)
conf_header
.
append
(
repr
(
baseline_time
/
self
.
__aggregate_results
[
Driver
.
results_time_key
][
conf_name
]))
conf_header
.
append
(
repr
(
baseline_energy
/
self
.
__aggregate_results
[
Driver
.
results_energy_key
][
conf_name
]))
# TODO Accuracy/accuracy loss
conf_header
.
append
(
orig_line_lst
[
-
2
])
conf_header
.
append
(
orig_line_lst
[
-
1
])
results_file
.
write
(
"
%s
"
%
'
'
.
join
(
conf_header
))
else
:
results_file
.
write
(
"
%s
"
%
line
)
# Copy the line
config_file
.
close
()
if
not
baseline_conf
:
baseline_conf
=
self
.
__conf_results
[
conf_index
]
#conf_name]
print
(
"
FOUND baseline
"
,
baseline_conf
)
baseline_total_time
,
baseline_total_energy
=
get_baseline_times_enegies
()
results_file
.
write
(
"
%s
\n
"
%
repr
(
baseline_total_time
))
# write baseline time to top of file
write_conf_to_file
(
conf_name
,
baseline_conf
,
1
,
1
)
else
:
curr_conf
=
self
.
__conf_results
[
conf_index
]
#conf_name]
final_time
,
final_energy
,
curr_conf
=
get_final_times_energies_conf
(
curr_conf
)
assert
(
final_time
<=
baseline_total_time
)
#assert(final_energy <= baseline_total_energy)
write_conf_to_file
(
conf_name
,
curr_conf
,
baseline_total_time
/
final_time
,
baseline_total_energy
/
final_energy
)
conf_index
+=
1
results_file
.
close
()
config_file
.
close
()
if
__name__
==
"
__main__
"
:
if
len
(
sys
.
argv
)
!=
5
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment