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
1e78d41c
Commit
1e78d41c
authored
Dec 31, 2018
by
Wuwei Lin
Committed by
Tianqi Chen
Dec 30, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Mutate free variables in CommReducer in cache_write (#2354)
parent
8dd928c7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
0 deletions
+48
-0
src/schedule/schedule_dataflow_rewrite.cc
+34
-0
tests/python/unittest/test_schedule_schedule_ops.py
+14
-0
No files found.
src/schedule/schedule_dataflow_rewrite.cc
View file @
1e78d41c
...
...
@@ -35,6 +35,40 @@ class VarReplacer : public ir::IRMutator {
return
e
;
}
ir
::
CommReducer
MutateCommReducer
(
ir
::
CommReducer
combiner
)
{
// Replace free variables in combiner
auto
new_identity
=
ir
::
UpdateArray
(
combiner
->
identity_element
,
[
this
]
(
const
Expr
&
e
)
{
return
this
->
Mutate
(
e
);
});
auto
new_result
=
ir
::
UpdateArray
(
combiner
->
result
,
[
this
]
(
const
Expr
&
e
)
{
return
this
->
Mutate
(
e
);
});
if
(
combiner
->
identity_element
.
same_as
(
new_identity
)
&&
combiner
->
identity_element
.
same_as
(
new_result
))
{
return
combiner
;
}
else
{
return
ir
::
CommReducerNode
::
make
(
combiner
->
lhs
,
combiner
->
rhs
,
new_result
,
new_identity
);
}
}
Expr
Mutate_
(
const
ir
::
Reduce
*
op
,
const
Expr
&
e
)
{
Expr
new_e
=
IRMutator
::
Mutate_
(
op
,
e
);
const
ir
::
Reduce
*
new_reduce
=
new_e
.
as
<
ir
::
Reduce
>
();
ir
::
CommReducer
new_combiner
=
MutateCommReducer
(
op
->
combiner
);
if
(
op
->
combiner
.
same_as
(
new_combiner
))
{
return
new_e
;
}
else
{
return
ir
::
Reduce
::
make
(
new_combiner
,
new_reduce
->
source
,
new_reduce
->
axis
,
new_reduce
->
condition
,
new_reduce
->
value_index
);
}
}
private
:
const
std
::
unordered_map
<
const
Variable
*
,
Expr
>&
vsub_
;
};
...
...
tests/python/unittest/test_schedule_schedule_ops.py
View file @
1e78d41c
...
...
@@ -420,8 +420,22 @@ def test_loop_dep_reduce():
f
=
tvm
.
build
(
s
,
[
X
,
Y
])
def
test_loop_dep_reduce_cache_write
():
X
=
tvm
.
placeholder
(
shape
=
(
10
,),
name
=
"x"
)
def
f
(
n
):
rv
=
tvm
.
reduce_axis
((
0
,
n
))
init
=
lambda
dtype
:
tvm
.
select
(
n
>
1
,
tvm
.
const
(
0
,
dtype
),
n
.
astype
(
dtype
))
sum
=
tvm
.
comm_reducer
(
lambda
x
,
y
:
tvm
.
max
(
x
+
y
,
n
.
astype
(
'float32'
)),
init
,
name
=
'sum'
)
return
sum
(
X
[
rv
],
axis
=
rv
)
Y
=
tvm
.
compute
(
X
.
shape
,
f
,
name
=
"y"
)
s
=
tvm
.
create_schedule
([
Y
.
op
])
s
.
cache_write
(
Y
,
'local'
)
f
=
tvm
.
build
(
s
,
[
X
,
Y
])
if
__name__
==
"__main__"
:
test_loop_dep_reduce
()
test_loop_dep_reduce_cache_write
()
test_schedule_middle_cache
()
test_inline_multi_reduce
()
test_schedule_cache_relayout4
()
...
...
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