tvm
Loading...
Searching...
No Matches
space_generator.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#ifndef TVM_S_TIR_META_SCHEDULE_SPACE_GENERATOR_H_
20#define TVM_S_TIR_META_SCHEDULE_SPACE_GENERATOR_H_
21
22#include <tvm/base.h>
23#include <tvm/ffi/container/array.h>
24#include <tvm/ffi/function.h>
25#include <tvm/ffi/reflection/registry.h>
26#include <tvm/ir/module.h>
27#include <tvm/ir/prim/expr.h>
32#include <tvm/target/target.h>
33
34namespace tvm {
35namespace s_tir {
36namespace meta_schedule {
37
38// Forward declaration
39class TuneContext;
40class SpaceGenerator;
41
78class SpaceGeneratorObj : public ffi::Object {
79 public:
81 ffi::Optional<ffi::Array<ScheduleRule>> sch_rules;
83 ffi::Optional<ffi::Array<Postproc>> postprocs;
85 ffi::Optional<ffi::Map<Mutator, FloatImm>> mutator_probs;
86
87 static void RegisterReflection() {
88 namespace refl = tvm::ffi::reflection;
89 refl::ObjectDef<SpaceGeneratorObj>()
90 .def_ro("sch_rules", &SpaceGeneratorObj::sch_rules)
91 .def_ro("postprocs", &SpaceGeneratorObj::postprocs)
92 .def_ro("mutator_probs", &SpaceGeneratorObj::mutator_probs);
93 }
94
96 virtual ~SpaceGeneratorObj() = default;
97
103 virtual void InitializeWithTuneContext(const TuneContext& context);
104
110 virtual ffi::Array<s_tir::Schedule> GenerateDesignSpace(const IRModule& mod) = 0;
111
116 virtual SpaceGenerator Clone() const = 0;
117
118 static constexpr const bool _type_mutable = true;
119 TVM_FFI_DECLARE_OBJECT_INFO("s_tir.meta_schedule.SpaceGenerator", SpaceGeneratorObj, ffi::Object);
120};
121
126class SpaceGenerator : public ffi::ObjectRef {
127 public:
132 explicit SpaceGenerator(ffi::ObjectPtr<SpaceGeneratorObj> data) : ffi::ObjectRef(data) {
133 TVM_FFI_ICHECK(data != nullptr);
134 }
139 using FInitializeWithTuneContext = ffi::TypedFunction<void(const TuneContext&)>;
145 using FGenerateDesignSpace = ffi::TypedFunction<ffi::Array<s_tir::Schedule>(const IRModule&)>;
150 using FClone = ffi::TypedFunction<SpaceGenerator()>;
151
152 protected:
153 SpaceGenerator() = default;
154
155 public:
167 ffi::Optional<ffi::Array<ScheduleRule>> sch_rules,
168 ffi::Optional<ffi::Array<Postproc>> postprocs,
169 ffi::Optional<ffi::Map<Mutator, FloatImm>> mutator_probs,
170 FInitializeWithTuneContext f_initialize_with_tune_context,
171 FGenerateDesignSpace f_generate_design_space, FClone f_clone);
183 ffi::Function schedule_fn, ffi::Optional<ffi::Array<ScheduleRule>> sch_rules,
184 ffi::Optional<ffi::Array<Postproc>> postprocs,
185 ffi::Optional<ffi::Map<Mutator, FloatImm>> mutator_probs);
195 ffi::Array<SpaceGenerator, void> space_generators,
196 ffi::Optional<ffi::Array<ScheduleRule>> sch_rules,
197 ffi::Optional<ffi::Array<Postproc>> postprocs,
198 ffi::Optional<ffi::Map<Mutator, FloatImm>> mutator_probs);
209 ffi::Function f_block_filter, ffi::Optional<ffi::Array<ScheduleRule>> sch_rules,
210 ffi::Optional<ffi::Array<Postproc>> postprocs,
211 ffi::Optional<ffi::Map<Mutator, FloatImm>> mutator_probs);
213};
214
217 public:
227
228 static void RegisterReflection() {
229 // `f_initialize_with_tune_context` is not registered
230 // `f_generate_design_space` is not registered
231 // `f_clone` is not registered
232 namespace refl = tvm::ffi::reflection;
233 refl::ObjectDef<PySpaceGeneratorObj>();
234 }
235
236 void InitializeWithTuneContext(const TuneContext& context) final;
237 ffi::Array<s_tir::Schedule> GenerateDesignSpace(const IRModule& mod) final;
238 SpaceGenerator Clone() const final;
239 TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.meta_schedule.PySpaceGenerator", PySpaceGeneratorObj,
241};
242
243} // namespace meta_schedule
244} // namespace s_tir
245} // namespace tvm
246
247#endif // TVM_S_TIR_META_SCHEDULE_SPACE_GENERATOR_H_
TIR expressions.
Managed reference class to IRModuleObj.
Definition module.h:292
The design space generator with customized methods on the python-side.
Definition space_generator.h:216
SpaceGenerator::FInitializeWithTuneContext FInitializeWithTuneContext
Definition space_generator.h:218
void InitializeWithTuneContext(const TuneContext &context) final
Initialize the design space generator with tuning context.
SpaceGenerator::FClone FClone
Definition space_generator.h:220
ffi::Array< s_tir::Schedule > GenerateDesignSpace(const IRModule &mod) final
Generate design spaces given a module.
FInitializeWithTuneContext f_initialize_with_tune_context
The packed function to the InitializeWithTuneContext function.
Definition space_generator.h:222
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.meta_schedule.PySpaceGenerator", PySpaceGeneratorObj, SpaceGeneratorObj)
FClone f_clone
The packed function to the Clone function.
Definition space_generator.h:226
SpaceGenerator Clone() const final
Clone the space generator.
SpaceGenerator::FGenerateDesignSpace FGenerateDesignSpace
Definition space_generator.h:219
static void RegisterReflection()
Definition space_generator.h:228
FGenerateDesignSpace f_generate_design_space
The packed function to the GenerateDesignSpace function.
Definition space_generator.h:224
The abstract class for design space generation.
Definition space_generator.h:78
virtual ~SpaceGeneratorObj()=default
Default destructor.
static constexpr const bool _type_mutable
Definition space_generator.h:118
virtual SpaceGenerator Clone() const =0
Clone the space generator.
virtual void InitializeWithTuneContext(const TuneContext &context)
Initialize the design space generator with tuning context.
ffi::Optional< ffi::Map< Mutator, FloatImm > > mutator_probs
The probability of using certain mutator.
Definition space_generator.h:85
virtual ffi::Array< s_tir::Schedule > GenerateDesignSpace(const IRModule &mod)=0
Generate design spaces given a module.
TVM_FFI_DECLARE_OBJECT_INFO("s_tir.meta_schedule.SpaceGenerator", SpaceGeneratorObj, ffi::Object)
ffi::Optional< ffi::Array< ScheduleRule > > sch_rules
The schedule rules.
Definition space_generator.h:81
ffi::Optional< ffi::Array< Postproc > > postprocs
The postprocessors.
Definition space_generator.h:83
static void RegisterReflection()
Definition space_generator.h:87
Managed reference to SpaceGeneratorObj.
Definition space_generator.h:126
static SpaceGenerator SpaceGeneratorUnion(ffi::Array< SpaceGenerator, void > space_generators, ffi::Optional< ffi::Array< ScheduleRule > > sch_rules, ffi::Optional< ffi::Array< Postproc > > postprocs, ffi::Optional< ffi::Map< Mutator, FloatImm > > mutator_probs)
Create a design space generator that is union of multiple design space generators.
ffi::TypedFunction< SpaceGenerator()> FClone
The function type of Clone method.
Definition space_generator.h:150
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(SpaceGenerator, ffi::ObjectRef, SpaceGeneratorObj)
ffi::TypedFunction< void(const TuneContext &)> FInitializeWithTuneContext
The function type of InitializeWithTuneContext method.
Definition space_generator.h:139
static SpaceGenerator PySpaceGenerator(ffi::Optional< ffi::Array< ScheduleRule > > sch_rules, ffi::Optional< ffi::Array< Postproc > > postprocs, ffi::Optional< ffi::Map< Mutator, FloatImm > > mutator_probs, FInitializeWithTuneContext f_initialize_with_tune_context, FGenerateDesignSpace f_generate_design_space, FClone f_clone)
Create a design space generator with customized methods on the python-side.
static SpaceGenerator ScheduleFn(ffi::Function schedule_fn, ffi::Optional< ffi::Array< ScheduleRule > > sch_rules, ffi::Optional< ffi::Array< Postproc > > postprocs, ffi::Optional< ffi::Map< Mutator, FloatImm > > mutator_probs)
Create a design space generator with customized schedule function.
ffi::TypedFunction< ffi::Array< s_tir::Schedule >(const IRModule &)> FGenerateDesignSpace
The function type of GenerateDesignSpace method.
Definition space_generator.h:145
SpaceGenerator(ffi::ObjectPtr< SpaceGeneratorObj > data)
Constructor from ffi::ObjectPtr<SpaceGeneratorObj>.
Definition space_generator.h:132
static SpaceGenerator PostOrderApply(ffi::Function f_block_filter, ffi::Optional< ffi::Array< ScheduleRule > > sch_rules, ffi::Optional< ffi::Array< Postproc > > postprocs, ffi::Optional< ffi::Map< Mutator, FloatImm > > mutator_probs)
Create a design space generator that generates design spaces by applying schedule rules to blocks in ...
Managed reference to TuneContextObj.
Definition tune_context.h:100
Parent compiler symbol visibility.
IRModule that holds the functions and type definitions.
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition analysis.h:41
Compilation target object.