tvm
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
function.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 
24 #ifndef TVM_IR_FUNCTION_H_
25 #define TVM_IR_FUNCTION_H_
26 
27 #include <tvm/ir/attrs.h>
28 #include <tvm/ir/expr.h>
32 
33 #include <string>
34 #include <type_traits>
35 
36 namespace tvm {
37 
44 enum class CallingConv : int {
51  kDefault = 0,
58  kCPackedFunc = 1,
66 };
67 
77 class BaseFuncNode : public RelayExprNode {
78  public:
81 
101  template <typename TObjectRef>
103  const std::string& attr_key,
104  Optional<TObjectRef> default_value = Optional<TObjectRef>(nullptr)) const {
105  return attrs.GetAttr(attr_key, default_value);
106  }
107  // variant that uses TObjectRef to enable implicit conversion to default value.
108  template <typename TObjectRef>
109  Optional<TObjectRef> GetAttr(const std::string& attr_key, TObjectRef default_value) const {
110  return GetAttr<TObjectRef>(attr_key, Optional<TObjectRef>(default_value));
111  }
112 
132  bool HasNonzeroAttr(const std::string& attr_key) const { return attrs.HasNonzeroAttr(attr_key); }
133 
134  static constexpr const char* _type_key = "BaseFunc";
135  static constexpr const uint32_t _type_child_slots = 2;
137 };
138 
143 class BaseFunc : public RelayExpr {
144  public:
146 };
147 
153 namespace attr {
161 constexpr const char* kCallingConv = "calling_conv";
162 
170 constexpr const char* kTarget = "target";
171 
191 constexpr const char* kGlobalSymbol = "global_symbol";
192 
193 } // namespace attr
194 } // namespace tvm
195 #endif // TVM_IR_FUNCTION_H_
Runtime Array container types.
Base node of all functions.
Definition: function.h:77
static constexpr const uint32_t _type_child_slots
Definition: function.h:135
bool HasNonzeroAttr(const std::string &attr_key) const
Check whether the function has an non-zero integer attr.
Definition: function.h:132
Optional< TObjectRef > GetAttr(const std::string &attr_key, Optional< TObjectRef > default_value=Optional< TObjectRef >(nullptr)) const
Get a function attribute.
Definition: function.h:102
Optional< TObjectRef > GetAttr(const std::string &attr_key, TObjectRef default_value) const
Definition: function.h:109
DictAttrs attrs
Additional attributes storing the meta-data.
Definition: function.h:80
TVM_DECLARE_BASE_OBJECT_INFO(BaseFuncNode, RelayExprNode)
static constexpr const char * _type_key
Definition: function.h:134
Managed reference to BaseFuncNode.
Definition: function.h:143
TVM_DEFINE_OBJECT_REF_METHODS(BaseFunc, RelayExpr, BaseFuncNode)
Managed reference to DictAttrsNode.
Definition: attrs.h:227
bool HasNonzeroAttr(const std::string &attr_key) const
Check whether the function has an non-zero integer attr.
Definition: attrs.h:297
Optional< TObjectRef > GetAttr(const std::string &attr_key, Optional< TObjectRef > default_value=Optional< TObjectRef >(nullptr)) const
Get a function attribute.
Definition: attrs.h:258
Base node of all non-primitive expressions.
Definition: expr.h:361
Managed reference to RelayExprNode.
Definition: expr.h:433
Optional container that to represent to a Nullable variant of T.
Definition: optional.h:51
Helpers for attribute objects.
Base expr nodes in TVM.
Runtime Map container types.
constexpr const char * kCallingConv
Indicates the special calling convention.
Definition: function.h:161
constexpr const char * kTarget
Compilation target of the function.
Definition: function.h:170
constexpr const char * kGlobalSymbol
Global linker symbol of the function in generated code.
Definition: function.h:191
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
CallingConv
Possible Calling conventions.
Definition: function.h:44
@ kDefault
Default calling convention.
@ kCPackedFunc
PackedFunc that exposes a CPackedFunc signature.
@ kDeviceKernelLaunch
Device kernel launch.
Runtime String container types.