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
Branches containing commit
No related tags found
Tags containing commit
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:
...
@@ -10,18 +10,54 @@ class Driver:
FP16
=
0
FP16
=
0
FP32
=
1
FP32
=
1
PROMISE
=
2
PROMISE
=
2
PERF
=
3
results_time_key
=
"
Time
"
results_time_key
=
"
Time
"
results_energy_key
=
"
Energy
"
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
):
def
driver
(
self
):
self
.
__parse_tensor_layer_file
()
#self.__parse_tensor_layer_file()
self
.
__parse_tensor_table
()
#self.__parse_tensor_table()
self
.
__run_simulations
()
#self.__run_simulations()
self
.
__display_results
()
#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
):
def
__init__
(
self
,
layer_filename
,
table_filename
,
config_filename
,
results_filename
):
self
.
__layer_filename
=
layer_filename
self
.
__layer_filename
=
layer_filename
...
@@ -144,6 +180,7 @@ class Driver:
...
@@ -144,6 +180,7 @@ class Driver:
def
__quantize
(
self
,
curr_layer
,
prev_layer
,
h2f_f2h_operation_ind
,
layer_data
):
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
\
if
curr_layer
==
prev_layer
or
curr_layer
==
Driver
.
ApproxTypes
.
PROMISE
\
or
prev_layer
==
Driver
.
ApproxTypes
.
PROMISE
:
# No quantization needed
or
prev_layer
==
Driver
.
ApproxTypes
.
PROMISE
:
# No quantization needed
return
0.0
,
0.0
return
0.0
,
0.0
...
@@ -155,7 +192,6 @@ class Driver:
...
@@ -155,7 +192,6 @@ class Driver:
# Get h2f/f2h data using the first tensor operation in the layer
# Get h2f/f2h data using the first tensor operation in the layer
# (which is why order matters in the tensor table)
# (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
]
tensor_op_row
=
self
.
__tensor_table
[
layer_name
][
h2f_f2h_operation_ind
]
if
curr_layer
==
Driver
.
ApproxTypes
.
FP32
:
if
curr_layer
==
Driver
.
ApproxTypes
.
FP32
:
time
=
tensor_op_row
[
"
h2f_time
"
]
time
=
tensor_op_row
[
"
h2f_time
"
]
...
@@ -189,7 +225,7 @@ class Driver:
...
@@ -189,7 +225,7 @@ class Driver:
exit
(
1
)
exit
(
1
)
# Run promise simulator
# Run promise simulator
# TODO need to print time and energy in the ptm runner so we can pipe it
# 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
)],
\
str
(
cols_b
),
str
(
patch_factor
),
str
(
swing
)],
\
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
).
communicate
()[
0
]
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
).
communicate
()[
0
]
total_time_energy
=
output
.
strip
().
split
(
'
,
'
)
total_time_energy
=
output
.
strip
().
split
(
'
,
'
)
...
@@ -199,100 +235,71 @@ class Driver:
...
@@ -199,100 +235,71 @@ class Driver:
return
float
(
total_time_energy
[
0
]),
float
(
total_time_energy
[
1
])
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
):
def
__run_simulations
(
self
):
if
not
os
.
path
.
isfile
(
self
.
__config_filename
):
if
not
os
.
path
.
isfile
(
self
.
__config_filename
):
print
(
"
ERROR: %s was not found
"
%
self
.
__config_filename
)
print
(
"
ERROR: %s was not found
"
%
self
.
__config_filename
)
exit
(
1
)
exit
(
1
)
config_file
=
open
(
self
.
__config_filename
,
"
r
"
)
config_file
=
open
(
self
.
__config_filename
,
"
r
"
)
line
=
config_file
.
readline
().
strip
()
# each line = indepedent configuration
# layers are separated by commas
while
line
:
# tensor ops are separated by spaces
assert
(
line
.
startswith
(
"
+++++
"
))
for
config
in
config_file
:
config_name
=
config_file
.
readline
().
strip
().
split
(
'
'
)[
0
]
# Next line = configuration name
config_layers
=
config
.
strip
().
split
(
'
,
'
)
print
(
"
CONFIGURATION
"
)
line
=
config_file
.
readline
().
strip
()
layer_ind
=
0
# NOTE can also use the leftmost number in the currl ine
prev_layer
=
Driver
.
ApproxTypes
.
FP32
prev_layer
=
Driver
.
ApproxTypes
.
FP32
curr_layer
=
None
curr_layer
=
None
while
not
line
.
startswith
(
"
-----
"
):
for
layer_ind
,
config_layer
in
enumerate
(
config_layers
):
# level
layer_info
=
line
.
split
(
'
'
)
layer_data
=
self
.
__tensor_layers
[
layer_ind
]
# layer
layer_data
=
self
.
__tensor_layers
[
layer_ind
]
layer_name
=
layer_data
[
"
Name
"
]
layer_name
=
layer_data
[
"
Name
"
]
if
Driver
.
is_promise
(
config_layer
):
if
layer_info
[
1
]
==
"
promise
"
:
print
(
"
Running layer %s on PROMISE
"
%
layer_name
)
print
(
"
Running layer %s on PROMISE
"
%
layer_name
)
curr_layer
=
Driver
.
ApproxTypes
.
PROMISE
curr_layer
=
Driver
.
ApproxTypes
.
PROMISE
# Compute
swing
=
int
(
layer_info
[
3
])
time
,
energy
=
self
.
__run_promise_simulation
(
config_layer
,
layer_data
)
time
,
energy
=
self
.
__run_promise_simulation
(
swing
,
layer_data
)
print
(
time
,
energy
)
self
.
__aggregate_results
[
Driver
.
results_time_key
][
self
.
__config_count
]
+=
time
self
.
__aggregate_results
[
Driver
.
results_time_key
][
self
.
__config_count
]
+=
time
self
.
__aggregate_results
[
Driver
.
results_energy_key
][
self
.
__config_count
]
+=
energy
self
.
__aggregate_results
[
Driver
.
results_energy_key
][
self
.
__config_count
]
+=
energy
else
:
elif
layer_info
[
1
]
==
"
gpu
"
:
print
(
"
Running layer %s on the GPU
"
%
layer_name
)
# Parse each individual
tensor
op
eration
tensor
_
op
s
=
config_layer
.
split
(
'
'
)
# TODO not portable bc there can be multiple numbers after each approx later on
total_time
=
0
total_time
=
0
total_energy
=
0
total_energy
=
0
for
tensor_ind
,
tensor_op
in
enumerate
(
tensor_ops
):
# sublevle
tensor_ind
=
0
tensor_op
=
int
(
tensor_op
)
for
i
in
range
(
2
,
len
(
layer_info
),
3
):
if
tensor_op
==
Driver
.
fp16_swing
:
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
"
:
curr_layer
=
Driver
.
ApproxTypes
.
FP16
curr_layer
=
Driver
.
ApproxTypes
.
FP16
el
if
approx_type
==
"
fp32
"
:
el
se
:
curr_layer
=
Driver
.
ApproxTypes
.
FP32
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
)
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
)
conv_time
,
conv_energy
=
self
.
__run_gpu_simulation
(
curr_layer
,
layer_name
,
tensor_ind
)
total_time
+=
time
total_time
+=
quant_time
+
conv_time
total_energy
+=
energy
total_energy
+=
quant_energy
+
conv_energy
prev_layer
=
curr_layer
tensor_ind
+=
1
self
.
__aggregate_results
[
Driver
.
results_time_key
][
self
.
__config_count
]
+=
total_time
self
.
__aggregate_results
[
Driver
.
results_time_key
][
self
.
__config_count
]
+=
total_time
self
.
__aggregate_results
[
Driver
.
results_energy_key
][
self
.
__config_count
]
+=
total_energy
self
.
__aggregate_results
[
Driver
.
results_energy_key
][
self
.
__config_count
]
+=
total_energy
prev_layer
=
curr_layer
layer_ind
+=
1
line
=
config_file
.
readline
().
strip
()
self
.
__config_count
+=
1
self
.
__config_count
+=
1
line
=
config_file
.
readline
().
strip
()
print
(
"
\n
"
)
config_file
.
close
()
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
):
def
__display_results
(
self
):
results_file
=
open
(
self
.
__results_filename
,
"
w
"
)
results_file
=
open
(
self
.
__results_filename
,
"
w
"
)
attributes_to_print
=
[
Driver
.
results_time_key
,
Driver
.
results_energy_key
]
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