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
e4b40b53
Commit
e4b40b53
authored
Nov 11, 2017
by
Tianqi Chen
Committed by
GitHub
Nov 11, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[PASS] Enhance LiftAttrScope (#632)
* [PASS] Enhance LiftAttrScope * update vt
parent
182a7852
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
97 additions
and
44 deletions
+97
-44
src/pass/inject_virtual_thread.cc
+2
-1
src/pass/lift_attr_scope.cc
+95
-43
No files found.
src/pass/inject_virtual_thread.cc
View file @
e4b40b53
...
@@ -229,7 +229,8 @@ class VTInjector : public IRMutator {
...
@@ -229,7 +229,8 @@ class VTInjector : public IRMutator {
if
(
visit_touched_var_
&&
!
vt_loop_injected_
)
{
if
(
visit_touched_var_
&&
!
vt_loop_injected_
)
{
return
InjectVTLoop
(
s
,
true
);
return
InjectVTLoop
(
s
,
true
);
}
else
if
(
!
allow_share_
&&
!
vt_loop_injected_
&&
}
else
if
(
!
allow_share_
&&
!
vt_loop_injected_
&&
op
->
attr_key
==
attr
::
coproc_uop_scope
)
{
(
op
->
attr_key
==
attr
::
coproc_uop_scope
||
op
->
attr_key
==
attr
::
coproc_scope
))
{
return
InjectVTLoop
(
s
,
true
);
return
InjectVTLoop
(
s
,
true
);
}
else
{
}
else
{
Stmt
body
=
Mutate
(
op
->
body
);
Stmt
body
=
Mutate
(
op
->
body
);
...
...
src/pass/lift_attr_scope.cc
View file @
e4b40b53
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
*/
*/
#include <tvm/ir_pass.h>
#include <tvm/ir_pass.h>
#include <tvm/ir_mutator.h>
#include <tvm/ir_mutator.h>
#include "./ir_util.h"
namespace
tvm
{
namespace
tvm
{
namespace
ir
{
namespace
ir
{
...
@@ -57,41 +58,16 @@ class AttrScopeLifter : public IRMutator {
...
@@ -57,41 +58,16 @@ class AttrScopeLifter : public IRMutator {
}
}
Stmt
Mutate_
(
const
Block
*
op
,
const
Stmt
&
s
)
final
{
Stmt
Mutate_
(
const
Block
*
op
,
const
Stmt
&
s
)
final
{
Stmt
first
=
this
->
Mutate
(
op
->
first
);
std
::
vector
<
Stmt
>
seq
;
NodeRef
first_node_
;
FlattenSeq
(
op
->
first
,
&
seq
);
Expr
first_value_
;
FlattenSeq
(
op
->
rest
,
&
seq
);
std
::
swap
(
first_node_
,
attr_node_
);
seq
=
MutateSeq
(
seq
);
std
::
swap
(
first_value_
,
attr_value_
);
if
(
seq
.
size
()
==
2
&&
Stmt
rest
=
this
->
Mutate
(
op
->
rest
);
seq
[
0
].
same_as
(
op
->
first
)
&&
if
(
attr_node_
.
defined
()
&&
seq
[
1
].
same_as
(
op
->
rest
))
{
attr_value_
.
defined
()
&&
first_node_
.
defined
()
&&
first_value_
.
defined
()
&&
attr_node_
.
same_as
(
first_node_
)
&&
attr_value_
.
same_as
(
first_value_
))
{
if
(
first
.
same_as
(
op
->
first
)
&&
rest
.
same_as
(
op
->
rest
))
{
return
s
;
return
s
;
}
else
{
return
Block
::
make
(
first
,
rest
);
}
}
else
{
if
(
first_node_
.
defined
())
{
first
=
AttrStmt
::
make
(
first_node_
,
attr_key_
,
first_value_
,
first
);
}
if
(
attr_node_
.
defined
())
{
rest
=
AttrStmt
::
make
(
attr_node_
,
attr_key_
,
attr_value_
,
rest
);
// undefine them
attr_node_
=
NodeRef
();
attr_value_
=
Expr
();
}
if
(
first
.
same_as
(
op
->
first
)
&&
rest
.
same_as
(
op
->
rest
))
{
return
s
;
}
else
{
return
Block
::
make
(
first
,
rest
);
}
}
}
return
MergeSeq
(
seq
);
}
}
Stmt
Mutate_
(
const
IfThenElse
*
op
,
const
Stmt
&
s
)
final
{
Stmt
Mutate_
(
const
IfThenElse
*
op
,
const
Stmt
&
s
)
final
{
...
@@ -99,17 +75,17 @@ class AttrScopeLifter : public IRMutator {
...
@@ -99,17 +75,17 @@ class AttrScopeLifter : public IRMutator {
return
IRMutator
::
Mutate_
(
op
,
s
);
return
IRMutator
::
Mutate_
(
op
,
s
);
}
}
Stmt
then_case
=
this
->
Mutate
(
op
->
then_case
);
Stmt
then_case
=
this
->
Mutate
(
op
->
then_case
);
NodeRef
first_node
_
;
NodeRef
first_node
;
Expr
first_value
_
;
Expr
first_value
;
std
::
swap
(
first_node
_
,
attr_node_
);
std
::
swap
(
first_node
,
attr_node_
);
std
::
swap
(
first_value
_
,
attr_value_
);
std
::
swap
(
first_value
,
attr_value_
);
Stmt
else_case
=
this
->
Mutate
(
op
->
else_case
);
Stmt
else_case
=
this
->
Mutate
(
op
->
else_case
);
if
(
attr_node_
.
defined
()
&&
if
(
attr_node_
.
defined
()
&&
attr_value_
.
defined
()
&&
attr_value_
.
defined
()
&&
first_node
_
.
defined
()
&&
first_node
.
defined
()
&&
first_value
_
.
defined
()
&&
first_value
.
defined
()
&&
attr_node_
.
same_as
(
first_node
_
)
&&
attr_node_
.
same_as
(
first_node
)
&&
attr_value_
.
same_as
(
first_value_
))
{
ValueSame
(
attr_value_
,
first_value
))
{
if
(
then_case
.
same_as
(
op
->
then_case
)
&&
if
(
then_case
.
same_as
(
op
->
then_case
)
&&
else_case
.
same_as
(
op
->
else_case
))
{
else_case
.
same_as
(
op
->
else_case
))
{
return
s
;
return
s
;
...
@@ -117,9 +93,9 @@ class AttrScopeLifter : public IRMutator {
...
@@ -117,9 +93,9 @@ class AttrScopeLifter : public IRMutator {
return
IfThenElse
::
make
(
op
->
condition
,
then_case
,
else_case
);
return
IfThenElse
::
make
(
op
->
condition
,
then_case
,
else_case
);
}
}
}
else
{
}
else
{
if
(
first_node
_
.
defined
())
{
if
(
first_node
.
defined
())
{
then_case
=
AttrStmt
::
make
(
then_case
=
AttrStmt
::
make
(
first_node
_
,
attr_key_
,
first_value_
,
then_case
);
first_node
,
attr_key_
,
first_value
,
then_case
);
}
}
if
(
attr_node_
.
defined
())
{
if
(
attr_node_
.
defined
())
{
else_case
=
AttrStmt
::
make
(
else_case
=
AttrStmt
::
make
(
...
@@ -138,6 +114,82 @@ class AttrScopeLifter : public IRMutator {
...
@@ -138,6 +114,82 @@ class AttrScopeLifter : public IRMutator {
}
}
private
:
private
:
void
FlattenSeq
(
Stmt
s
,
std
::
vector
<
Stmt
>*
res
)
{
if
(
const
Block
*
op
=
s
.
as
<
Block
>
())
{
FlattenSeq
(
op
->
first
,
res
);
FlattenSeq
(
op
->
rest
,
res
);
}
else
if
(
const
ProducerConsumer
*
op
=
s
.
as
<
ProducerConsumer
>
())
{
if
(
!
op
->
is_producer
)
{
FlattenSeq
(
op
->
body
,
res
);
}
else
{
res
->
emplace_back
(
s
);
}
}
else
{
res
->
emplace_back
(
s
);
}
}
std
::
vector
<
Stmt
>
MutateSeq
(
const
std
::
vector
<
Stmt
>&
seq
)
{
std
::
vector
<
Stmt
>
res_seq
;
NodeRef
curr_node
;
Expr
curr_value
;
Stmt
curr_stmt
;
for
(
const
Stmt
&
stmt
:
seq
)
{
attr_node_
=
NodeRef
();
attr_value_
=
Expr
();
Stmt
rest
=
this
->
Mutate
(
stmt
);
if
(
attr_node_
.
defined
()
&&
attr_value_
.
defined
()
&&
curr_node
.
defined
()
&&
curr_value
.
defined
()
&&
attr_node_
.
same_as
(
curr_node
)
&&
ValueSame
(
attr_value_
,
curr_value
))
{
curr_stmt
=
Block
::
make
(
curr_stmt
,
rest
);
}
else
{
if
(
curr_stmt
.
defined
())
{
if
(
curr_node
.
defined
())
{
curr_stmt
=
AttrStmt
::
make
(
curr_node
,
attr_key_
,
curr_value
,
curr_stmt
);
}
res_seq
.
push_back
(
curr_stmt
);
}
curr_stmt
=
rest
;
curr_node
=
attr_node_
;
curr_value
=
attr_value_
;
}
}
if
(
curr_stmt
.
defined
())
{
// keep attr_node_, attr_node_
if
(
res_seq
.
size
()
==
0
)
{
return
{
curr_stmt
};
}
if
(
curr_node
.
defined
())
{
curr_stmt
=
AttrStmt
::
make
(
curr_node
,
attr_key_
,
curr_value
,
curr_stmt
);
}
res_seq
.
push_back
(
curr_stmt
);
// reset
attr_node_
=
NodeRef
();
attr_value_
=
Expr
();
}
return
res_seq
;
}
// value comparison that also compares content of int constant
static
bool
ValueSame
(
const
Expr
&
a
,
const
Expr
&
b
)
{
if
(
a
.
same_as
(
b
))
return
true
;
if
(
a
->
type_key
()
!=
b
->
type_key
())
return
false
;
if
(
a
.
type
()
!=
b
.
type
())
return
false
;
if
(
const
IntImm
*
op
=
a
.
as
<
IntImm
>
())
{
return
op
->
value
==
b
.
as
<
IntImm
>
()
->
value
;
}
if
(
const
UIntImm
*
op
=
a
.
as
<
UIntImm
>
())
{
return
op
->
value
==
b
.
as
<
UIntImm
>
()
->
value
;
}
return
false
;
}
std
::
string
attr_key_
;
std
::
string
attr_key_
;
NodeRef
attr_node_
;
NodeRef
attr_node_
;
Expr
attr_value_
;
Expr
attr_value_
;
...
...
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