tvm
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_TIR_FUNCTION_H_
25 #define TVM_TIR_FUNCTION_H_
26 
27 #include <tvm/ffi/container/map.h>
28 #include <tvm/ffi/container/variant.h>
29 #include <tvm/ir/function.h>
30 #include <tvm/runtime/ndarray.h>
31 #include <tvm/tir/buffer.h>
32 #include <tvm/tir/expr.h>
33 #include <tvm/tir/stmt.h>
34 
35 #include <string>
36 
37 namespace tvm {
38 namespace tir {
39 
48 class PrimFuncNode : public BaseFuncNode {
49  public:
51  Array<tir::Var> params;
99  Map<tir::Var, Buffer> buffer_map;
102 
103  static void RegisterReflection() {
104  namespace refl = tvm::ffi::reflection;
105  refl::ObjectDef<PrimFuncNode>()
106  .def_ro("params", &PrimFuncNode::params, refl::AttachFieldFlag::SEqHashDef())
107  .def_ro("ret_type", &PrimFuncNode::ret_type)
108  .def_ro("buffer_map", &PrimFuncNode::buffer_map)
109  .def_ro("body", &PrimFuncNode::body);
110  }
111 
120 
122 
123  static constexpr const char* _type_key = "tir.PrimFunc";
125 };
126 
131 class PrimFunc : public BaseFunc {
132  public:
151  TVM_DLL PrimFunc(Array<tir::Var> params, Stmt body, Type ret_type = VoidType(),
152  Map<tir::Var, Buffer> buffer_map = Map<tir::Var, Buffer>(),
153  DictAttrs attrs = DictAttrs(), Span span = Span());
154 
157 };
158 
162 class TensorIntrinNode : public Object {
163  public:
168 
169  static void RegisterReflection() {
170  namespace refl = tvm::ffi::reflection;
171  refl::ObjectDef<TensorIntrinNode>()
172  .def_ro("desc", &TensorIntrinNode::desc)
173  .def_ro("impl", &TensorIntrinNode::impl);
174  }
175 
176  static constexpr const char* _type_key = "tir.TensorIntrin";
178 };
179 
183 class TensorIntrin : public ObjectRef {
184  public:
190  TVM_DLL explicit TensorIntrin(PrimFunc desc, PrimFunc impl);
191 
201  TVM_DLL static void Register(String name, TensorIntrin intrin, bool override = false);
202 
212  TVM_DLL static Optional<TensorIntrin> Get(String name, bool allow_missing = false);
213 
215 };
216 
255 PrimFunc Specialize(PrimFunc func, const Map<Var, Variant<Buffer, PrimExpr>>& param_map);
256 
262 namespace attr {
263 
310 constexpr const char* kKernelLaunchParams = "tir.kernel_launch_params";
311 
317 constexpr const char* kNoAlias = "tir.noalias";
318 
327 constexpr const char* kIsEntryFunc = "tir.is_entry_func";
328 
334 constexpr const char* kIsGlobalFunc = "tir.is_global_func";
335 
341 constexpr const char* kIsHostFunc = "tir.is_host_func";
342 
348 constexpr const char* kIsScheduled = "tir.is_scheduled";
349 
350 } // namespace attr
351 } // namespace tir
352 } // namespace tvm
353 #endif // TVM_TIR_FUNCTION_H_
Symbolic n-dimensional array, to represent a memory buffer.
Base node of all functions.
Definition: function.h:139
Managed reference to BaseFuncNode.
Definition: function.h:234
Managed reference to DictAttrsNode.
Definition: attrs.h:166
Managed reference to FuncTypeNode.
Definition: type.h:283
Definition: source_map.h:113
Managed reference to TypeNode.
Definition: type.h:101
Primitive functions that contains TIR statements.
Definition: function.h:48
static constexpr const char * _type_key
Definition: function.h:123
Array< tir::Var > params
Function parameters.
Definition: function.h:51
TVM_DECLARE_FINAL_OBJECT_INFO(PrimFuncNode, BaseFuncNode)
FuncType func_type_annotation() const
Return the derived function annotation of this function.
tir::Stmt body
The body of the function.
Definition: function.h:101
Type ret_type
The return type of the function.
Definition: function.h:53
static void RegisterReflection()
Definition: function.h:103
Map< tir::Var, Buffer > buffer_map
Maps some parameters to specific Buffer data structures.
Definition: function.h:99
Managed reference to PrimFuncNode.
Definition: function.h:131
TVM_DEFINE_OBJECT_REF_COW_METHOD(PrimFuncNode)
PrimFunc(Array< tir::Var > params, Stmt body, Type ret_type=VoidType(), Map< tir::Var, Buffer > buffer_map=Map< tir::Var, Buffer >(), DictAttrs attrs=DictAttrs(), Span span=Span())
Constructor.
TVM_DEFINE_OBJECT_REF_METHODS(PrimFunc, BaseFunc, PrimFuncNode)
Container of all statements.
Definition: stmt.h:64
Tensor intrinsics for tensorization.
Definition: function.h:162
TVM_DECLARE_FINAL_OBJECT_INFO(TensorIntrinNode, Object)
static constexpr const char * _type_key
Definition: function.h:176
PrimFunc impl
The function of the implementation for the execution.
Definition: function.h:167
static void RegisterReflection()
Definition: function.h:169
PrimFunc desc
The function to describe the computation.
Definition: function.h:165
Managed reference to TensorIntrinNode.
Definition: function.h:183
TVM_DEFINE_OBJECT_REF_METHODS(TensorIntrin, ObjectRef, TensorIntrinNode)
static Optional< TensorIntrin > Get(String name, bool allow_missing=false)
Look up TensorIntrin by name. Raises an exception if not found.
static void Register(String name, TensorIntrin intrin, bool override=false)
Create and register a TensorIntrin. After registration, the TensorIntrin can be looked up with its na...
TensorIntrin(PrimFunc desc, PrimFunc impl)
Constructor.
a named variable in TIR
Definition: var.h:78
Function nodes.
Definition: repr_printer.h:91
constexpr const char * kIsGlobalFunc
Mark the function as the global function called from the host.
Definition: function.h:334
constexpr const char * kIsEntryFunc
Mark the function as the entry function of the final generated runtime module.
Definition: function.h:327
constexpr const char * kKernelLaunchParams
List of thread IterVar that a DeviceLaunch function corresponds to.
Definition: function.h:310
constexpr const char * kIsHostFunc
Mark the function as run on the host, mutually exclusive with kTarget.
Definition: function.h:341
constexpr const char * kNoAlias
Whether to set noalias rule on the function arguments.
Definition: function.h:317
constexpr const char * kIsScheduled
Mark the function as scheduled, so the default schedule will pass will skip it.
Definition: function.h:348
PrimFunc Specialize(PrimFunc func, const Map< Var, Variant< Buffer, PrimExpr >> &param_map)
Specialize parameters of PrimFunc.
Performance counters for profiling via the PAPI library.
Definition: analyzer.h:37
Type VoidType()
Definition: type.h:241
A device-independent managed NDArray abstraction.
TIR statements.
TIR expressions.