Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tvm
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
Service Desk
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cld
ml
tvm
Commits
abccd9cd
Commit
abccd9cd
authored
7 years ago
by
Tianqi Chen
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
[TOPI] Improve dilate (#330)
parent
9ac46bea
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
topi/python/topi/nn/dilate.py
+13
-6
13 additions, 6 deletions
topi/python/topi/nn/dilate.py
topi/python/topi/util.py
+25
-3
25 additions, 3 deletions
topi/python/topi/util.py
with
38 additions
and
9 deletions
topi/python/topi/nn/dilate.py
+
13
−
6
View file @
abccd9cd
...
...
@@ -2,6 +2,7 @@
"""
Dilation operators
"""
from
__future__
import
absolute_import
as
_abs
import
tvm
from
..
import
util
@tvm.tag_scope
(
tag
=
"
dilation
"
)
...
...
@@ -29,15 +30,21 @@ def dilate(Input, strides):
output_size
+=
(
tvm
.
ir_pass
.
Simplify
((
Input
.
shape
[
i
]
-
1
)
*
strides
[
i
]
+
1
),)
def
_dilate
(
data
,
*
indices
):
not_zero
=
(
indices
[
0
]
%
strides
[
0
]).
equal
(
0
)
index_tuple
=
()
not_zero
=
[]
index_tuple
=
[]
for
i
in
range
(
n
):
index_tuple
+=
(
indices
[
i
]
/
strides
[
i
],)
not_zero
=
tvm
.
all
(
not_zero
,
(
indices
[
i
]
%
strides
[
i
]).
equal
(
0
))
return
tvm
.
select
(
not_zero
,
data
[
index_tuple
],
tvm
.
const
(
0.0
,
data
.
dtype
))
if
not
util
.
equal_const_int
(
strides
[
i
],
1
):
index_tuple
.
append
(
indices
[
i
]
/
strides
[
i
])
not_zero
.
append
((
indices
[
i
]
%
strides
[
i
]).
equal
(
0
))
else
:
index_tuple
.
append
(
indices
[
i
])
if
not_zero
:
not_zero
=
tvm
.
all
(
*
not_zero
)
return
tvm
.
select
(
not_zero
,
data
(
*
index_tuple
),
tvm
.
const
(
0.0
,
data
.
dtype
))
return
data
(
*
index_tuple
)
Output
=
tvm
.
compute
(
(
output_size
)
,
output_size
,
lambda
*
indices
:
_dilate
(
Input
,
*
indices
),
name
=
'
DilatedInput
'
)
...
...
This diff is collapsed.
Click to expand it.
topi/python/topi/util.py
+
25
−
3
View file @
abccd9cd
...
...
@@ -7,21 +7,43 @@ def get_const_int(expr):
Parameters
----------
expr :
expr :
tvm.Expr
The input expression.
Returns
-------
out_
tuple : tuple of
int
out_
value :
int
The output.
"""
if
not
isinstance
(
expr
,
(
tvm
.
expr
.
IntImm
,
tvm
.
expr
.
UIntImm
)):
expr
=
tvm
.
ir_pass
.
Simplfy
(
expr
)
expr
=
tvm
.
ir_pass
.
Simpl
i
fy
(
expr
)
if
not
isinstance
(
expr
,
(
tvm
.
expr
.
IntImm
,
tvm
.
expr
.
UIntImm
)):
raise
ValueError
(
"
Expect value to be constant int
"
)
return
expr
.
value
def
equal_const_int
(
expr
,
value
):
"""
Returns if expr equals value.
Parameters
----------
expr : tvm.Expr
The input expression.
Returns
-------
equal : bool
Whether they equals.
"""
if
isinstance
(
expr
,
int
):
return
expr
==
value
if
not
isinstance
(
expr
,
(
tvm
.
expr
.
IntImm
,
tvm
.
expr
.
UIntImm
)):
expr
=
tvm
.
ir_pass
.
Simplify
(
expr
)
if
not
isinstance
(
expr
,
(
tvm
.
expr
.
IntImm
,
tvm
.
expr
.
UIntImm
)):
return
False
return
expr
.
value
==
value
def
get_const_tuple
(
in_tuple
):
"""
Verifies input tuple is IntImm, returns tuple of int.
...
...
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