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
2672aad4
Commit
2672aad4
authored
Nov 20, 2019
by
Zhi
Committed by
Haichen Shen
Nov 20, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[fix][pass] Save the function when it is used as a call arg (#4389)
parent
3338af7c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
7 deletions
+29
-7
src/relay/backend/vm/removed_unused_funcs.cc
+12
-7
tests/python/relay/test_pass_remove_unused_functions.py
+17
-0
No files found.
src/relay/backend/vm/removed_unused_funcs.cc
View file @
2672aad4
...
...
@@ -54,12 +54,8 @@ struct CallTracer : ExprVisitor {
called_funcs_
{},
visiting_
{}
{}
void
VisitExpr_
(
const
CallNode
*
call_node
)
final
{
Expr
op
=
call_node
->
op
;
for
(
auto
param
:
call_node
->
args
)
{
VisitExpr
(
param
);
}
if
(
auto
func_node
=
op
.
as
<
FunctionNode
>
())
{
void
CheckExpr
(
const
Expr
&
expr
)
{
if
(
auto
func_node
=
expr
.
as
<
FunctionNode
>
())
{
auto
func
=
GetRef
<
Function
>
(
func_node
);
auto
it
=
visiting_
.
find
(
func
);
if
(
it
!=
visiting_
.
end
())
{
...
...
@@ -67,7 +63,7 @@ struct CallTracer : ExprVisitor {
}
visiting_
.
insert
(
func
);
VisitExpr
(
func
);
}
else
if
(
auto
global
=
op
.
as
<
GlobalVarNode
>
())
{
}
else
if
(
auto
global
=
expr
.
as
<
GlobalVarNode
>
())
{
called_funcs_
.
insert
(
global
->
name_hint
);
auto
func
=
module_
->
Lookup
(
global
->
name_hint
);
auto
it
=
visiting_
.
find
(
func
);
...
...
@@ -76,6 +72,15 @@ struct CallTracer : ExprVisitor {
}
visiting_
.
insert
(
func
);
VisitExpr
(
func
);
}
else
{
VisitExpr
(
expr
);
}
}
void
VisitExpr_
(
const
CallNode
*
call_node
)
final
{
CheckExpr
(
call_node
->
op
);
for
(
auto
param
:
call_node
->
args
)
{
CheckExpr
(
param
);
}
}
...
...
tests/python/relay/test_pass_remove_unused_functions.py
View file @
2672aad4
...
...
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
import
pytest
import
tvm
from
tvm
import
relay
from
tvm.relay
import
transform
...
...
@@ -71,5 +72,21 @@ def test_multiple_entry_functions():
l
=
set
([
x
[
0
]
.
name_hint
for
x
in
mod
.
functions
.
items
()])
assert
l
==
set
([
'tl'
,
'hd'
,
'main2'
,
'id_func'
,
'main1'
])
def
test_globalvar_as_call_arg
():
mod
=
relay
.
Module
()
p
=
Prelude
(
mod
)
tensor_array
=
p
.
get_var
(
'tensor_array'
,
'int32'
)
tensor1
=
p
.
get_var
(
'tensor1'
,
'int32'
)
write
=
p
.
get_var
(
'tensor_array_write'
,
'int32'
)
stack
=
p
.
get_var
(
'tensor_array_stack'
,
'int32'
)
v
=
relay
.
var
(
'v'
)
init_tensor_array
=
tensor_array
(
relay
.
const
(
3
))
tensor_array1
=
write
(
init_tensor_array
,
relay
.
const
(
0
),
tensor1
(
v
))
tensor_array2
=
stack
(
tensor_array1
)
mod
[
"main"
]
=
relay
.
Function
([
v
],
tensor_array2
)
mod
=
relay
.
transform
.
RemoveUnusedFunctions
()(
mod
)
l
=
set
([
x
[
0
]
.
name_hint
for
x
in
mod
.
functions
.
items
()])
assert
'tensor_array_int32'
in
l
if
__name__
==
'__main__'
:
pytest
.
main
()
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