tvm
Loading...
Searching...
No Matches
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/base.h>
24#include <tvm/ffi/function.h>
25#include <tvm/ffi/reflection/registry.h>
26#include <tvm/ir/prim/expr.h>
27#include <tvm/runtime/base.h>
29
30namespace tvm {
31namespace s_tir {
32namespace meta_schedule {
33
34class TuneContext;
35class Postproc;
36
40class PostprocObj : public ffi::Object {
41 public:
43 virtual ~PostprocObj() = default;
44
45 static void RegisterReflection() {
46 namespace refl = tvm::ffi::reflection;
47 refl::ObjectDef<PostprocObj>();
48 }
49
55 virtual void InitializeWithTuneContext(const TuneContext& context) = 0;
56
62 virtual bool Apply(const s_tir::Schedule& sch) = 0;
63
68 virtual Postproc Clone() const = 0;
69
70 static constexpr const bool _type_mutable = true;
71 TVM_FFI_DECLARE_OBJECT_INFO("s_tir.meta_schedule.Postproc", PostprocObj, ffi::Object);
72};
73
78class Postproc : public ffi::ObjectRef {
79 public:
80 explicit Postproc(ffi::UnsafeInit tag, ffi::ObjectPtr<PostprocObj> data) : ffi::ObjectRef(tag) {
81 data_ = std::move(data);
82 }
83
88 using FInitializeWithTuneContext = ffi::TypedFunction<void(const TuneContext&)>;
94 using FApply = ffi::TypedFunction<bool(const s_tir::Schedule&)>;
99 using FClone = ffi::TypedFunction<Postproc()>;
107 TVM_DLL static Postproc PyPostproc(FInitializeWithTuneContext f_initialize_with_tune_context, //
108 FApply f_apply, //
109 FClone f_clone);
142 TVM_DLL static Postproc RewriteUnboundBlock(int max_threadblocks);
149 TVM_DLL static Postproc RewriteTensorize(bool vectorize_init_loop = false);
154 TVM_DLL static Postproc VerifyGPUCode();
159 TVM_DLL static Postproc VerifyVTCMLimit();
165 TVM_DLL static Postproc RewriteLayout();
167 TVM_DLL static ffi::Array<Postproc, void> DefaultLLVM();
169 TVM_DLL static ffi::Array<Postproc, void> DefaultCPUTensorization();
171 TVM_DLL static ffi::Array<Postproc, void> DefaultRISCV();
173 TVM_DLL static ffi::Array<Postproc, void> DefaultCUDA();
175 TVM_DLL static ffi::Array<Postproc, void> DefaultHexagon();
176
178};
179
182 public:
192
193 static void RegisterReflection() {
194 // `f_initialize_with_tune_context` is not registered
195 // `f_apply` is not registered
196 // `f_clone` is not registered
197 namespace refl = tvm::ffi::reflection;
198 refl::ObjectDef<PyPostprocObj>();
199 }
200
201 void InitializeWithTuneContext(const TuneContext& context) final;
202 bool Apply(const s_tir::Schedule& sch) final;
203 Postproc Clone() const final;
205};
206
207} // namespace meta_schedule
208} // namespace s_tir
209} // namespace tvm
210
211#endif // TVM_S_TIR_META_SCHEDULE_POSTPROC_H_
TIR expressions.
Managed reference to ScheduleObj.
Definition schedule.h:888
Rules to apply a postprocessor to a schedule.
Definition postproc.h:40
TVM_FFI_DECLARE_OBJECT_INFO("s_tir.meta_schedule.Postproc", PostprocObj, ffi::Object)
static constexpr const bool _type_mutable
Definition postproc.h:70
virtual Postproc Clone() const =0
Clone the postprocessor.
virtual void InitializeWithTuneContext(const TuneContext &context)=0
Initialize the design space generator with tuning context.
static void RegisterReflection()
Definition postproc.h:45
virtual ~PostprocObj()=default
Virtual destructor.
virtual bool Apply(const s_tir::Schedule &sch)=0
Apply a postprocessor to the given schedule.
Managed reference to PostprocObj.
Definition postproc.h:78
static ffi::Array< Postproc, void > DefaultRISCV()
Create default postprocessors for RISCV.
static Postproc DisallowDynamicLoop()
Create a postprocessor that checks if all loops are static.
static ffi::Array< Postproc, void > DefaultHexagon()
Create default postprocessors for Hexagon.
static Postproc DisallowAsyncStridedMemCopy()
Create a postprocessor that checks if all async mem copies are not strided.
static ffi::Array< Postproc, void > DefaultCUDA()
Create default postprocessors for CUDA.
Postproc(ffi::UnsafeInit tag, ffi::ObjectPtr< PostprocObj > data)
Definition postproc.h:80
ffi::TypedFunction< void(const TuneContext &)> FInitializeWithTuneContext
The function type of InitializeWithTuneContext method.
Definition postproc.h:88
static Postproc RewriteUnboundBlock(int max_threadblocks)
Create a postprocessor that adds thread binding to unbound blocks.
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:94
static Postproc RewriteReductionBlock()
Create a postprocessor that rewrites reduction block by moving the init block out.
static Postproc PyPostproc(FInitializeWithTuneContext f_initialize_with_tune_context, FApply f_apply, FClone f_clone)
Create a postprocessor with customized methods on the python-side.
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...
static ffi::Array< Postproc, void > DefaultLLVM()
Create default postprocessors for LLVM.
ffi::TypedFunction< Postproc()> FClone
Clone the postprocessor.
Definition postproc.h:99
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(Postproc, ffi::ObjectRef, PostprocObj)
static ffi::Array< Postproc, void > DefaultCPUTensorization()
Create default postprocessors for x86 (AVX512 and VNNI)
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:181
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.meta_schedule.PyPostproc", PyPostprocObj, PostprocObj)
Postproc::FApply FApply
Definition postproc.h:184
bool Apply(const s_tir::Schedule &sch) final
Apply a postprocessor to the given schedule.
Postproc::FInitializeWithTuneContext FInitializeWithTuneContext
Definition postproc.h:183
static void RegisterReflection()
Definition postproc.h:193
void InitializeWithTuneContext(const TuneContext &context) final
Initialize the design space generator with tuning context.
FInitializeWithTuneContext f_initialize_with_tune_context
The packed function to the InitializeWithTuneContext function.
Definition postproc.h:187
FClone f_clone
The packed function to the Clone function.
Definition postproc.h:191
Postproc Clone() const final
Clone the postprocessor.
FApply f_apply
The packed function to the Apply function.
Definition postproc.h:189
Postproc::FClone FClone
Definition postproc.h:185
Managed reference to TuneContextObj.
Definition tune_context.h:100
Parent compiler symbol visibility.
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition analysis.h:41