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
ff6b8d82
Commit
ff6b8d82
authored
8 years ago
by
tqchen
Browse files
Options
Downloads
Patches
Plain Diff
check substitute
parent
363cc280
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/tvm/ir_mutator.h
+8
-0
8 additions, 0 deletions
include/tvm/ir_mutator.h
src/pass/ir_mutator.cc
+26
-0
26 additions, 0 deletions
src/pass/ir_mutator.cc
tests/cpp/ir_mutator_test.cc
+19
-0
19 additions, 0 deletions
tests/cpp/ir_mutator_test.cc
with
53 additions
and
0 deletions
include/tvm/ir_mutator.h
+
8
−
0
View file @
ff6b8d82
...
...
@@ -7,6 +7,7 @@
#define TVM_IR_MUTATOR_H_
#include
<tvm/ir_node.h>
#include
<unordered_map>
#include
"./expr.h"
namespace
tvm
{
...
...
@@ -72,6 +73,13 @@ class IRMutatorExample : public IRMutator {
static
FMutateStmt
&
vtable_stmt
();
// NOLINT(*)
};
/*!
* \brief Substitute occurance of IRNode to be expr
* \param replacements The replacement rule of substitution
* \param expr The expression to be substituted.
*/
Expr
Substitute
(
const
std
::
unordered_map
<
const
IRNode
*
,
Expr
>&
replacements
,
Expr
expr
);
}
// namespace ir
}
// namespace tvm
#endif // TVM_IR_MUTATOR_H_
This diff is collapsed.
Click to expand it.
src/pass/ir_mutator.cc
+
26
−
0
View file @
ff6b8d82
...
...
@@ -8,6 +8,32 @@
namespace
tvm
{
namespace
ir
{
namespace
{
// visitor to implement apply
class
IRSubstitute
:
public
IRMutator
{
public:
Expr
mutate
(
Expr
expr
)
final
{
const
IRNode
*
v
=
expr
.
get
();
if
(
v
!=
nullptr
)
{
auto
it
=
replacements_
.
find
(
v
);
if
(
it
!=
replacements_
.
end
())
{
return
it
->
second
;
}
}
return
IRMutator
::
mutate
(
expr
);
}
explicit
IRSubstitute
(
const
std
::
unordered_map
<
const
IRNode
*
,
Expr
>&
replacements
)
:
replacements_
(
replacements
)
{}
private
:
const
std
::
unordered_map
<
const
IRNode
*
,
Expr
>&
replacements_
;
};
}
// namespace
Expr
Substitute
(
const
std
::
unordered_map
<
const
IRNode
*
,
Expr
>&
replacements
,
Expr
expr
)
{
return
IRSubstitute
(
replacements
).
mutate
(
expr
);
}
IRMutator
::
FMutateExpr
&
IRMutator
::
vtable_expr
()
{
// NOLINT(*)
static
FMutateExpr
inst
;
return
inst
;
}
...
...
This diff is collapsed.
Click to expand it.
tests/cpp/ir_mutator_test.cc
+
19
−
0
View file @
ff6b8d82
...
...
@@ -52,6 +52,25 @@ TEST(IRMutator, Basic) {
CHECK
(
os
.
str
()
==
"(x + 10)"
);
}
TEST
(
IRMutator
,
Substitute
)
{
using
namespace
Halide
::
Internal
;
using
namespace
tvm
;
Var
x
(
"x"
),
y
;
auto
z
=
x
+
y
;
{
auto
zz
=
Substitute
({{
y
.
get
(),
11
}},
z
);
std
::
ostringstream
os
;
os
<<
zz
;
CHECK
(
os
.
str
()
==
"(x + 11)"
);
}
{
auto
zz
=
Substitute
({{
z
.
get
(),
11
}},
z
);
std
::
ostringstream
os
;
os
<<
zz
;
CHECK
(
os
.
str
()
==
"11"
);
}
}
int
main
(
int
argc
,
char
**
argv
)
{
testing
::
InitGoogleTest
(
&
argc
,
argv
);
testing
::
FLAGS_gtest_death_test_style
=
"threadsafe"
;
...
...
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