-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ROCM/CodeGen] added initial math functions support to rocm #553
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/*! | ||
* Copyright (c) 2017 by Contributors | ||
* \file intrin_rule_rocm.cc | ||
*/ | ||
#ifdef TVM_LLVM_VERSION | ||
#if TVM_ROCM_RUNTIME | ||
|
||
#include <tvm/ir.h> | ||
#include <tvm/api_registry.h> | ||
#include <tvm/codegen.h> | ||
#include <string> | ||
#include "./llvm_common.h" | ||
|
||
namespace tvm { | ||
namespace codegen { | ||
namespace llvm { | ||
|
||
using namespace ir; | ||
|
||
// num_signature means number of arguments used to query signature | ||
template<unsigned id, int num_signature> | ||
inline void DispatchLLVMPureIntrin(const TVMArgs& targs, TVMRetValue* rv) { | ||
Expr e = targs[0]; | ||
const Call* call = e.as<Call>(); | ||
CHECK(call != nullptr); | ||
Array<Expr> cargs; | ||
// intrin id. | ||
cargs.push_back(UIntImm::make(UInt(32), id)); | ||
cargs.push_back(UIntImm::make(UInt(32), num_signature)); | ||
|
||
for (Expr arg : call->args) { | ||
cargs.push_back(arg); | ||
} | ||
*rv = Call::make( | ||
call->type, "llvm_intrin", cargs, Call::PureIntrinsic); | ||
} | ||
|
||
template<unsigned id, int num_signature> | ||
inline void DispatchLLVMIntrin(const TVMArgs& targs, TVMRetValue* rv) { | ||
Expr e = targs[0]; | ||
const Call* call = e.as<Call>(); | ||
CHECK(call != nullptr); | ||
Array<Expr> cargs; | ||
// intrin id. | ||
cargs.push_back(UIntImm::make(UInt(32), id)); | ||
cargs.push_back(UIntImm::make(UInt(32), num_signature)); | ||
for (Expr arg : call->args) { | ||
cargs.push_back(arg); | ||
} | ||
*rv = Call::make( | ||
call->type, "llvm_intrin", cargs, Call::Intrinsic); | ||
} | ||
|
||
TVM_REGISTER_GLOBAL("tvm.intrin.rule.llvm.rocm.prefetch") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tvm.intrin.rule.rocm.prefetch There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually we can delete this line, as prefetch is only intended for cpu for now |
||
.set_body(DispatchLLVMIntrin<::llvm::Intrinsic::prefetch, 0>); | ||
|
||
TVM_REGISTER_GLOBAL("tvm.intrin.rule.llvm.rocm.exp") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tvm.intrin.rule.rocm.exp There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same changes in the following functions |
||
.set_body(DispatchLLVMPureIntrin<::llvm::Intrinsic::exp, 1>); | ||
|
||
TVM_REGISTER_GLOBAL("tvm.intrin.rule.llvm.rocm.fma") | ||
.set_body(DispatchLLVMPureIntrin<::llvm::Intrinsic::fmuladd, 1>); | ||
|
||
TVM_REGISTER_GLOBAL("tvm.intrin.rule.llvm.rocm.log") | ||
.set_body(DispatchLLVMPureIntrin<::llvm::Intrinsic::log, 1>); | ||
|
||
TVM_REGISTER_GLOBAL("tvm.intrin.rule.llvm.rocm.sqrt") | ||
.set_body(DispatchLLVMPureIntrin<::llvm::Intrinsic::sqrt, 1>); | ||
|
||
TVM_REGISTER_GLOBAL("tvm.intrin.rule.llvm.rocm.pow") | ||
.set_body(DispatchLLVMPureIntrin<::llvm::Intrinsic::pow, 1>); | ||
|
||
} // namespace llvm | ||
} // namespace codegen | ||
} // namespace tvm | ||
|
||
#endif // TVM_ROCM_RUNTIME | ||
|
||
#endif // LLVM_VERSION |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
create a new file intrin_rule_llvm.h and move the two template functions into there so it is shared with intrin_rule_llvm.cc