tvm
Loading...
Searching...
No Matches
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/ffi/container/array.h>
28#include <tvm/ffi/container/map.h>
29#include <tvm/ffi/string.h>
30#include <tvm/ir/attrs.h>
31#include <tvm/ir/expr.h>
32
33#include <string>
34#include <type_traits>
35
36namespace tvm {
37
44enum class CallingConv : int {
51 kDefault = 0,
58 kCPackedFunc = 1,
66};
67
71enum class LinkageType : int {
75 kInternal = 0,
80 kExternal = 1
81};
82
92class BaseFuncNode : public ExprNode {
93 public:
96
116 template <typename TObjectRef>
117 ffi::Optional<TObjectRef> GetAttr(const std::string& attr_key,
118 ffi::Optional<TObjectRef> default_value = std::nullopt) const {
119 return attrs.GetAttr(attr_key, default_value);
120 }
121 // variant that uses TObjectRef to enable implicit conversion to default value.
122 template <typename TObjectRef>
123 ffi::Optional<TObjectRef> GetAttr(const std::string& attr_key, TObjectRef default_value) const {
124 return GetAttr<TObjectRef>(attr_key, ffi::Optional<TObjectRef>(default_value));
125 }
126
146 bool HasNonzeroAttr(const std::string& attr_key) const { return attrs.HasNonzeroAttr(attr_key); }
167
168 static void RegisterReflection() {
169 namespace refl = tvm::ffi::reflection;
170 refl::ObjectDef<BaseFuncNode>().def_ro("attrs", &BaseFuncNode::attrs);
171 }
172
173 static constexpr const uint32_t _type_child_slots = 2;
175};
176
181class BaseFunc : public Expr {
182 public:
183 explicit BaseFunc(ffi::ObjectPtr<BaseFuncNode> node) : Expr(std::move(node)) {}
184
186};
187
193namespace attr {
201constexpr const char* kCallingConv = "calling_conv";
202
210constexpr const char* kTarget = "target";
211
231constexpr const char* kGlobalSymbol = "global_symbol";
232
241constexpr const char* kSTir = "s_tir";
242
250constexpr const char* kScriptNamespace = "script.namespace";
251
257constexpr const char* kNumInputs = "num_inputs";
258
259} // namespace attr
260
267
268} // namespace tvm
269#endif // TVM_IR_FUNCTION_H_
Helpers for attribute objects.
Base node of all functions.
Definition function.h:92
static constexpr const uint32_t _type_child_slots
Definition function.h:173
bool HasNonzeroAttr(const std::string &attr_key) const
Check whether the function has an non-zero integer attr.
Definition function.h:146
LinkageType GetLinkageType() const
Get the type of the linkage.
Definition function.h:261
ffi::Optional< TObjectRef > GetAttr(const std::string &attr_key, TObjectRef default_value) const
Definition function.h:123
DictAttrs attrs
Additional attributes storing the meta-data.
Definition function.h:95
ffi::Optional< TObjectRef > GetAttr(const std::string &attr_key, ffi::Optional< TObjectRef > default_value=std::nullopt) const
Get a function attribute.
Definition function.h:117
static void RegisterReflection()
Definition function.h:168
TVM_FFI_DECLARE_OBJECT_INFO("ir.BaseFunc", BaseFuncNode, ExprNode)
Managed reference to BaseFuncNode.
Definition function.h:181
BaseFunc(ffi::ObjectPtr< BaseFuncNode > node)
Definition function.h:183
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(BaseFunc, Expr, BaseFuncNode)
Managed reference to DictAttrsNode.
Definition attrs.h:108
ffi::Optional< TObjectRef > GetAttr(const std::string &attr_key, ffi::Optional< TObjectRef > default_value=ffi::Optional< TObjectRef >(std::nullopt)) const
Get a function attribute.
Definition attrs.h:171
bool HasNonzeroAttr(const std::string &attr_key) const
Check whether the function has an non-zero integer attr.
Definition attrs.h:206
Base type of all the expressions.
Definition base_expr.h:324
Managed reference to ExprNode.
Definition base_expr.h:359
Base expr nodes in TVM.
constexpr const char * kScriptNamespace
Script construction namespace used to select the function decorator. Absent metadata selects the func...
Definition function.h:250
constexpr const char * kCallingConv
Indicates the special calling convention.
Definition function.h:201
constexpr const char * kSTir
The function uses s_tir (apache-derived TIR) semantics: parser fills layout=None, ScriptComplete wrap...
Definition function.h:241
constexpr const char * kNumInputs
Number of inputs of the Function.
Definition function.h:257
constexpr const char * kTarget
Compilation target of the function.
Definition function.h:210
constexpr const char * kGlobalSymbol
Global linker symbol of the function in generated code.
Definition function.h:231
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition attr.h:23
CallingConv
Possible Calling conventions.
Definition function.h:44
@ kDefault
Default calling convention.
@ kCPackedFunc
ffi::Function that exposes a Cffi::Function signature.
@ kDeviceKernelLaunch
Device kernel launch.
LinkageType
Supported linkage types.
Definition function.h:71
@ kExternal
External linkage.
@ kInternal
Internal linkage.