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
68632c71
Commit
68632c71
authored
5 years ago
by
Elizabeth
Browse files
Options
Downloads
Patches
Plain Diff
Fixed bug in parsing alg
parent
96ac90c5
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
+82
-75
82 additions, 75 deletions
llvm/projects/soc_simulator/src/driver_new_config.py
with
82 additions
and
75 deletions
llvm/projects/soc_simulator/src/driver_new_config.py
+
82
−
75
View file @
68632c71
...
...
@@ -10,18 +10,54 @@ class Driver:
FP16
=
0
FP32
=
1
PROMISE
=
2
PERF
=
3
results_time_key
=
"
Time
"
results_energy_key
=
"
Energy
"
def
__get_str
(
self
,
appr
):
if
appr
==
Driver
.
ApproxTypes
.
FP16
:
return
"
FP16
"
elif
appr
==
Driver
.
ApproxTypes
.
FP32
:
return
"
FP32
"
elif
appr
==
Driver
.
ApproxTypes
.
PROMISE
:
return
"
PROMISE
"
def
driver
(
self
):
self
.
__parse_tensor_layer_file
()
self
.
__parse_tensor_table
()
self
.
__run_simulations
()
self
.
__display_results
()
#self.__parse_tensor_layer_file()
#self.__parse_tensor_table()
#self.__run_simulations()
#self.__display_results()
config_file
=
open
(
self
.
__config_filename
,
"
r
"
)
line
=
config_file
.
readline
().
strip
()
while
line
:
print
(
line
)
assert
(
line
==
"
+++++
"
)
print
(
"
CONFIGURATION
"
)
line
=
config_file
.
readline
().
strip
()
# configuration data
conf_name
=
line
.
split
(
'
'
)[
0
]
assert
(
conf_name
.
startswith
(
"
conf
"
))
print
(
conf_name
)
line
=
config_file
.
readline
().
strip
()
# layers
while
line
!=
"
-----
"
:
print
(
"
LAYER
"
,
line
==
"
-----
"
)
layer_data
=
line
.
split
(
'
'
)
if
layer_data
[
1
]
==
"
promise
"
:
print
(
"
PROMISE
"
)
elif
layer_data
[
1
]
==
"
gpu
"
:
print
(
"
GPU
"
)
for
i
in
range
(
2
,
len
(
layer_data
),
3
):
op_type
=
layer_data
[
i
]
approx_type
=
layer_data
[
i
+
1
]
op_number
=
layer_data
[
i
+
2
]
print
(
op_type
,
approx_type
,
op_number
)
line
=
config_file
.
readline
().
strip
()
line
=
config_file
.
readline
().
strip
()
config_file
.
close
()
def
__init__
(
self
,
layer_filename
,
table_filename
,
config_filename
,
results_filename
):
self
.
__layer_filename
=
layer_filename
...
...
@@ -144,6 +180,7 @@ class Driver:
def
__quantize
(
self
,
curr_layer
,
prev_layer
,
h2f_f2h_operation_ind
,
layer_data
):
print
(
self
.
__get_str
(
curr_layer
),
self
.
__get_str
(
prev_layer
),
h2f_f2h_operation_ind
)
if
curr_layer
==
prev_layer
or
curr_layer
==
Driver
.
ApproxTypes
.
PROMISE
\
or
prev_layer
==
Driver
.
ApproxTypes
.
PROMISE
:
# No quantization needed
return
0.0
,
0.0
...
...
@@ -155,7 +192,6 @@ class Driver:
# Get h2f/f2h data using the first tensor operation in the layer
# (which is why order matters in the tensor table)
print
(
layer_name
,
self
.
__tensor_table
[
layer_name
])
tensor_op_row
=
self
.
__tensor_table
[
layer_name
][
h2f_f2h_operation_ind
]
if
curr_layer
==
Driver
.
ApproxTypes
.
FP32
:
time
=
tensor_op_row
[
"
h2f_time
"
]
...
...
@@ -189,7 +225,7 @@ class Driver:
exit
(
1
)
# Run promise simulator
# TODO need to print time and energy in the ptm runner so we can pipe it
output
=
subprocess
.
Popen
([
"
./ptm
"
,
str
(
rows_a
),
str
(
cols_a
),
str
(
rows_b
),
\
output
=
subprocess
.
Popen
([
"
./ptm
_new
"
,
str
(
rows_a
),
str
(
cols_a
),
str
(
rows_b
),
\
str
(
cols_b
),
str
(
patch_factor
),
str
(
swing
)],
\
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
).
communicate
()[
0
]
total_time_energy
=
output
.
strip
().
split
(
'
,
'
)
...
...
@@ -199,100 +235,71 @@ class Driver:
return
float
(
total_time_energy
[
0
]),
float
(
total_time_energy
[
1
])
def
__run_gpu_simulation
(
self
,
curr_layer
,
layer_name
,
tensor_ind
):
tensor_info
=
self
.
__tensor_table
[
layer_name
][
tensor_ind
]
if
curr_layer
==
Driver
.
ApproxTypes
.
FP32
:
conversion_time
=
tensor_info
[
"
fp32_time
"
]
conversion_energy
=
tensor_info
[
"
fp32_energy
"
]
else
:
conversion_time
=
tensor_info
[
"
fp16_time
"
]
conversion_energy
=
tensor_info
[
"
fp16_energy
"
]
print
(
"
GPU: (%f, %f)
"
%
(
conversion_time
,
conversion_energy
))
return
(
conversion_time
,
conversion_energy
)
def
__run_simulations
(
self
):
if
not
os
.
path
.
isfile
(
self
.
__config_filename
):
print
(
"
ERROR: %s was not found
"
%
self
.
__config_filename
)
exit
(
1
)
config_file
=
open
(
self
.
__config_filename
,
"
r
"
)
line
=
config_file
.
readline
().
strip
()
while
line
:
assert
(
line
.
startswith
(
"
+++++
"
))
config_name
=
config_file
.
readline
().
strip
().
split
(
'
'
)[
0
]
# Next line = configuration name
print
(
"
CONFIGURATION
"
)
line
=
config_file
.
readline
().
strip
()
layer_ind
=
0
# NOTE can also use the leftmost number in the currl ine
# each line = indepedent configuration
# layers are separated by commas
# tensor ops are separated by spaces
for
config
in
config_file
:
config_layers
=
config
.
strip
().
split
(
'
,
'
)
prev_layer
=
Driver
.
ApproxTypes
.
FP32
curr_layer
=
None
while
not
line
.
startswith
(
"
-----
"
):
layer_info
=
line
.
split
(
'
'
)
layer_data
=
self
.
__tensor_layers
[
layer_ind
]
for
layer_ind
,
config_layer
in
enumerate
(
config_layers
):
# level
layer_data
=
self
.
__tensor_layers
[
layer_ind
]
# layer
layer_name
=
layer_data
[
"
Name
"
]
if
layer_info
[
1
]
==
"
promise
"
:
if
Driver
.
is_promise
(
config_layer
):
print
(
"
Running layer %s on PROMISE
"
%
layer_name
)
curr_layer
=
Driver
.
ApproxTypes
.
PROMISE
swing
=
int
(
layer_info
[
3
])
time
,
energy
=
self
.
__run_promise_simulation
(
swing
,
layer_data
)
print
(
time
,
energy
)
# Compute
time
,
energy
=
self
.
__run_promise_simulation
(
config_layer
,
layer_data
)
self
.
__aggregate_results
[
Driver
.
results_time_key
][
self
.
__config_count
]
+=
time
self
.
__aggregate_results
[
Driver
.
results_energy_key
][
self
.
__config_count
]
+=
energy
elif
layer_info
[
1
]
==
"
gpu
"
:
# Parse each individual
tensor
op
eration
# TODO not portable bc there can be multiple numbers after each approx later on
self
.
__aggregate_results
[
Driver
.
results_energy_key
][
self
.
__config_count
]
+=
energy
else
:
print
(
"
Running layer %s on the GPU
"
%
layer_name
)
tensor
_
op
s
=
config_layer
.
split
(
'
'
)
total_time
=
0
total_energy
=
0
tensor_ind
=
0
for
i
in
range
(
2
,
len
(
layer_info
),
3
):
tensor_op
=
layer_info
[
i
]
approx_type
=
layer_info
[
i
+
1
]
approx_num
=
layer_info
[
i
+
2
]
# only matters if perf
if
approx_type
==
"
fp16
"
:
for
tensor_ind
,
tensor_op
in
enumerate
(
tensor_ops
):
# sublevle
tensor_op
=
int
(
tensor_op
)
if
tensor_op
==
Driver
.
fp16_swing
:
curr_layer
=
Driver
.
ApproxTypes
.
FP16
el
if
approx_type
==
"
fp32
"
:
el
se
:
curr_layer
=
Driver
.
ApproxTypes
.
FP32
elif
approx_type
==
"
perf
"
:
curr_layer
=
DriverApproxTypes
.
PERF
else
:
assert
(
False
)
quant_time
,
quant_energy
=
self
.
__quantize
(
curr_layer
,
prev_layer
,
tensor_ind
,
layer_data
)
time
,
energy
=
self
.
__run_gpu_simulation
(
curr_layer
,
layer_name
,
tensor_ind
,
approx_num
)
total_time
+=
time
total_energy
+=
energy
tensor_ind
+=
1
conv_time
,
conv_energy
=
self
.
__run_gpu_simulation
(
curr_layer
,
layer_name
,
tensor_ind
)
total_time
+=
quant_time
+
conv_time
total_energy
+=
quant_energy
+
conv_energy
prev_layer
=
curr_layer
self
.
__aggregate_results
[
Driver
.
results_time_key
][
self
.
__config_count
]
+=
total_time
self
.
__aggregate_results
[
Driver
.
results_energy_key
][
self
.
__config_count
]
+=
total_energy
layer_ind
+=
1
line
=
config_file
.
readline
().
strip
()
self
.
__aggregate_results
[
Driver
.
results_energy_key
][
self
.
__config_count
]
+=
total_energy
prev_layer
=
curr_layer
self
.
__config_count
+=
1
line
=
config_file
.
readline
().
strip
()
print
(
"
\n
"
)
config_file
.
close
()
def
__run_gpu_simulation
(
self
,
curr_layer
,
layer_name
,
tensor_ind
,
approx_num
):
tensor_info
=
self
.
__tensor_table
[
layer_name
][
tensor_ind
]
if
curr_layer
==
Driver
.
ApproxTypes
.
FP32
:
time
=
tensor_info
[
"
fp32_time
"
]
energy
=
tensor_info
[
"
fp32_energy
"
]
elif
curr_layer
==
Driver
.
ApproxTypes
.
FP16
:
time
=
tensor_info
[
"
fp16_time
"
]
energy
=
tensor_info
[
"
fp16_energy
"
]
elif
curr_layer
==
Driver
.
ApproxTypes
.
PERF
:
time
=
tensor_info
[
"
perf%s_energy
"
%
approx_num
]
energy
=
tensor_info
[
"
perf%s_energy
"
%
approx_num
]
print
(
"
GPU: (%f, %f)
"
%
(
time
,
energy
))
return
time
,
energy
def
__display_results
(
self
):
results_file
=
open
(
self
.
__results_filename
,
"
w
"
)
attributes_to_print
=
[
Driver
.
results_time_key
,
Driver
.
results_energy_key
]
...
...
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