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
8c507806
Commit
8c507806
authored
5 years ago
by
Elizabeth
Browse files
Options
Downloads
Patches
Plain Diff
Ported quantize method to python
parent
50d7b8b9
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.py
+17
-12
17 additions, 12 deletions
llvm/projects/soc_simulator/src/driver.py
with
17 additions
and
12 deletions
llvm/projects/soc_simulator/src/driver.py
+
17
−
12
View file @
8c507806
...
@@ -58,8 +58,7 @@ def parse_tensor_layer_file(layer_filename):
...
@@ -58,8 +58,7 @@ def parse_tensor_layer_file(layer_filename):
layer_file
.
close
()
layer_file
.
close
()
# [layer_name][operation_name][cols]
# [layer_name][operation_name][cols]
# operation names need to be stored in order of insertion (use a list)
# Operation names need to be stored in order of insertion
# defaultdict, value = lists of default dicts
tensor_table
=
defaultdict
(
lambda
:
list
(
defaultdict
(
str
)))
tensor_table
=
defaultdict
(
lambda
:
list
(
defaultdict
(
str
)))
def
parse_tensor_table
(
table_filename
):
def
parse_tensor_table
(
table_filename
):
...
@@ -116,13 +115,13 @@ def is_promise(config_layer):
...
@@ -116,13 +115,13 @@ def is_promise(config_layer):
return
config_layer
.
split
(
'
'
)[
0
]
<
fp16_swing
return
config_layer
.
split
(
'
'
)[
0
]
<
fp16_swing
# NOTE smart_dma is always true
# NOTE smart_dma is always true
def
quantize
(
curr_layer
,
prev_layer
,
tensor
,
layer_data
):
def
quantize
(
curr_layer
,
prev_layer
,
h2f_f2h_operation_ind
,
layer_data
):
if
curr_layer
==
prev_layer
or
curr_layer
==
ApproxTypes
.
PROMISE
\
if
curr_layer
==
prev_layer
or
curr_layer
==
ApproxTypes
.
PROMISE
\
or
prev_layer
==
ApproxTypes
.
PROMISE
:
# No quantization needed
or
prev_layer
==
ApproxTypes
.
PROMISE
:
# No quantization needed
return
(
0.0
,
0.0
)
return
0.0
,
0.0
size
=
None
layer_name
=
layer_data
[
"
Name
"
]
layer_name
=
layer_data
[
"
Name
"
]
'''
if is_conv(layer_name):
if is_conv(layer_name):
size = layer_data[
"
N
"
] * layer_data[
"
Cin
"
] * layer_data[
"
H
"
] * layer_data[
"
W
"
]
\
size = layer_data[
"
N
"
] * layer_data[
"
Cin
"
] * layer_data[
"
H
"
] * layer_data[
"
W
"
]
\
+ layer_data[
"
Cout
"
] * layer_data[
"
Cin
"
] * layer_data[
"
Kh
"
] * layer_data[
"
Kw
"
]
+ layer_data[
"
Cout
"
] * layer_data[
"
Cin
"
] * layer_data[
"
Kh
"
] * layer_data[
"
Kw
"
]
...
@@ -131,16 +130,20 @@ def quantize(curr_layer, prev_layer, tensor, layer_data):
...
@@ -131,16 +130,20 @@ def quantize(curr_layer, prev_layer, tensor, layer_data):
elif not is_nml(layer_name):
elif not is_nml(layer_name):
print(
"
ERROR: Invalid layer name %s
"
% layer_name)
print(
"
ERROR: Invalid layer name %s
"
% layer_name)
exit(1)
exit(1)
'''
# NOTE: Ignoring logic where curr == promise or prev == promise bc
# NOTE: Ignoring logic where curr == promise or prev == promise bc
# smartDMA is always true so we'd return near the beginning of the method
# smartDMA is always true so we'd return near the beginning of the method
# Converting between fp16 and fp32
#info = tensor_table[layer_name]
# [layer_name][operation_name][cols]
# [layer name][operation number] = list of values
# Get h2f/f2h data using the first tensor operation in the layer
# we need to get the layer number, the first operation in that layer --> need to change table to store order
# (which is why order matters in the tensor table)
# then the h2f and f2h values
tensor_op_row
=
tensor_table
[
layer_name
][
h2f_f2h_operation_ind
]
if
curr_layer
==
ApproxTypes
.
FP32
:
return
tensor_op_row
[
"
h2f_time
"
],
tensor_op_row
[
"
h2f_energy
"
]
elif
curr_layer
==
ApproxTypes
.
FP16
:
return
tensor_op_row
[
"
f2h_time
"
],
tensor_op_row
[
"
f2h_energy
"
]
assert
(
False
)
# Error: Should never reach this section
def
run_simulations
(
config_filename
,
results_filename
):
def
run_simulations
(
config_filename
,
results_filename
):
config_file
=
open
(
config_filename
,
"
r
"
)
config_file
=
open
(
config_filename
,
"
r
"
)
...
@@ -161,7 +164,9 @@ def run_simulations(config_filename, results_filename):
...
@@ -161,7 +164,9 @@ def run_simulations(config_filename, results_filename):
if
is_promise
(
config_layer
):
if
is_promise
(
config_layer
):
print
(
"
Running layer %s on PROMISE
"
%
layer_data
[
"
Name
"
])
print
(
"
Running layer %s on PROMISE
"
%
layer_data
[
"
Name
"
])
curr_layer
=
ApproxTypes
.
PROMISE
curr_layer
=
ApproxTypes
.
PROMISE
quant_time
,
quant_energy
=
quantize
(
curr_layer
,
prev_layer
,
0
,
layer_data
)
# Compute
else
:
else
:
pass
pass
...
...
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