tvm
Loading...
Searching...
No Matches
context.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 */
20#ifndef TVM_TIRX_TILE_CONTEXT_H_
21#define TVM_TIRX_TILE_CONTEXT_H_
22
23#include <tvm/target/target.h>
24#include <tvm/tirx/stmt.h>
26
27namespace tvm {
28namespace tirx {
29namespace tile {
30
31namespace callback {
33constexpr const char* kPrivateAlloc = "private_alloc";
37constexpr const char* kDeviceInitStmt = "device_init_stmt";
41constexpr const char* kHostInitStmt = "host_init_stmt";
45constexpr const char* kPostTensorDefStmt = "post_tensor_def_stmt";
46} // namespace callback
47
51class DispatchContextObj : public ffi::Object {
52 public:
55 explicit DispatchContextObj(ffi::UnsafeInit)
56 : target(ffi::UnsafeInit{}), exec_scope(ffi::UnsafeInit{}) {}
57
63 ffi::Map<ffi::String, ffi::Tuple<PrimVar, PrimExpr>> launch_params;
65 ffi::Map<Var, Range> var_range_map;
69 ffi::Map<ffi::String, ffi::ObjectRef> callbacks;
71 ffi::Map<ffi::String, ffi::ObjectRef> shared_state;
81 ffi::Map<ffi::String, ffi::Array<PrimExpr>> inter;
83 ffi::Map<ffi::String, ffi::Array<PrimExpr>> intra;
85 ffi::String scope_kind;
86
87 static void RegisterReflection() {
88 namespace refl = tvm::ffi::reflection;
89 refl::ObjectDef<DispatchContextObj>()
90 .def_ro("target", &DispatchContextObj::target)
91 .def_ro("exec_scope", &DispatchContextObj::exec_scope)
92 .def_ro("launch_params", &DispatchContextObj::launch_params)
93 .def_ro("var_range_map", &DispatchContextObj::var_range_map)
94 .def_ro("alloc_only", &DispatchContextObj::alloc_only)
95 .def_ro("callbacks", &DispatchContextObj::callbacks)
96 .def_ro("shared_state", &DispatchContextObj::shared_state)
97 .def_ro("inter", &DispatchContextObj::inter)
98 .def_ro("intra", &DispatchContextObj::intra)
99 .def_ro("scope_kind", &DispatchContextObj::scope_kind);
100 }
101
103 void AddAllocTensor(TensorVar tensor, ffi::Array<PrimExpr> allocated_addr = {},
104 ffi::Map<ffi::String, ffi::Any> annotations = {});
105
107 void AddInitStmt(Stmt stmt, bool host = false);
108
111
113 void SharedStateSet(ffi::String key, ffi::ObjectRef value);
114
116 ffi::Optional<ffi::ObjectRef> SharedStateGet(ffi::String key);
117
118 TVM_FFI_DECLARE_OBJECT_INFO_FINAL("tirx.DispatchContext", DispatchContextObj, ffi::Object);
119};
120
124class DispatchContext : public ffi::ObjectRef {
125 public:
127 Target target, ExecScope exec_scope,
128 ffi::Map<ffi::String, ffi::Tuple<PrimVar, PrimExpr>> launch_params = {},
129 ffi::Map<Var, Range> var_range_map = {}, bool alloc_only = false,
130 ffi::Map<ffi::String, ffi::ObjectRef> callbacks = {},
131 ffi::Map<ffi::String, ffi::ObjectRef> shared_state = {},
132 ffi::Map<ffi::String, ffi::Array<PrimExpr>> inter = {},
133 ffi::Map<ffi::String, ffi::Array<PrimExpr>> intra = {}, ffi::String scope_kind = "");
134
137};
138
139} // namespace tile
140} // namespace tirx
141} // namespace tvm
142
143#endif // TVM_TIRX_TILE_CONTEXT_H_
Container of all statements.
Definition stmt.h:62
Managed reference class to TargetObj.
Definition target.h:136
Definition exec_scope.h:47
Checked zero-state view over an ordinary VarNode with TensorType.
Definition expr.h:50
The context information of the kernel required by op dispatch.
Definition context.h:51
void AddPostTensorDefStmt(TensorVar tensor, Stmt stmt)
Add a statement to be inserted after a tensor's definition.
void AddAllocTensor(TensorVar tensor, ffi::Array< PrimExpr > allocated_addr={}, ffi::Map< ffi::String, ffi::Any > annotations={})
Add a tensor to be allocated in the kernel.
ffi::String scope_kind
Scope kind string ("kernel"/"cta"/"warpgroup"/"warp"/"thread"/"cluster").
Definition context.h:85
DispatchContextObj(Target target, ExecScope exec_scope)
Definition context.h:53
bool alloc_only
Whether the dispatch context is only used for tensor allocation.
Definition context.h:67
void SharedStateSet(ffi::String key, ffi::ObjectRef value)
Set a value in the shared state cache.
ffi::Map< ffi::String, ffi::Array< PrimExpr > > inter
ExecContext inter-team view at this op site.
Definition context.h:81
DispatchContextObj(ffi::UnsafeInit)
Definition context.h:55
ffi::Map< ffi::String, ffi::ObjectRef > callbacks
Callback to be handled when the operator is scheduled.
Definition context.h:69
ffi::Map< Var, Range > var_range_map
A map from loop variables to their ranges.
Definition context.h:65
ffi::Map< ffi::String, ffi::ObjectRef > shared_state
Shared state that persists across dispatch calls within a single lowering pass.
Definition context.h:71
ffi::Map< ffi::String, ffi::Array< PrimExpr > > intra
ExecContext intra-team view. Same encoding as inter.
Definition context.h:83
static void RegisterReflection()
Definition context.h:87
ExecScope exec_scope
The exec scope of the operator.
Definition context.h:61
ffi::Optional< ffi::ObjectRef > SharedStateGet(ffi::String key)
Get a value from the shared state cache.
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("tirx.DispatchContext", DispatchContextObj, ffi::Object)
void AddInitStmt(Stmt stmt, bool host=false)
Add an initialization statement to be inserted.
ffi::Map< ffi::String, ffi::Tuple< PrimVar, PrimExpr > > launch_params
Hardware tag to (index variable, extent) launch parameters.
Definition context.h:63
Target target
The target of the kernel.
Definition context.h:59
Managed reference to DispatchContextObj.
Definition context.h:124
TVM_TIRX_DLL DispatchContext(Target target, ExecScope exec_scope, ffi::Map< ffi::String, ffi::Tuple< PrimVar, PrimExpr > > launch_params={}, ffi::Map< Var, Range > var_range_map={}, bool alloc_only=false, ffi::Map< ffi::String, ffi::ObjectRef > callbacks={}, ffi::Map< ffi::String, ffi::ObjectRef > shared_state={}, ffi::Map< ffi::String, ffi::Array< PrimExpr > > inter={}, ffi::Map< ffi::String, ffi::Array< PrimExpr > > intra={}, ffi::String scope_kind="")
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(DispatchContext, ffi::ObjectRef, DispatchContextObj)
constexpr const char * kPostTensorDefStmt
Statements to be inserted after a specific tensor's definition (DeclTensor/AllocTensor)....
Definition context.h:45
constexpr const char * kDeviceInitStmt
The initialization statement of the operator. which will be inserted at the beginning of the kernel.
Definition context.h:37
constexpr const char * kHostInitStmt
The initialization statement of the operator. which will be inserted at the beginning of the kernel.
Definition context.h:41
constexpr const char * kPrivateAlloc
The allocation Bind statements requested by the operator.
Definition context.h:33
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition attr.h:23
#define TVM_TIRX_DLL
Definition base.h:83
Compilation target object.
TIRx statements and shared statement entry header.