tvm
postproc.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 
20 #ifndef TVM_META_SCHEDULE_POSTPROC_H_
21 #define TVM_META_SCHEDULE_POSTPROC_H_
22 
23 #include <tvm/node/reflection.h>
24 #include <tvm/runtime/object.h>
27 
28 namespace tvm {
29 namespace meta_schedule {
30 
31 class TuneContext;
32 class Postproc;
33 
37 class PostprocNode : public runtime::Object {
38  public:
40  virtual ~PostprocNode() = default;
41 
43 
49  virtual void InitializeWithTuneContext(const TuneContext& context) = 0;
50 
56  virtual bool Apply(const tir::Schedule& sch) = 0;
57 
62  virtual Postproc Clone() const = 0;
63 
64  static constexpr const char* _type_key = "meta_schedule.Postproc";
66 };
67 
72 class Postproc : public runtime::ObjectRef {
73  public:
103  TVM_DLL static Postproc PyPostproc(FInitializeWithTuneContext f_initialize_with_tune_context, //
104  FApply f_apply, //
105  FClone f_clone, //
106  FAsString f_as_string);
111  TVM_DLL static Postproc DisallowDynamicLoop();
117  TVM_DLL static Postproc RewriteCooperativeFetch();
123  TVM_DLL static Postproc RewriteParallelVectorizeUnroll();
128  TVM_DLL static Postproc RewriteReductionBlock();
134  TVM_DLL static Postproc RewriteUnboundBlock(int max_threadblocks);
141  TVM_DLL static Postproc RewriteTensorize(bool vectorize_init_loop = false);
146  TVM_DLL static Postproc VerifyGPUCode();
151  TVM_DLL static Postproc VerifyVTCMLimit();
157  TVM_DLL static Postproc RewriteLayout();
159  TVM_DLL static Array<Postproc, void> DefaultLLVM();
161  TVM_DLL static Array<Postproc, void> DefaultVNNI();
163  TVM_DLL static Array<Postproc, void> DefaultCUDA();
165  TVM_DLL static Array<Postproc, void> DefaultCUDATensorCore();
167  TVM_DLL static Array<Postproc, void> DefaultHexagon();
168 
170 };
171 
173 class PyPostprocNode : public PostprocNode {
174  public:
187 
189  // `f_initialize_with_tune_context` is not visited
190  // `f_apply` is not visited
191  // `f_clone` is not visited
192  // `f_as_string` is not visited
193  }
194 
195  void InitializeWithTuneContext(const TuneContext& context) final;
196  bool Apply(const tir::Schedule& sch) final;
197  Postproc Clone() const final;
198 
199  static constexpr const char* _type_key = "meta_schedule.PyPostproc";
201 };
202 
203 } // namespace meta_schedule
204 } // namespace tvm
205 
206 #endif // TVM_META_SCHEDULE_POSTPROC_H_
The postprocessor with customized methods on the python-side.
Definition: postproc.h:173
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
runtime::TypedPackedFunc< void(const TuneContext &)> FInitializeWithTuneContext
The function type of InitializeWithTuneContext method.
Definition: postproc.h:78
Managed reference to PostprocNode.
Definition: postproc.h:72
FInitializeWithTuneContext f_initialize_with_tune_context
The packed function to the InitializeWithTuneContext function.
Definition: postproc.h:180
runtime::TypedPackedFunc< Postproc()> FClone
Clone the postprocessor.
Definition: postproc.h:89
base class of all object containers.
Definition: object.h:167
FApply f_apply
The packed function to the Apply function.
Definition: postproc.h:182
#define TVM_DEFINE_MUTABLE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName)
Definition: object.h:744
Managed reference to ScheduleNode.
Definition: schedule.h:736
Managed reference to TuneContextNode.
Definition: tune_context.h:95
Visitor class to get the attributes of an AST/IR node. The content is going to be called for each fie...
Definition: reflection.h:52
runtime::TypedPackedFunc< String()> FAsString
Get the postprocessor function as string with name.
Definition: postproc.h:94
static constexpr const char * _type_key
Definition: postproc.h:64
bool VerifyGPUCode(const PrimFunc &func, Map< String, PrimExpr > constraints)
Verify the correctness of a GPU code It will check the whether the amount of memory usage or the numb...
Rules to apply a postprocessor to a schedule.
Definition: postproc.h:37
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
Please refer to TypedPackedFunc<R(Args..)>.
Definition: packed_func.h:60
Base class of all object reference.
Definition: object.h:511
TVM_DECLARE_BASE_OBJECT_INFO(PostprocNode, Object)
virtual Postproc Clone() const =0
Clone the postprocessor.
FClone f_clone
The packed function to the Clone function.
Definition: postproc.h:184
A managed object in the TVM runtime.
#define TVM_DECLARE_FINAL_OBJECT_INFO(TypeName, ParentType)
helper macro to declare type information in a final class.
Definition: object.h:671
FAsString f_as_string
The packed function to the AsString function.
Definition: postproc.h:186
virtual void InitializeWithTuneContext(const TuneContext &context)=0
Initialize the design space generator with tuning context.
runtime::TypedPackedFunc< bool(const tir::Schedule &)> FApply
Apply a postprocessor to the given schedule.
Definition: postproc.h:84
virtual bool Apply(const tir::Schedule &sch)=0
Apply a postprocessor to the given schedule.
bool VerifyVTCMLimit(const PrimFunc &func, Integer limit)
Verifies that the VTCM usage of the given prim_func is within the provided limit. ...
virtual ~PostprocNode()=default
Virtual destructor.
void VisitAttrs(tvm::AttrVisitor *v)
Definition: postproc.h:188
Reflection and serialization of compiler IR/AST nodes.
Type-erased function used across TVM API.
void VisitAttrs(tvm::AttrVisitor *v)
Definition: postproc.h:42