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();
133  TVM_DLL static Postproc RewriteReductionBlock();
139  TVM_DLL static Postproc RewriteUnboundBlock(int max_threadblocks);
146  TVM_DLL static Postproc RewriteTensorize(bool vectorize_init_loop = false);
151  TVM_DLL static Postproc VerifyGPUCode();
156  TVM_DLL static Postproc VerifyVTCMLimit();
162  TVM_DLL static Postproc RewriteLayout();
173 
175 };
176 
178 class PyPostprocNode : public PostprocNode {
179  public:
192 
194  // `f_initialize_with_tune_context` is not visited
195  // `f_apply` is not visited
196  // `f_clone` is not visited
197  // `f_as_string` is not visited
198  }
199 
200  void InitializeWithTuneContext(const TuneContext& context) final;
201  bool Apply(const tir::Schedule& sch) final;
202  Postproc Clone() const final;
203 
204  static constexpr const char* _type_key = "meta_schedule.PyPostproc";
206 };
207 
208 } // namespace meta_schedule
209 } // namespace tvm
210 
211 #endif // TVM_META_SCHEDULE_POSTPROC_H_
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
Rules to apply a postprocessor to a schedule.
Definition: postproc.h:37
virtual void InitializeWithTuneContext(const TuneContext &context)=0
Initialize the design space generator with tuning context.
virtual Postproc Clone() const =0
Clone the postprocessor.
virtual ~PostprocNode()=default
Virtual destructor.
virtual bool Apply(const tir::Schedule &sch)=0
Apply a postprocessor to the given schedule.
TVM_DECLARE_BASE_OBJECT_INFO(PostprocNode, Object)
static constexpr const char * _type_key
Definition: postproc.h:64
void VisitAttrs(tvm::AttrVisitor *v)
Definition: postproc.h:42
Managed reference to PostprocNode.
Definition: postproc.h:72
static Postproc DisallowAsyncStridedMemCopy()
Create a postprocessor that checks if all async mem copies are not strided.
static Postproc RewriteReductionBlock()
Create a postprocessor that rewrites reduction block by moving the init block out.
static Postproc RewriteUnboundBlock(int max_threadblocks)
Create a postprocessor that adds thread binding to unbound blocks.
runtime::TypedPackedFunc< String()> FAsString
Get the postprocessor function as string with name.
Definition: postproc.h:94
runtime::TypedPackedFunc< Postproc()> FClone
Clone the postprocessor.
Definition: postproc.h:89
TVM_DEFINE_MUTABLE_OBJECT_REF_METHODS(Postproc, ObjectRef, PostprocNode)
static Array< Postproc, void > DefaultCUDATensorCore()
Create default postprocessors for CUDA with TensorCore.
static Array< Postproc, void > DefaultCPUTensorization()
Create default postprocessors for x86 (AVX512 and VNNI)
static Array< Postproc, void > DefaultLLVM()
Create default postprocessors for LLVM.
runtime::TypedPackedFunc< void(const TuneContext &)> FInitializeWithTuneContext
The function type of InitializeWithTuneContext method.
Definition: postproc.h:78
static Postproc VerifyGPUCode()
Creates a postprocessor that verifies if the GPU code is correct.
static Array< Postproc, void > DefaultCUDA()
Create default postprocessors for CUDA.
static Postproc RewriteLayout()
Creates a postprocessor that rewrites the layout of input tensor.
static Postproc RewriteCooperativeFetch()
Create a postprocessor that rewrites the cooperative fetch annotation to actual vectorized cooperativ...
static Postproc RewriteTensorize(bool vectorize_init_loop=false)
Create a postprocessor that applies tensorization to annotated blocks.
runtime::TypedPackedFunc< bool(const tir::Schedule &)> FApply
Apply a postprocessor to the given schedule.
Definition: postproc.h:84
static Postproc VerifyVTCMLimit()
Verifies that the VTCM usage of a given schedule is within the provided limit.
static Postproc RewriteParallelVectorizeUnroll()
Creates a postprocessor that applies parallelization, vectorization and auto unrolling according to t...
static Postproc PyPostproc(FInitializeWithTuneContext f_initialize_with_tune_context, FApply f_apply, FClone f_clone, FAsString f_as_string)
Create a postprocessor with customized methods on the python-side.
static Array< Postproc, void > DefaultHexagon()
Create default postprocessors for Hexagon.
static Postproc DisallowDynamicLoop()
Create a postprocessor that checks if all loops are static.
The postprocessor with customized methods on the python-side.
Definition: postproc.h:178
Postproc Clone() const final
Clone the postprocessor.
FAsString f_as_string
The packed function to the AsString function.
Definition: postproc.h:191
void InitializeWithTuneContext(const TuneContext &context) final
Initialize the design space generator with tuning context.
FApply f_apply
The packed function to the Apply function.
Definition: postproc.h:187
bool Apply(const tir::Schedule &sch) final
Apply a postprocessor to the given schedule.
static constexpr const char * _type_key
Definition: postproc.h:204
FInitializeWithTuneContext f_initialize_with_tune_context
The packed function to the InitializeWithTuneContext function.
Definition: postproc.h:185
TVM_DECLARE_FINAL_OBJECT_INFO(PyPostprocNode, PostprocNode)
FClone f_clone
The packed function to the Clone function.
Definition: postproc.h:189
void VisitAttrs(tvm::AttrVisitor *v)
Definition: postproc.h:193
Managed reference to TuneContextNode.
Definition: tune_context.h:95
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
Base class of all object reference.
Definition: object.h:519
base class of all object containers.
Definition: object.h:171
Reference to string objects.
Definition: string.h:98
Please refer to TypedPackedFunc<R(Args..)>.
Definition: packed_func.h:63
Managed reference to ScheduleNode.
Definition: schedule.h:877
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
A managed object in the TVM runtime.
Type-erased function used across TVM API.
Reflection and serialization of compiler IR/AST nodes.