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>
31 #include <tvm/runtime/tensor.h>
32 #include <tvm/tirx/buffer.h>
33 #include <tvm/tirx/expr.h>
34 #include <tvm/tirx/stmt.h>
35 
36 #include <string>
37 
38 namespace tvm {
39 namespace tirx {
40 
49 class PrimFuncNode : public BaseFuncNode {
50  public:
52  ffi::Array<tirx::Var> params;
100  ffi::Map<tirx::Var, Buffer> buffer_map;
103 
104  static void RegisterReflection() {
105  namespace refl = tvm::ffi::reflection;
106  refl::ObjectDef<PrimFuncNode>()
107  .def_ro("params", &PrimFuncNode::params, refl::AttachFieldFlag::SEqHashDef())
108  .def_ro("ret_type", &PrimFuncNode::ret_type)
109  .def_ro("buffer_map", &PrimFuncNode::buffer_map)
110  .def_ro("body", &PrimFuncNode::body);
111  }
112 
121 
124 };
125 
130 class PrimFunc : public BaseFunc {
131  public:
150  TVM_DLL PrimFunc(ffi::Array<tirx::Var> params, Stmt body, Type ret_type = VoidType(),
151  ffi::Map<tirx::Var, Buffer> buffer_map = ffi::Map<tirx::Var, Buffer>(),
152  DictAttrs attrs = DictAttrs(), Span span = Span());
153 
156 };
157 
161 class TensorIntrinNode : public Object {
162  public:
167 
168  static void RegisterReflection() {
169  namespace refl = tvm::ffi::reflection;
170  refl::ObjectDef<TensorIntrinNode>()
171  .def_ro("desc", &TensorIntrinNode::desc)
172  .def_ro("impl", &TensorIntrinNode::impl);
173  }
175 };
176 
180 class TensorIntrin : public ObjectRef {
181  public:
187  TVM_DLL explicit TensorIntrin(PrimFunc desc, PrimFunc impl);
188 
198  TVM_DLL static void Register(ffi::String name, TensorIntrin intrin, bool override = false);
199 
209  TVM_DLL static ffi::Optional<TensorIntrin> Get(ffi::String name, bool allow_missing = false);
210 
212 };
213 
252 PrimFunc Specialize(PrimFunc func, const ffi::Map<Var, ffi::Variant<Buffer, PrimExpr>>& param_map);
253 
259 namespace attr {
260 
307 constexpr const char* kKernelLaunchParams = "tirx.kernel_launch_params";
308 
314 constexpr const char* kNoAlias = "tirx.noalias";
315 
324 constexpr const char* kIsEntryFunc = "tirx.is_entry_func";
325 
331 constexpr const char* kIsGlobalFunc = "tirx.is_global_func";
332 
338 constexpr const char* kIsHostFunc = "tirx.is_host_func";
339 
345 constexpr const char* kIsScheduled = "tirx.is_scheduled";
346 
347 } // namespace attr
348 } // namespace tirx
349 } // namespace tvm
350 #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:233
Managed reference to DictAttrsNode.
Definition: attrs.h:161
Managed reference to FuncTypeNode.
Definition: type.h:273
Definition: source_map.h:111
Managed reference to TypeNode.
Definition: type.h:99
Primitive functions that contains TIR statements.
Definition: function.h:49
ffi::Array< tirx::Var > params
Function parameters.
Definition: function.h:52
ffi::Map< tirx::Var, Buffer > buffer_map
Maps some parameters to specific Buffer data structures.
Definition: function.h:100
static void RegisterReflection()
Definition: function.h:104
FuncType func_type_annotation() const
Return the derived function annotation of this function.
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("tirx.PrimFunc", PrimFuncNode, BaseFuncNode)
tirx::Stmt body
The body of the function.
Definition: function.h:102
Type ret_type
The return type of the function.
Definition: function.h:54
Managed reference to PrimFuncNode.
Definition: function.h:130
PrimFunc(ffi::Array< tirx::Var > params, Stmt body, Type ret_type=VoidType(), ffi::Map< tirx::Var, Buffer > buffer_map=ffi::Map< tirx::Var, Buffer >(), DictAttrs attrs=DictAttrs(), Span span=Span())
Constructor.
TVM_DEFINE_OBJECT_REF_COW_METHOD(PrimFuncNode)
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(PrimFunc, BaseFunc, PrimFuncNode)
Container of all statements.
Definition: stmt.h:65
Tensor intrinsics for tensorization.
Definition: function.h:161
PrimFunc desc
The function to describe the computation.
Definition: function.h:164
PrimFunc impl
The function of the implementation for the execution.
Definition: function.h:166
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("tirx.TensorIntrin", TensorIntrinNode, Object)
static void RegisterReflection()
Definition: function.h:168
Managed reference to TensorIntrinNode.
Definition: function.h:180
static void Register(ffi::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.
static ffi::Optional< TensorIntrin > Get(ffi::String name, bool allow_missing=false)
Look up TensorIntrin by name. Raises an exception if not found.
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(TensorIntrin, ObjectRef, TensorIntrinNode)
a named variable in TIR
Definition: var.h:76
Function nodes.
Definition: repr_printer.h:91
constexpr const char * kIsHostFunc
Mark the function as run on the host, mutually exclusive with kTarget.
Definition: function.h:338
constexpr const char * kIsEntryFunc
Mark the function as the entry function of the final generated runtime module.
Definition: function.h:324
constexpr const char * kIsGlobalFunc
Mark the function as the global function called from the host.
Definition: function.h:331
constexpr const char * kIsScheduled
Mark the function as scheduled, so the default schedule will pass will skip it.
Definition: function.h:345
constexpr const char * kNoAlias
Whether to set noalias rule on the function arguments.
Definition: function.h:314
constexpr const char * kKernelLaunchParams
List of thread IterVar that a DeviceLaunch function corresponds to.
Definition: function.h:307
PrimFunc Specialize(PrimFunc func, const ffi::Map< Var, ffi::Variant< Buffer, PrimExpr >> &param_map)
Specialize parameters of PrimFunc.
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition: analyzer.h:37
Type VoidType()
Definition: type.h:233
A device-independent managed Tensor abstraction.
TIR expressions.
TIR statements.