intrin_rule_rocm.cc 2.71 KB
Newer Older
1 2 3 4 5 6 7 8
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
9
 *
10
 *   http://www.apache.org/licenses/LICENSE-2.0
11
 *
12 13 14 15 16 17 18 19
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

20
/*!
21
 * \file intrin_rule_rocm.cc
22 23 24 25 26
 */
#ifdef TVM_LLVM_VERSION

#include <tvm/ir.h>
#include <tvm/expr.h>
27 28 29
#include <tvm/runtime/registry.h>
#include <tvm/packed_func_ext.h>

30 31 32 33 34 35
#include <sstream>

namespace tvm {
namespace codegen {

inline void DispatchExternOCML(const TVMArgs& args, TVMRetValue* rv) {
36
  PrimExpr e = args[0];
37
  using namespace ir;
38
  const CallNode* call = e.as<CallNode>();
39 40
  CHECK(call != nullptr);
  std::ostringstream intrinsic_name;
41
  intrinsic_name << "__ocml_" << call->name << "_f" << call->dtype.bits();
42 43
  *rv = CallNode::make(call->dtype, intrinsic_name.str(), call->args,
                   CallNode::PureExtern);
44 45 46 47
}

namespace llvm {

48
TVM_REGISTER_GLOBAL("tvm.intrin.rule.rocm.floor")
49
.set_body(DispatchExternOCML);
50 51

TVM_REGISTER_GLOBAL("tvm.intrin.rule.rocm.ceil")
52
.set_body(DispatchExternOCML);
53

54
TVM_REGISTER_GLOBAL("tvm.intrin.rule.rocm.round")
55
.set_body(DispatchExternOCML);
56 57

TVM_REGISTER_GLOBAL("tvm.intrin.rule.rocm.trunc")
58
.set_body(DispatchExternOCML);
59

60
TVM_REGISTER_GLOBAL("tvm.intrin.rule.rocm.fabs")
61
.set_body(DispatchExternOCML);
62

63 64 65
TVM_REGISTER_GLOBAL("tvm.intrin.rule.rocm.exp")
.set_body(DispatchExternOCML);

66 67 68
TVM_REGISTER_GLOBAL("tvm.intrin.rule.rocm.erf")
.set_body(DispatchExternOCML);

69
TVM_REGISTER_GLOBAL("tvm.intrin.rule.rocm.fma")
70
.set_body(DispatchExternOCML);
71 72 73 74 75 76 77 78 79 80

TVM_REGISTER_GLOBAL("tvm.intrin.rule.rocm.log")
.set_body(DispatchExternOCML);

TVM_REGISTER_GLOBAL("tvm.intrin.rule.rocm.sqrt")
.set_body(DispatchExternOCML);

TVM_REGISTER_GLOBAL("tvm.intrin.rule.rocm.pow")
.set_body(DispatchExternOCML);

masahi committed
81 82
TVM_REGISTER_GLOBAL("tvm.intrin.rule.rocm.tanh")
.set_body(DispatchExternOCML);
83 84 85 86 87 88 89 90 91 92

TVM_REGISTER_GLOBAL("tvm.intrin.rule.rocm.cos")
.set_body(DispatchExternOCML);

TVM_REGISTER_GLOBAL("tvm.intrin.rule.rocm.sin")
.set_body(DispatchExternOCML);

TVM_REGISTER_GLOBAL("tvm.intrin.rule.rocm.atan")
.set_body(DispatchExternOCML);

93 94 95 96 97
}  // namespace llvm
}  // namespace codegen
}  // namespace tvm

#endif  // LLVM_VERSION