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
f1096cae
Commit
f1096cae
authored
5 years ago
by
Hashim Sharif
Browse files
Options
Downloads
Patches
Plain Diff
DepthwiseConv2D working with HPVM frontend translator
parent
0a3b3254
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
llvm/projects/keras/frontend/approxhpvm_translator.py
+16
-17
16 additions, 17 deletions
llvm/projects/keras/frontend/approxhpvm_translator.py
llvm/projects/keras/frontend/hpvm_dfg_translator.py
+55
-9
55 additions, 9 deletions
llvm/projects/keras/frontend/hpvm_dfg_translator.py
with
71 additions
and
26 deletions
llvm/projects/keras/frontend/approxhpvm_translator.py
+
16
−
17
View file @
f1096cae
...
@@ -336,24 +336,23 @@ class TensorRtTranslator:
...
@@ -336,24 +336,23 @@ class TensorRtTranslator:
return
False
return
False
def
genActivationCall
(
self
,
input_var
,
output_var
,
activation_type
):
#def genActivationCall(self, input_var, output_var, activation_type):
func_name
=
""
# func_name = ""
if
activation_type
==
"
tanh
"
:
# if activation_type == "tanh":
func_name
=
"
Tanh
"
# func_name = "Tanh"
if
activation_type
==
"
relu
"
:
func_name
=
"
Relu
"
if
activation_type
==
"
softmax
"
:
#
if activation_type == "
relu
":
func_name
=
"
Softmax
"
#
func_name = "
Relu
"
i
nst_str
=
"
void*
"
+
output_var
+
"
=
"
#
i
f activation_type
=
=
"
softmax":
inst_str
+=
"
tensor
"
+
func_name
+
"
(
"
+
input_var
+
"
);
\n
"
#
func_name
=
"
Softmax
"
print
(
"
***** inst_str =
"
,
inst_str
,
"
\n
"
)
# inst_str = "void* " + output_var + " = "
# inst_str += "tensor" + func_name + "(" + input_var + "); \n"
# print ("***** inst_str = ", inst_str, "\n")
return
inst_str
#
return inst_str
...
@@ -425,8 +424,8 @@ class TensorRtTranslator:
...
@@ -425,8 +424,8 @@ class TensorRtTranslator:
if
layer_type
==
"
Activation
"
:
if
layer_type
==
"
Activation
"
:
input_var_name
=
self
.
getSingleInputName
(
cur_node
)
input_var_name
=
self
.
getSingleInputName
(
cur_node
)
inst_str
=
self
.
genActivationCall
(
input_var_name
,
out_var_name1
,
cur_node
.
activation_type
)
inst_str
=
genActivationCall
Str
(
input_var_name
,
out_var_name1
,
cur_node
.
activation_type
)
self
.
program_str
+=
inst_str
self
.
program_str
+=
inst_str
...
@@ -434,7 +433,7 @@ class TensorRtTranslator:
...
@@ -434,7 +433,7 @@ class TensorRtTranslator:
activation_type
=
cur_node
.
activation_type
activation_type
=
cur_node
.
activation_type
out_var_name3
=
self
.
getVariableName
(
cur_node
)
out_var_name3
=
self
.
getVariableName
(
cur_node
)
inst_str
=
self
.
genActivationCall
(
out_var_name1
,
out_var_name3
,
activation_type
)
inst_str
=
genActivationCall
Str
(
out_var_name1
,
out_var_name3
,
activation_type
)
self
.
program_str
+=
inst_str
self
.
program_str
+=
inst_str
...
...
This diff is collapsed.
Click to expand it.
llvm/projects/keras/frontend/hpvm_dfg_translator.py
+
55
−
9
View file @
f1096cae
import
sys
import
sys
from
frontend.utils
import
*
class
HPVMTranslator
:
class
HPVMTranslator
:
...
@@ -285,6 +286,50 @@ class HPVMTranslator:
...
@@ -285,6 +286,50 @@ class HPVMTranslator:
self
.
root_str
+=
self
.
genHpvmNodeEdges
(
out_var_name
,
input_var_name
,
weight_name
)
self
.
root_str
+=
self
.
genHpvmNodeEdges
(
out_var_name
,
input_var_name
,
weight_name
)
def
genDepthwiseConvNode
(
self
,
cur_node
):
#input_var_name = self.getSingleInputName(cur_node)
out_var_name
=
self
.
getVariableName
(
cur_node
)
header_str
=
self
.
genNodeHeader
(
out_var_name
,
2
)
inst_str
=
header_str
weights
=
cur_node
.
weights
strides
=
cur_node
.
strides
padding
=
0
if
cur_node
.
padding
.
strip
()
==
"
valid
"
:
padding
=
0
else
:
padding
=
cur_node
.
padding
padding
=
int
((
weights
.
shape
[
0
]
-
1
)
/
2
)
prev_padding
=
self
.
getPrevLayerPadding
(
cur_node
)
if
prev_padding
!=
None
:
# FIXME: currently only supporting symmetric padding
padding
=
prev_padding
[
0
][
0
]
inst_str
+=
"
void *r = __visc__tensor_group_convolution(t1, t2,
"
inst_str
+=
str
(
padding
)
+
"
,
"
inst_str
+=
str
(
padding
)
+
"
,
"
inst_str
+=
str
(
strides
[
0
])
+
"
,
"
inst_str
+=
str
(
strides
[
1
])
+
"
,
"
inst_str
+=
"
1,
"
C
=
weights
.
shape
[
2
]
inst_str
+=
str
(
C
)
+
"
);
\n
"
footer_str
=
self
.
genNodeFooter
(
2
)
inst_str
+=
footer_str
self
.
node_str
+=
inst_str
input_var_name
=
self
.
getSingleInputName
(
cur_node
)
weight_name
=
cur_node
.
layer_name
+
"
_w
"
self
.
root_str
+=
self
.
genHpvmNodeEdges
(
out_var_name
,
input_var_name
,
weight_name
)
def
genBiasNode
(
self
,
cur_node
):
def
genBiasNode
(
self
,
cur_node
):
input_var_name
=
self
.
output_map
[
cur_node
.
layer_name
]
input_var_name
=
self
.
output_map
[
cur_node
.
layer_name
]
...
@@ -384,13 +429,18 @@ class HPVMTranslator:
...
@@ -384,13 +429,18 @@ class HPVMTranslator:
if
layer_type
==
"
Conv2D
"
:
if
layer_type
==
"
Conv2D
"
:
self
.
genConvNode
(
cur_node
)
self
.
genConvNode
(
cur_node
)
if
layer_type
==
"
DepthwiseConv2D
"
:
self
.
genDepthwiseConvNode
(
cur_node
)
if
layer_type
==
"
Dense
"
:
if
layer_type
==
"
Dense
"
:
self
.
genDenseNode
(
cur_node
)
self
.
genDenseNode
(
cur_node
)
if
self
.
hasBiasAdd
(
cur_node
):
if
nodeHasBias
(
cur_node
):
#if self.hasBiasAdd(cur_node):
self
.
genBiasNode
(
cur_node
)
self
.
genBiasNode
(
cur_node
)
if
self
.
hasActivation
(
cur_node
):
if
nodeHasActivation
(
cur_node
)
and
layer_type
!=
"
Activation
"
:
#if self.hasActivation(cur_node):
self
.
genSubActivationNode
(
cur_node
)
self
.
genSubActivationNode
(
cur_node
)
if
layer_type
==
"
Activation
"
:
if
layer_type
==
"
Activation
"
:
...
@@ -536,11 +586,7 @@ class HPVMTranslator:
...
@@ -536,11 +586,7 @@ class HPVMTranslator:
def
generateSourceProgram
(
self
,
dir_prefix
):
def
generateSourceProgram
(
self
,
dir_prefix
):
#print (self.node_str)
#print (self.root_str)
#print (self.root_struct_str)
#print (self.main_func_str)
program_str
=
self
.
file_header_str
+
self
.
node_str
+
self
.
root_str
program_str
=
self
.
file_header_str
+
self
.
node_str
+
self
.
root_str
program_str
+=
self
.
root_struct_str
+
self
.
main_func_str
program_str
+=
self
.
root_struct_str
+
self
.
main_func_str
...
...
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