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
b6606ceb
Commit
b6606ceb
authored
4 years ago
by
Yifan Zhao
Browse files
Options
Downloads
Patches
Plain Diff
Added support for GlobalAveragePool
parent
c12a9b26
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
hpvm/projects/onnx_frontend/frontend/graph_builder.py
+5
-1
5 additions, 1 deletion
hpvm/projects/onnx_frontend/frontend/graph_builder.py
hpvm/projects/onnx_frontend/frontend/graph_ir.py
+27
-15
27 additions, 15 deletions
hpvm/projects/onnx_frontend/frontend/graph_ir.py
with
32 additions
and
16 deletions
hpvm/projects/onnx_frontend/frontend/graph_builder.py
+
5
−
1
View file @
b6606ceb
...
@@ -183,7 +183,7 @@ class DFG(object):
...
@@ -183,7 +183,7 @@ class DFG(object):
# Split into conv followed by an addition
# Split into conv followed by an addition
bias_node
=
g
.
BiasAddNode
(
f
"
Bias_
{
node
.
name
.
split
(
'
_
'
)[
-
1
]
}
"
)
bias_node
=
g
.
BiasAddNode
(
f
"
Bias_
{
node
.
name
.
split
(
'
_
'
)[
-
1
]
}
"
)
return
MarkedSubGraph
.
idiomatic_1to2
(
conv_node
,
bias_node
,
predec
)
return
MarkedSubGraph
.
idiomatic_1to2
(
conv_node
,
bias_node
,
predec
)
el
if
node
.
op_type
in
(
"
MatMul
"
,
"
Gemm
"
):
if
node
.
op_type
in
(
"
MatMul
"
,
"
Gemm
"
):
mul_node
=
g
.
MatMulNode
(
node
.
name
,
**
attrs
)
mul_node
=
g
.
MatMulNode
(
node
.
name
,
**
attrs
)
if
node
.
op_type
==
"
Gemm
"
:
if
node
.
op_type
==
"
Gemm
"
:
mul_node
.
gemm_transpose
(
node
,
predec
)
mul_node
.
gemm_transpose
(
node
,
predec
)
...
@@ -192,6 +192,10 @@ class DFG(object):
...
@@ -192,6 +192,10 @@ class DFG(object):
# Split into mul followed by an addition
# Split into mul followed by an addition
bias_node
=
g
.
BiasAddNode
(
f
"
Bias_
{
node
.
name
.
split
(
'
_
'
)[
-
1
]
}
"
)
bias_node
=
g
.
BiasAddNode
(
f
"
Bias_
{
node
.
name
.
split
(
'
_
'
)[
-
1
]
}
"
)
return
MarkedSubGraph
.
idiomatic_1to2
(
mul_node
,
bias_node
,
predec
)
return
MarkedSubGraph
.
idiomatic_1to2
(
mul_node
,
bias_node
,
predec
)
if
node
.
op_type
==
"
GlobalAveragePool
"
:
input0_shape
=
in_graph
.
nodes
[
predec
[
0
]][
"
shape
"
]
_
,
_
,
h
,
w
=
input0_shape
return
g
.
AveragePool2DNode
(
node
.
name
,
[
1
,
1
],
(
h
,
w
),
[
0
,
0
,
0
,
0
])
one_to_one_nodes
=
{
one_to_one_nodes
=
{
"
MaxPool
"
:
g
.
MaxPool2DNode
,
"
MaxPool
"
:
g
.
MaxPool2DNode
,
"
AveragePool
"
:
g
.
AveragePool2DNode
,
"
AveragePool
"
:
g
.
AveragePool2DNode
,
...
...
This diff is collapsed.
Click to expand it.
hpvm/projects/onnx_frontend/frontend/graph_ir.py
+
27
−
15
View file @
b6606ceb
import
abc
import
abc
from
os
import
PathLike
from
os
import
PathLike
from
typing
import
List
,
Tuple
from
typing
import
List
,
Sequence
,
Tuple
import
onnx
import
onnx
...
@@ -102,28 +102,36 @@ class WeightTensor(TensorNode):
...
@@ -102,28 +102,36 @@ class WeightTensor(TensorNode):
class
Conv2DNode
(
DFGNode
):
class
Conv2DNode
(
DFGNode
):
op_type
=
"
Conv2D
"
op_type
=
"
Conv2D
"
def
__init__
(
self
,
name
:
str
,
pads
,
strides
,
dilations
,
group
:
int
,
kernel_shape
):
def
__init__
(
self
,
name
:
str
,
pads
:
Sequence
[
int
],
strides
:
Sequence
[
int
],
dilations
:
Sequence
[
int
],
group
:
int
,
kernel_shape
,
):
super
().
__init__
(
name
)
super
().
__init__
(
name
)
assert
len
(
pads
)
==
4
,
"
2D convolution must have 4 padding values
"
assert
len
(
pads
)
==
4
,
"
2D convolution must have 4 padding values
"
if
any
(
p
!=
pads
[
0
]
for
p
in
pads
[
1
:]):
if
any
(
p
!=
pads
[
0
]
for
p
in
pads
[
1
:]):
raise
ValueError
(
"
Convolution with different padding is unsupported
"
)
raise
ValueError
(
"
Convolution with different padding is unsupported
"
)
if
dilations
!=
[
1
,
1
]:
if
list
(
dilations
)
!=
[
1
,
1
]:
raise
ValueError
(
"
Dilation > 1 is unsupported
"
)
raise
ValueError
(
"
Dilation > 1 is unsupported
"
)
if
group
!=
1
:
if
group
!=
1
:
raise
ValueError
(
"
Group > 1 is unsupported
"
)
raise
ValueError
(
"
Group > 1 is unsupported
"
)
self
.
pads
=
pads
[
0
]
self
.
pads
=
pads
[
0
]
self
.
strides
=
strides
self
.
strides
=
sh
,
sw
=
strides
def
codegen
(
self
):
def
codegen
(
self
):
return
(
return
(
"
tensorConvolution
"
,
"
tensorConvolution
"
,
[
self
.
pads
,
self
.
pads
,
self
.
strides
[
0
],
self
.
strides
[
1
]
],
[
self
.
pads
,
self
.
pads
,
*
self
.
strides
],
)
)
def
hpvm_codegen
(
self
):
def
hpvm_codegen
(
self
):
return
(
return
(
"
__visc__tensor_convolution
"
,
"
__visc__tensor_convolution
"
,
[
self
.
pads
,
self
.
pads
,
self
.
strides
[
0
],
self
.
strides
[
1
]
],
[
self
.
pads
,
self
.
pads
,
*
self
.
strides
],
)
)
...
@@ -132,13 +140,22 @@ class _Pool2DNode(DFGNode, abc.ABC):
...
@@ -132,13 +140,22 @@ class _Pool2DNode(DFGNode, abc.ABC):
pool_type
=
"
0
"
pool_type
=
"
0
"
def
__init__
(
self
,
name
:
str
,
strides
,
kernel_shape
,
pads
,
ceil_mode
:
int
):
def
__init__
(
self
,
name
:
str
,
strides
:
Sequence
[
int
],
kernel_shape
:
Sequence
[
int
],
pads
:
Sequence
[
int
],
ceil_mode
:
int
=
0
,
):
super
().
__init__
(
name
)
super
().
__init__
(
name
)
self
.
strides
=
strides
self
.
strides
=
sh
,
sw
=
strides
self
.
kernel_shape
=
kernel_shape
self
.
kernel_shape
=
kernel_shape
pt
,
pb
,
pl
,
pr
=
pads
pt
,
pb
,
pl
,
pr
=
pads
if
pt
!=
pb
or
pl
!=
pr
:
if
pt
!=
pb
or
pl
!=
pr
:
raise
ValueError
(
"
Unequal padding on either side of same axis is unsupported
"
)
raise
ValueError
(
"
Unequal padding on either side of same axis is unsupported
"
)
self
.
pads
=
pt
,
pl
self
.
pads
=
pt
,
pl
if
ceil_mode
!=
0
:
if
ceil_mode
!=
0
:
raise
ValueError
(
"
Only ceil_mode == 0 is supported
"
)
raise
ValueError
(
"
Only ceil_mode == 0 is supported
"
)
...
@@ -146,12 +163,7 @@ class _Pool2DNode(DFGNode, abc.ABC):
...
@@ -146,12 +163,7 @@ class _Pool2DNode(DFGNode, abc.ABC):
def
codegen
(
self
):
def
codegen
(
self
):
return
(
return
(
"
tensorPooling
"
,
"
tensorPooling
"
,
[
[
self
.
pool_type
,
*
self
.
kernel_shape
,
*
self
.
pads
,
*
self
.
strides
,],
self
.
pool_type
,
*
self
.
kernel_shape
,
*
self
.
pads
,
*
self
.
strides
,
],
)
)
def
hpvm_codegen
(
self
):
def
hpvm_codegen
(
self
):
...
...
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