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
50d7b8b9
Commit
50d7b8b9
authored
5 years ago
by
Elizabeth
Browse files
Options
Downloads
Patches
Plain Diff
Implemented some quantization functionality + changed table to maintain insertion order
parent
c00161ad
No related branches found
Branches containing commit
Tags
2.0.0-alpha09
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
+66
-14
66 additions, 14 deletions
llvm/projects/soc_simulator/src/driver.py
with
66 additions
and
14 deletions
llvm/projects/soc_simulator/src/driver.py
+
66
−
14
View file @
50d7b8b9
...
...
@@ -57,9 +57,10 @@ def parse_tensor_layer_file(layer_filename):
tensor_layers
.
append
(
tensor_layer
)
layer_file
.
close
()
# should this be a nested dict of dicts?
# [layer_name][operation_name][cols]
tensor_table
=
defaultdict
(
build_nested_default_dict
)
# [layer_name][operation_name][cols]
# operation names need to be stored in order of insertion (use a list)
# defaultdict, value = lists of default dicts
tensor_table
=
defaultdict
(
lambda
:
list
(
defaultdict
(
str
)))
def
parse_tensor_table
(
table_filename
):
if
not
os
.
path
.
isfile
(
table_filename
):
...
...
@@ -67,7 +68,6 @@ def parse_tensor_table(table_filename):
exit
(
1
)
table_file
=
open
(
table_filename
,
"
r
"
)
line
=
table_file
.
readline
().
strip
()
print
(
line
)
while
line
:
# Line here MUST be a header or there's a bug
...
...
@@ -79,22 +79,68 @@ def parse_tensor_table(table_filename):
num_ops
=
int
(
header_contents
[
1
])
col_names
=
header_contents
[
2
:]
layer_operations
=
[]
# Go through all operations in the layer
for
op_count
in
range
(
num_ops
):
operation_data
=
defaultdict
(
str
)
line
=
table_file
.
readline
().
strip
()
op_data
=
line
.
split
(
'
'
)
op_name
=
op_data
[
0
]
operation_data
[
"
Name
"
]
=
op_name
# Number of data items (#s) needs to match up with the # of cols
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
)):
tensor_table
[
layer_name
][
op_name
]
[
col_names
[
i
]]
=
op_data
[
i
+
1
]
operation_data
[
col_names
[
i
]]
=
op_data
[
i
+
1
]
layer_operations
.
append
(
operation_data
)
tensor_table
[
layer_name
]
=
layer_operations
line
=
table_file
.
readline
().
strip
()
table_file
.
close
()
fp16_swing
=
8
iterations
=
10
class
ApproxTypes
:
FP16
=
0
FP32
=
1
PROMISE
=
2
def
is_promise
(
config_layer
):
# TODO overhead in call to split?
return
config_layer
.
split
(
'
'
)[
0
]
<
fp16_swing
# NOTE smart_dma is always true
def
quantize
(
curr_layer
,
prev_layer
,
tensor
,
layer_data
):
if
curr_layer
==
prev_layer
or
curr_layer
==
ApproxTypes
.
PROMISE
\
or
prev_layer
==
ApproxTypes
.
PROMISE
:
# No quantization needed
return
(
0.0
,
0.0
)
size
=
None
layer_name
=
layer_data
[
"
Name
"
]
if
is_conv
(
layer_name
):
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
"
]
elif
is_fc
(
layer_name
):
size
=
layer_data
[
"
RA
"
]
*
layer_data
[
"
CA
"
]
+
layer_data
[
"
RB
"
]
*
layer_data
[
"
CB
"
]
elif
not
is_nml
(
layer_name
):
print
(
"
ERROR: Invalid layer name %s
"
%
layer_name
)
exit
(
1
)
# NOTE: Ignoring logic where curr == promise or prev == promise bc
# 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
# we need to get the layer number, the first operation in that layer --> need to change table to store order
# then the h2f and f2h values
def
run_simulations
(
config_filename
,
results_filename
):
config_file
=
open
(
config_filename
,
"
r
"
)
...
...
@@ -106,13 +152,19 @@ def run_simulations(config_filename, results_filename):
for
config
in
config_file
:
config_layers
=
config
.
strip
().
split
(
'
,
'
)
prev
=
"
FP32
"
# TODO??!
curr
=
None
for
layer_ind
,
curr_layer
in
enumerate
(
config_layers
):
# TODO tensor_layers needs to be a list?
curr_tensor_layer
=
tensor_layers
[
layer_ind
]
prev_layer
=
ApproxTypes
.
FP32
curr_layer
=
None
for
layer_ind
,
config_layer
in
enumerate
(
config_layers
):
# level
layer_data
=
tensor_layers
[
layer_ind
]
# layer
if
is_promise
(
config_layer
):
print
(
"
Running layer %s on PROMISE
"
%
layer_data
[
"
Name
"
])
curr_layer
=
ApproxTypes
.
PROMISE
else
:
pass
# for each config file line --> parse the comma separated voltage swing levels
# recall: each line = a configuration that works
# for each level
...
...
@@ -139,4 +191,4 @@ if __name__ == "__main__":
exit(1)
'''
parse_tensor_layer_file
(
"
/home/nvidia/Gitlab/hpvm/llvm/projects/hpvm-tensor-rt/build_mobilenet/mobilenet_layers.txt
"
)
#
parse_tensor_table("/home/nvidia/Gitlab/hpvm/llvm/projects/hpvm-tensor-rt/build_pldi/mobilenet_results/mobilenet_tensors.txt")
parse_tensor_table
(
"
/home/nvidia/Gitlab/hpvm/llvm/projects/hpvm-tensor-rt/build_pldi/mobilenet_results/mobilenet_tensors.txt
"
)
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