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
f73c461f
Commit
f73c461f
authored
7 years ago
by
Tianqi Chen
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
[BACKEND] Explicitly allow specialization of FMA in llvm (#407)
parent
a45d3b01
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/codegen/llvm/intrin_rule_llvm.cc
+3
-0
3 additions, 0 deletions
src/codegen/llvm/intrin_rule_llvm.cc
src/pass/lower_intrin.cc
+22
-4
22 additions, 4 deletions
src/pass/lower_intrin.cc
with
25 additions
and
4 deletions
src/codegen/llvm/intrin_rule_llvm.cc
+
3
−
0
View file @
f73c461f
...
...
@@ -67,6 +67,9 @@ inline void DispatchLLVMIntrin(const TVMArgs& targs, TVMRetValue* rv) {
TVM_REGISTER_GLOBAL
(
"tvm.intrin.rule.llvm.exp"
)
.
set_body
(
DispatchLLVMPureIntrin
<::
llvm
::
Intrinsic
::
exp
>
);
TVM_REGISTER_GLOBAL
(
"tvm.intrin.rule.llvm.fma"
)
.
set_body
(
DispatchLLVMPureIntrin
<::
llvm
::
Intrinsic
::
fmuladd
>
);
TVM_REGISTER_GLOBAL
(
"tvm.intrin.rule.llvm.log"
)
.
set_body
(
DispatchLLVMPureIntrin
<::
llvm
::
Intrinsic
::
log
>
);
...
...
This diff is collapsed.
Click to expand it.
src/pass/lower_intrin.cc
+
22
−
4
View file @
f73c461f
...
...
@@ -16,11 +16,12 @@ namespace ir {
class
IntrinInjecter
:
public
IRMutator
{
public:
explicit
IntrinInjecter
(
std
::
string
target
)
{
patterns_
.
push_back
(
"tvm.intrin.rule."
+
target
+
"."
);
if
(
!
strncmp
(
target
.
c_str
(),
"llvm"
,
4
)
&&
target
!=
"llvm"
)
{
patterns_
.
push_back
(
"tvm.intrin.rule.llvm."
)
;
}
std
::
istringstream
is
(
target
);
std
::
string
starget
;
is
>>
starget
;
patterns_
.
push_back
(
"tvm.intrin.rule."
+
starget
+
"."
);
patterns_
.
push_back
(
"tvm.intrin.rule.default."
);
fma_
=
runtime
::
Registry
::
Get
(
patterns_
[
0
]
+
"fma"
);
}
Expr
Mutate_
(
const
Call
*
op
,
const
Expr
&
e
)
final
{
...
...
@@ -32,6 +33,22 @@ class IntrinInjecter : public IRMutator {
return
IRMutator
::
Mutate_
(
op
,
e
);
}
Expr
Mutate_
(
const
Add
*
op
,
const
Expr
&
e
)
final
{
if
(
fma_
==
nullptr
||
!
op
->
type
.
is_float
())
{
return
IRMutator
::
Mutate_
(
op
,
e
);
}
if
(
const
Mul
*
mb
=
op
->
b
.
as
<
Mul
>
())
{
Expr
r
=
(
*
fma_
)(
Call
::
make
(
op
->
type
,
"fma"
,
{
mb
->
a
,
mb
->
b
,
op
->
a
},
Call
::
PureIntrinsic
));
if
(
r
.
defined
())
return
r
;
}
else
if
(
const
Mul
*
ma
=
op
->
a
.
as
<
Mul
>
())
{
Expr
r
=
(
*
fma_
)(
Call
::
make
(
op
->
type
,
"fma"
,
{
ma
->
a
,
ma
->
b
,
op
->
b
},
Call
::
PureIntrinsic
));
if
(
r
.
defined
())
return
r
;
}
return
IRMutator
::
Mutate_
(
op
,
e
);
}
private
:
Expr
ApplyPattern
(
const
std
::
string
&
name
,
const
Expr
&
e
)
{
for
(
size_t
i
=
0
;
i
<
patterns_
.
size
();
++
i
)
{
...
...
@@ -54,6 +71,7 @@ class IntrinInjecter : public IRMutator {
}
// patterns
std
::
vector
<
std
::
string
>
patterns_
;
const
PackedFunc
*
fma_
{
nullptr
};
};
LoweredFunc
...
...
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