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
cb70da1b
Commit
cb70da1b
authored
Dec 09, 2018
by
Wei Chen
Committed by
Tianqi Chen
Dec 09, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve CanonicalSimplify to handle Min, Max(#2248) (#2261)
Also enable Mul caching for more cases
parent
1cb602f1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
5 deletions
+56
-5
src/arithmetic/canonical.cc
+19
-1
tests/cpp/ir_simplify_test.cc
+19
-0
tests/python/unittest/test_arith_simplify.py
+18
-4
No files found.
src/arithmetic/canonical.cc
View file @
cb70da1b
...
...
@@ -236,6 +236,24 @@ class Canonical::Internal : public IRMutator {
bool
EnableOpt
(
Type
t
)
const
{
return
(
t
.
lanes
()
==
1
&&
(
t
.
is_int
()
||
t
.
is_uint
()));
}
// Max
Expr
Mutate_
(
const
Max
*
op
,
const
Expr
&
e
)
final
{
CacheEntry
a
=
Produce
(
op
->
a
);
CacheEntry
b
=
Produce
(
op
->
b
);
if
(
a
.
has_side_effect
||
b
.
has_side_effect
)
{
return
Binary_
(
op
,
e
,
a
.
value
,
b
.
value
);
}
return
Binary
(
op
,
e
);
}
// Min
Expr
Mutate_
(
const
Min
*
op
,
const
Expr
&
e
)
final
{
CacheEntry
a
=
Produce
(
op
->
a
);
CacheEntry
b
=
Produce
(
op
->
b
);
if
(
a
.
has_side_effect
||
b
.
has_side_effect
)
{
return
Binary_
(
op
,
e
,
a
.
value
,
b
.
value
);
}
return
Binary
(
op
,
e
);
}
// Add
Expr
Mutate_
(
const
Add
*
op
,
const
Expr
&
e
)
final
{
if
(
!
EnableOpt
(
op
->
type
))
{
...
...
@@ -277,7 +295,7 @@ class Canonical::Internal : public IRMutator {
}
else
if
(
is_const
(
b
.
value
))
{
return
SumMulConst
(
a
.
AsSum
(),
b
.
value
);
}
else
{
return
Binary
_
(
op
,
e
,
a
.
value
,
b
.
valu
e
);
return
Binary
(
op
,
e
);
}
}
// Variable
...
...
tests/cpp/ir_simplify_test.cc
View file @
cb70da1b
#include <dmlc/logging.h>
#include <gtest/gtest.h>
#include <tvm/ir_pass.h>
#include <tvm/tvm.h>
#include <arithmetic/Simplify.h>
...
...
@@ -8,6 +9,24 @@ TEST(IRSIMPLIFY, Basic) {
simplify_test
();
}
TEST
(
IRSIMPLIFY
,
MinMax
)
{
auto
x
=
tvm
::
var
(
"x"
);
auto
e1
=
(
tvm
::
max
(
x
,
1
)
-
tvm
::
max
(
x
,
1
))
;
auto
e1s
=
tvm
::
ir
::
CanonicalSimplify
(
e1
);
CHECK
(
is_zero
(
e1s
));
auto
e2
=
(
x
*
tvm
::
min
(
x
,
1
))
-
(
x
*
tvm
::
min
(
x
,
1
));
auto
e2s
=
tvm
::
ir
::
CanonicalSimplify
(
e2
);
CHECK
(
is_zero
(
e2s
));
}
TEST
(
IRSIMPLIFY
,
Mul
)
{
auto
x
=
tvm
::
var
(
"x"
);
auto
e
=
(
x
*
x
)
-
(
x
*
x
)
;
auto
es
=
tvm
::
ir
::
CanonicalSimplify
(
e
);
CHECK
(
is_zero
(
es
));
}
int
main
(
int
argc
,
char
**
argv
)
{
testing
::
InitGoogleTest
(
&
argc
,
argv
);
testing
::
FLAGS_gtest_death_test_style
=
"threadsafe"
;
...
...
tests/python/unittest/test_arith_simplify.py
View file @
cb70da1b
...
...
@@ -46,6 +46,21 @@ def test_simplify_mod():
(
j
+
n
*
32
)
%
16
,
{
j
:
tvm
.
Range
(
0
,
6
)})
assert
index
==
j
def
test_simplify_minmax
():
x
=
tvm
.
var
(
'x'
)
e1
=
tvm
.
max
(
x
,
1
)
-
tvm
.
max
(
x
,
1
)
e1s
=
tvm
.
ir_pass
.
CanonicalSimplify
(
e1
)
assert
e1s
.
value
==
0
e2
=
tvm
.
min
(
x
,
1
)
-
tvm
.
min
(
x
,
1
)
e2s
=
tvm
.
ir_pass
.
CanonicalSimplify
(
e2
)
assert
e2s
.
value
==
0
def
test_mul
():
x
=
tvm
.
var
(
'x'
)
e
=
x
*
x
-
x
*
x
es
=
tvm
.
ir_pass
.
CanonicalSimplify
(
e
)
assert
es
.
value
==
0
def
test_modular
():
rx
=
tvm
.
var
(
"rx"
)
...
...
@@ -62,11 +77,9 @@ def test_modular():
assert
tvm
.
ir_pass
.
CanonicalSimplify
(
z1
-
(
ry
+
y
))
.
value
==
0
assert
tvm
.
ir_pass
.
CanonicalSimplify
(
z2
-
(
rx
+
x
))
.
value
==
0
if
__name__
==
"__main__"
:
test_simplify_mod
()
test_modular
()
test_simplify
()
test_mul
()
test_simplify_minmax
()
\ No newline at end of file
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