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
0a1f3d41
Commit
0a1f3d41
authored
Nov 26, 2018
by
ziheng
Committed by
Tianqi Chen
Nov 26, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[PASS] PostOrderVisit (#2169)
parent
b5e0d790
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
67 additions
and
13 deletions
+67
-13
include/tvm/relay/attrs/transform.h
+13
-0
include/tvm/relay/expr_functor.h
+8
-0
python/tvm/relay/ir_pass.py
+13
-0
src/relay/ir/expr_functor.cc
+30
-0
src/relay/op/tensor/unary.cc
+3
-13
No files found.
include/tvm/relay/attrs/transform.h
View file @
0a1f3d41
...
...
@@ -151,6 +151,19 @@ struct SliceLikeAttrs : public tvm::AttrsNode<SliceLikeAttrs> {
}
};
// Clip
struct
ClipAttrs
:
public
tvm
::
AttrsNode
<
ClipAttrs
>
{
double
a_min
;
double
a_max
;
TVM_DECLARE_ATTRS
(
ClipAttrs
,
"relay.attrs.ClipAttrs"
)
{
TVM_ATTR_FIELD
(
a_min
)
.
describe
(
"The minimum clip value."
);
TVM_ATTR_FIELD
(
a_max
)
.
describe
(
"The maximum clip value."
);
}
};
}
// namespace relay
}
// namespace tvm
#endif // TVM_RELAY_ATTRS_TRANSFORM_H_
include/tvm/relay/expr_functor.h
View file @
0a1f3d41
...
...
@@ -182,6 +182,14 @@ class ExprMutator
std
::
unordered_map
<
Expr
,
Expr
,
NodeHash
,
NodeEqual
>
memo_
;
};
/*!
* \brief recursively visit the ir in post DFS order node, apply fvisit
* Each node is guaranteed to be visited only once.
* \param node The ir to be visited.
* \param fvisit The visitor function to be applied.
*/
void
PostOrderVisit
(
const
NodeRef
&
node
,
std
::
function
<
void
(
const
NodeRef
&
)
>
fvisit
);
/*
* \brief Bind function parameters or free variables.
*
...
...
python/tvm/relay/ir_pass.py
View file @
0a1f3d41
...
...
@@ -10,6 +10,19 @@ from . import _make
from
.expr
import
Expr
from
.ty
import
Type
def
post_order_visit
(
expr
,
fvisit
):
"""Recursively visit the ir in post DFS order node,
apply fvisit. Each node is guaranteed to be visited
only once.
Parameters
----------
expr : tvm.relay.Expr
The input expression.
fvisit : function
The visitor function to be applied.
"""
return
_ir_pass
.
post_order_visit
(
expr
,
fvisit
)
def
infer_type
(
expr
,
mod
=
None
):
"""Infer the type of expr under the context of mod.
...
...
src/relay/ir/expr_functor.cc
View file @
0a1f3d41
...
...
@@ -228,6 +228,36 @@ void ExprVisitor::VisitExpr_(const TupleGetItemNode* op) {
void
ExprVisitor
::
VisitType
(
const
Type
&
t
)
{
return
;
}
// visitor to implement apply
class
ExprApplyVisit
:
public
ExprVisitor
{
public
:
explicit
ExprApplyVisit
(
std
::
function
<
void
(
const
Expr
&
)
>
f
)
:
f_
(
f
)
{}
void
VisitExpr
(
const
Expr
&
e
)
final
{
if
(
visited_
.
count
(
e
.
get
())
!=
0
)
return
;
visited_
.
insert
(
e
.
get
());
ExprVisitor
::
VisitExpr
(
e
);
f_
(
e
);
}
private
:
std
::
function
<
void
(
const
Expr
&
)
>
f_
;
std
::
unordered_set
<
const
Node
*>
visited_
;
};
void
PostOrderVisit
(
const
Expr
&
e
,
std
::
function
<
void
(
const
Expr
&
)
>
fvisit
)
{
ExprApplyVisit
(
fvisit
).
VisitExpr
(
e
);
}
TVM_REGISTER_API
(
"relay._ir_pass.post_order_visit"
)
.
set_body
([](
TVMArgs
args
,
TVMRetValue
*
ret
)
{
PackedFunc
f
=
args
[
1
];
PostOrderVisit
(
args
[
0
],
[
f
](
const
Expr
&
n
)
{
f
(
n
);
});
});
// Implement bind.
class
ExprBinder
:
public
ExprMutator
{
public
:
...
...
src/relay/op/tensor/unary.cc
View file @
0a1f3d41
...
...
@@ -5,6 +5,7 @@
*/
#include <tvm/relay/expr.h>
#include <tvm/relay/op.h>
#include <tvm/relay/attrs/transform.h>
#include <topi/elemwise.h>
#include "../type_relations.h"
#include "../op_common.h"
...
...
@@ -89,19 +90,8 @@ RELAY_REGISTER_UNARY_OP("relay.op._make.", "copy")
.
add_type_rel
(
"Identity"
,
IdentityRel
)
.
set_attr
<
FTVMCompute
>
(
"FTVMCompute"
,
RELAY_UNARY_COMPUTE
(
topi
::
identity
));
// Clip
struct
ClipAttrs
:
public
tvm
::
AttrsNode
<
ClipAttrs
>
{
double
a_min
;
double
a_max
;
TVM_DECLARE_ATTRS
(
ClipAttrs
,
"relay.attrs.ClipAttrs"
)
{
TVM_ATTR_FIELD
(
a_min
)
.
describe
(
"The minimum clip value."
);
TVM_ATTR_FIELD
(
a_max
)
.
describe
(
"The maximum clip value."
);
}
};
// relay.clip
TVM_REGISTER_NODE_TYPE
(
ClipAttrs
);
TVM_REGISTER_API
(
"relay.op._make.clip"
)
.
set_body_typed
<
Expr
(
Expr
,
double
,
double
)
>
([](
Expr
a
,
double
a_min
,
double
a_max
)
{
...
...
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