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
b44becb8
Commit
b44becb8
authored
5 years ago
by
Elizabeth
Browse files
Options
Downloads
Patches
Plain Diff
Added code to check whether current operation time/energy is greater than baseline op
parent
724869d3
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
+88
-43
88 additions, 43 deletions
llvm/projects/soc_simulator/src/driver_new_config.py
with
88 additions
and
43 deletions
llvm/projects/soc_simulator/src/driver_new_config.py
+
88
−
43
View file @
b44becb8
...
...
@@ -34,9 +34,7 @@ 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
=
{}
# {conf name: (first line, [[layer value if promise], [tensor vals if gpu]])}
@staticmethod
...
...
@@ -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,11 +209,7 @@ 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
)
...
...
@@ -246,20 +244,17 @@ 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
)
layer_results
.
append
((
quant_time
+
conv_time
,
quant_energy
+
conv_energy
,
'
'
.
join
(
layer_as_lst
[
i
:
i
+
3
])))
total_time
+=
quant_time
+
conv_time
total_energy
+=
quant_energy
+
conv_energy
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
)
line
=
config_file
.
readline
().
strip
()
config_file
.
close
()
#print("AGGREGATE RESULTS", self.__aggregate_results)
...
...
@@ -307,7 +302,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.
"
)
...
...
@@ -365,39 +360,89 @@ class Driver:
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_time
=
baseline_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
=
[]
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
if
op_energy
>
baseline_energy
:
final_energy
+=
baseline_energy
final_tensor_op
=
baseline_op
else
:
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
)
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
()
results_file
.
close
()
if
not
baseline_conf
:
baseline_conf
=
self
.
__conf_results
[
conf_name
]
baseline_time
,
baseline_energy
=
get_baseline_times_enegies
()
write_conf_to_file
(
conf_name
,
baseline_conf
,
1
,
1
)
else
:
curr_conf
=
self
.
__conf_results
[
conf_name
]
final_time
,
final_energy
,
curr_conf
=
get_final_times_energies_conf
(
curr_conf
)
assert
(
final_time
<=
baseline_time
)
assert
(
final_energy
<=
baseline_energy
)
write_conf_to_file
(
conf_name
,
curr_conf
,
final_time
/
baseline_time
,
final_energy
/
baseline_energy
)
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