Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tic
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wenyuanbo
tic
Commits
abccd9cd
Commit
abccd9cd
authored
Aug 15, 2017
by
Tianqi Chen
Committed by
GitHub
Aug 15, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[TOPI] Improve dilate (#330)
parent
9ac46bea
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
9 deletions
+38
-9
topi/python/topi/nn/dilate.py
+13
-6
topi/python/topi/util.py
+25
-3
No files found.
topi/python/topi/nn/dilate.py
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'
)
...
...
topi/python/topi/util.py
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.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment