Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tvm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cld
ml
tvm
Commits
10d9da48
Commit
10d9da48
authored
7 years ago
by
Salem Derisavi
Committed by
Tianqi Chen
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Consider variable range information during simplification of tensorize expressions (#674)
parent
cf81f9f9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/arithmetic/canonical.cc
+2
-0
2 additions, 0 deletions
src/arithmetic/canonical.cc
src/op/tensorize.cc
+15
-7
15 additions, 7 deletions
src/op/tensorize.cc
with
17 additions
and
7 deletions
src/arithmetic/canonical.cc
+
2
−
0
View file @
10d9da48
...
...
@@ -5,6 +5,7 @@
*/
#include
<tvm/ir_mutator.h>
#include
<tvm/arithmetic.h>
#include
<tvm/ir_pass.h>
#include
"./canonical.h"
#include
"./compute_expr.h"
#include
"arithmetic/Simplify.h"
...
...
@@ -612,6 +613,7 @@ void Canonical::SetRange(Var v, Range r, int level) {
}
// namespace arith
namespace
ir
{
Stmt
CanonicalSimplify
(
Stmt
stmt
,
Map
<
Var
,
Range
>
vrange
)
{
return
arith
::
Canonical
(
vrange
).
Simplify
(
stmt
);
}
...
...
This diff is collapsed.
Click to expand it.
src/op/tensorize.cc
+
15
−
7
View file @
10d9da48
...
...
@@ -187,7 +187,8 @@ class TensorIntrinMatcher final : public IRMutator {
const
Stage
&
stage
,
const
std
::
unordered_map
<
IterVar
,
Range
>&
out_dom
,
const
std
::
unordered_map
<
Tensor
,
Array
<
Range
>
>&
in_region
,
const
TensorIntrin
&
intrin
)
{
const
TensorIntrin
&
intrin
,
Map
<
Var
,
Range
>*
compute_intrin_iter_space
)
{
CHECK
(
self
==
stage
->
op
.
get
());
// input remap.
Array
<
Tensor
>
inputs
=
self
->
InputTensors
();
...
...
@@ -232,6 +233,7 @@ class TensorIntrinMatcher final : public IRMutator {
Range
r
=
out_dom
.
at
(
iv
);
var_remap_
[
iv
->
var
.
get
()]
=
target_iv
->
var
+
r
->
min
;
axis_remap_
[
iv
]
=
target_iv
;
compute_intrin_iter_space
->
Set
(
target_iv
->
var
,
target_iv
->
dom
);
}
// Remap reduction axis
CHECK_GE
(
self
->
reduce_axis
.
size
(),
intrin_compute
->
reduce_axis
.
size
())
...
...
@@ -251,6 +253,7 @@ class TensorIntrinMatcher final : public IRMutator {
Range
r
=
out_dom
.
at
(
iv
);
var_remap_
[
iv
->
var
.
get
()]
=
target_iv
->
var
+
r
->
min
;
axis_remap_
[
iv
]
=
target_iv
;
compute_intrin_iter_space
->
Set
(
target_iv
->
var
,
target_iv
->
dom
);
}
}
...
...
@@ -275,9 +278,10 @@ Array<Expr> MatchTensorizeBody(
const
Stage
&
stage
,
const
std
::
unordered_map
<
IterVar
,
Range
>&
out_dom
,
const
std
::
unordered_map
<
Tensor
,
Array
<
Range
>
>&
in_region
,
const
TensorIntrin
&
intrin
)
{
const
TensorIntrin
&
intrin
,
Map
<
Var
,
Range
>*
compute_intrin_iter_space
)
{
TensorIntrinMatcher
matcher
;
matcher
.
Init
(
self
,
stage
,
out_dom
,
in_region
,
intrin
);
matcher
.
Init
(
self
,
stage
,
out_dom
,
in_region
,
intrin
,
compute_intrin_iter_space
);
Array
<
Expr
>
ret
;
for
(
Expr
expr
:
self
->
body
)
{
ret
.
push_back
(
matcher
.
Mutate
(
expr
));
...
...
@@ -291,14 +295,16 @@ void VerifyTensorizeBody(
const
std
::
unordered_map
<
IterVar
,
Range
>&
out_dom
,
const
std
::
unordered_map
<
Tensor
,
Array
<
Range
>
>&
in_region
,
const
TensorIntrin
&
intrin
)
{
Array
<
Expr
>
body
=
MatchTensorizeBody
(
self
,
stage
,
out_dom
,
in_region
,
intrin
);
Map
<
Var
,
Range
>
compute_intrin_iter_space
;
Array
<
Expr
>
body
=
MatchTensorizeBody
(
self
,
stage
,
out_dom
,
in_region
,
intrin
,
&
compute_intrin_iter_space
);
const
ComputeOpNode
*
intrin_compute
=
intrin
->
op
.
as
<
ComputeOpNode
>
();
CHECK
(
intrin_compute
)
<<
"Only support compute intrinsic for now"
;
CHECK_EQ
(
body
.
size
(),
intrin_compute
->
body
.
size
())
<<
"Tensorize failed: body size mismatch"
;
for
(
size_t
i
=
0
;
i
<
body
.
size
();
++
i
)
{
Expr
lhs
=
CanonicalSimplify
(
body
[
i
]);
Expr
rhs
=
CanonicalSimplify
(
intrin_compute
->
body
[
i
]);
Expr
lhs
=
CanonicalSimplify
(
body
[
i
]
,
compute_intrin_iter_space
);
Expr
rhs
=
CanonicalSimplify
(
intrin_compute
->
body
[
i
]
,
compute_intrin_iter_space
);
if
(
lhs
.
type
()
!=
rhs
.
type
())
{
LOG
(
FATAL
)
<<
"Failed to match the data type with TensorIntrin "
...
...
@@ -459,11 +465,13 @@ TVM_REGISTER_API("test.op.MatchTensorizeBody")
Map
<
IterVar
,
Range
>
out_dom
=
args
[
1
];
Map
<
Tensor
,
Array
<
Range
>
>
in_region
=
args
[
2
];
TensorIntrin
intrin
=
args
[
3
];
Map
<
Var
,
Range
>
vrange
;
CHECK
(
stage
->
op
.
as
<
ComputeOpNode
>
());
*
ret
=
MatchTensorizeBody
(
stage
->
op
.
as
<
ComputeOpNode
>
(),
stage
,
as_unordered_map
(
out_dom
),
as_unordered_map
(
in_region
),
intrin
);
intrin
,
&
vrange
);
});
}
// namespace tvm
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment