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_S_TIR_META_SCHEDULE_POSTPROC_H_
21 #define TVM_S_TIR_META_SCHEDULE_POSTPROC_H_
22 
23 #include <tvm/ffi/function.h>
24 #include <tvm/ffi/reflection/registry.h>
25 #include <tvm/runtime/object.h>
27 
28 namespace tvm {
29 namespace s_tir {
30 namespace meta_schedule {
31 
32 class TuneContext;
33 class Postproc;
34 
38 class PostprocNode : public runtime::Object {
39  public:
41  virtual ~PostprocNode() = default;
42 
43  static void RegisterReflection() {
44  namespace refl = tvm::ffi::reflection;
45  refl::ObjectDef<PostprocNode>();
46  }
47 
53  virtual void InitializeWithTuneContext(const TuneContext& context) = 0;
54 
60  virtual bool Apply(const s_tir::Schedule& sch) = 0;
61 
66  virtual Postproc Clone() const = 0;
67 
68  static constexpr const bool _type_mutable = true;
69  TVM_FFI_DECLARE_OBJECT_INFO("s_tir.meta_schedule.Postproc", PostprocNode, Object);
70 };
71 
76 class Postproc : public runtime::ObjectRef {
77  public:
82  using FInitializeWithTuneContext = ffi::TypedFunction<void(const TuneContext&)>;
88  using FApply = ffi::TypedFunction<bool(const s_tir::Schedule&)>;
93  using FClone = ffi::TypedFunction<Postproc()>;
98  using FAsString = ffi::TypedFunction<ffi::String()>;
107  TVM_DLL static Postproc PyPostproc(FInitializeWithTuneContext f_initialize_with_tune_context, //
108  FApply f_apply, //
109  FClone f_clone, //
110  FAsString f_as_string);
115  TVM_DLL static Postproc DisallowDynamicLoop();
137  TVM_DLL static Postproc RewriteReductionBlock();
143  TVM_DLL static Postproc RewriteUnboundBlock(int max_threadblocks);
150  TVM_DLL static Postproc RewriteTensorize(bool vectorize_init_loop = false);
155  TVM_DLL static Postproc VerifyGPUCode();
160  TVM_DLL static Postproc VerifyVTCMLimit();
166  TVM_DLL static Postproc RewriteLayout();
168  TVM_DLL static ffi::Array<Postproc, void> DefaultLLVM();
170  TVM_DLL static ffi::Array<Postproc, void> DefaultCPUTensorization();
172  TVM_DLL static ffi::Array<Postproc, void> DefaultRISCV();
174  TVM_DLL static ffi::Array<Postproc, void> DefaultCUDA();
176  TVM_DLL static ffi::Array<Postproc, void> DefaultCUDATensorCore();
178  TVM_DLL static ffi::Array<Postproc, void> DefaultHexagon();
179 
181 };
182 
184 class PyPostprocNode : public PostprocNode {
185  public:
198 
199  static void RegisterReflection() {
200  // `f_initialize_with_tune_context` is not registered
201  // `f_apply` is not registered
202  // `f_clone` is not registered
203  // `f_as_string` is not registered
204  namespace refl = tvm::ffi::reflection;
205  refl::ObjectDef<PyPostprocNode>();
206  }
207 
208  void InitializeWithTuneContext(const TuneContext& context) final;
209  bool Apply(const s_tir::Schedule& sch) final;
210  Postproc Clone() const final;
211  TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.meta_schedule.PyPostproc", PyPostprocNode, PostprocNode);
212 };
213 
214 } // namespace meta_schedule
215 } // namespace s_tir
216 } // namespace tvm
217 
218 #endif // TVM_S_TIR_META_SCHEDULE_POSTPROC_H_
Managed reference to ScheduleNode.
Definition: schedule.h:897
Rules to apply a postprocessor to a schedule.
Definition: postproc.h:38
TVM_FFI_DECLARE_OBJECT_INFO("s_tir.meta_schedule.Postproc", PostprocNode, Object)
virtual bool Apply(const s_tir::Schedule &sch)=0
Apply a postprocessor to the given schedule.
static constexpr const bool _type_mutable
Definition: postproc.h:68
virtual ~PostprocNode()=default
Virtual destructor.
virtual void InitializeWithTuneContext(const TuneContext &context)=0
Initialize the design space generator with tuning context.
virtual Postproc Clone() const =0
Clone the postprocessor.
static void RegisterReflection()
Definition: postproc.h:43
Managed reference to PostprocNode.
Definition: postproc.h:76
static Postproc DisallowDynamicLoop()
Create a postprocessor that checks if all loops are static.
static Postproc DisallowAsyncStridedMemCopy()
Create a postprocessor that checks if all async mem copies are not strided.
ffi::TypedFunction< ffi::String()> FAsString
Get the postprocessor function as string with name.
Definition: postproc.h:98
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.
ffi::TypedFunction< void(const TuneContext &)> FInitializeWithTuneContext
The function type of InitializeWithTuneContext method.
Definition: postproc.h:82
static ffi::Array< Postproc, void > DefaultHexagon()
Create default postprocessors for Hexagon.
static Postproc RewriteUnboundBlock(int max_threadblocks)
Create a postprocessor that adds thread binding to unbound blocks.
static ffi::Array< Postproc, void > DefaultLLVM()
Create default postprocessors for LLVM.
static Postproc RewriteCooperativeFetch()
Create a postprocessor that rewrites the cooperative fetch annotation to actual vectorized cooperativ...
ffi::TypedFunction< bool(const s_tir::Schedule &)> FApply
Apply a postprocessor to the given schedule.
Definition: postproc.h:88
static ffi::Array< Postproc, void > DefaultCUDATensorCore()
Create default postprocessors for CUDA with TensorCore.
static Postproc RewriteReductionBlock()
Create a postprocessor that rewrites reduction block by moving the init block out.
static ffi::Array< Postproc, void > DefaultCPUTensorization()
Create default postprocessors for x86 (AVX512 and VNNI)
static ffi::Array< Postproc, void > DefaultCUDA()
Create default postprocessors for CUDA.
static Postproc RewriteTensorize(bool vectorize_init_loop=false)
Create a postprocessor that applies tensorization to annotated blocks.
static Postproc VerifyGPUCode()
Creates a postprocessor that verifies if the GPU code is correct.
static Postproc RewriteLayout()
Creates a postprocessor that rewrites the layout of input tensor.
static Postproc RewriteParallelVectorizeUnroll()
Creates a postprocessor that applies parallelization, vectorization and auto unrolling according to t...
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(Postproc, ObjectRef, PostprocNode)
ffi::TypedFunction< Postproc()> FClone
Clone the postprocessor.
Definition: postproc.h:93
static ffi::Array< Postproc, void > DefaultRISCV()
Create default postprocessors for RISCV.
static Postproc VerifyVTCMLimit()
Verifies that the VTCM usage of a given schedule is within the provided limit.
The postprocessor with customized methods on the python-side.
Definition: postproc.h:184
Postproc::FAsString FAsString
Definition: postproc.h:189
Postproc::FInitializeWithTuneContext FInitializeWithTuneContext
Definition: postproc.h:186
Postproc Clone() const final
Clone the postprocessor.
FClone f_clone
The packed function to the Clone function.
Definition: postproc.h:195
FInitializeWithTuneContext f_initialize_with_tune_context
The packed function to the InitializeWithTuneContext function.
Definition: postproc.h:191
Postproc::FClone FClone
Definition: postproc.h:188
void InitializeWithTuneContext(const TuneContext &context) final
Initialize the design space generator with tuning context.
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.meta_schedule.PyPostproc", PyPostprocNode, PostprocNode)
FApply f_apply
The packed function to the Apply function.
Definition: postproc.h:193
Postproc::FApply FApply
Definition: postproc.h:187
bool Apply(const s_tir::Schedule &sch) final
Apply a postprocessor to the given schedule.
FAsString f_as_string
The packed function to the AsString function.
Definition: postproc.h:197
static void RegisterReflection()
Definition: postproc.h:199
Managed reference to TuneContextNode.
Definition: tune_context.h:99
Definition: repr_printer.h:91
Performance counters for profiling via the PAPI library.
Definition: analyzer.h:37
A managed object in the TVM runtime.