tvm
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_META_SCHEDULE_SPACE_GENERATOR_H_
20 #define TVM_META_SCHEDULE_SPACE_GENERATOR_H_
21 
22 #include <tvm/ir/module.h>
26 #include <tvm/node/reflection.h>
28 #include <tvm/runtime/object.h>
30 #include <tvm/target/target.h>
32 
33 namespace tvm {
34 namespace meta_schedule {
35 
36 // Forward declaration
37 class TuneContext;
38 class SpaceGenerator;
39 
77  public:
84 
86  v->Visit("sch_rules", &sch_rules);
87  v->Visit("postprocs", &postprocs);
88  v->Visit("mutator_probs", &mutator_probs);
89  }
90 
92  virtual ~SpaceGeneratorNode() = default;
93 
99  virtual void InitializeWithTuneContext(const TuneContext& context);
100 
107 
112  virtual SpaceGenerator Clone() const = 0;
113 
114  static constexpr const char* _type_key = "meta_schedule.SpaceGenerator";
116 };
117 
123  public:
140 
141  protected:
142  SpaceGenerator() = default;
143 
144  public:
156  Optional<Array<ScheduleRule>> sch_rules, Optional<Array<Postproc>> postprocs,
157  Optional<Map<Mutator, FloatImm>> mutator_probs,
158  FInitializeWithTuneContext f_initialize_with_tune_context,
159  FGenerateDesignSpace f_generate_design_space, FClone f_clone);
170  TVM_DLL static SpaceGenerator ScheduleFn(PackedFunc schedule_fn,
171  Optional<Array<ScheduleRule>> sch_rules,
172  Optional<Array<Postproc>> postprocs,
173  Optional<Map<Mutator, FloatImm>> mutator_probs);
183  Optional<Array<ScheduleRule>> sch_rules,
184  Optional<Array<Postproc>> postprocs,
185  Optional<Map<Mutator, FloatImm>> mutator_probs);
195  TVM_DLL static SpaceGenerator PostOrderApply(runtime::PackedFunc f_block_filter,
196  Optional<Array<ScheduleRule>> sch_rules,
197  Optional<Array<Postproc>> postprocs,
198  Optional<Map<Mutator, FloatImm>> mutator_probs);
200 };
201 
204  public:
214 
217  // `f_initialize_with_tune_context` is not visited
218  // `f_generate_design_space` is not visited
219  // `f_clone` is not visited
220  }
221 
222  void InitializeWithTuneContext(const TuneContext& context) final;
224  SpaceGenerator Clone() const final;
225 
226  static constexpr const char* _type_key = "meta_schedule.PySpaceGenerator";
228 };
229 
230 } // namespace meta_schedule
231 } // namespace tvm
232 
233 #endif // TVM_META_SCHEDULE_SPACE_GENERATOR_H_
Runtime Array container types.
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
Managed reference class to IRModuleNode.
Definition: module.h:366
The design space generator with customized methods on the python-side.
Definition: space_generator.h:203
void InitializeWithTuneContext(const TuneContext &context) final
Initialize the design space generator with tuning context.
static constexpr const char * _type_key
Definition: space_generator.h:226
FClone f_clone
The packed function to the Clone function.
Definition: space_generator.h:213
Array< tir::Schedule > GenerateDesignSpace(const IRModule &mod) final
Generate design spaces given a module.
FGenerateDesignSpace f_generate_design_space
The packed function to the GenerateDesignSpace function.
Definition: space_generator.h:211
TVM_DECLARE_FINAL_OBJECT_INFO(PySpaceGeneratorNode, SpaceGeneratorNode)
SpaceGenerator Clone() const final
Clone the space generator.
void VisitAttrs(tvm::AttrVisitor *v)
Definition: space_generator.h:215
FInitializeWithTuneContext f_initialize_with_tune_context
The packed function to the InitializeWithTuneContext function.
Definition: space_generator.h:209
The abstract class for design space generation.
Definition: space_generator.h:76
Optional< Array< Postproc > > postprocs
The postprocessors.
Definition: space_generator.h:81
static constexpr const char * _type_key
Definition: space_generator.h:114
Optional< Array< ScheduleRule > > sch_rules
The schedule rules.
Definition: space_generator.h:79
virtual ~SpaceGeneratorNode()=default
Default destructor.
TVM_DECLARE_BASE_OBJECT_INFO(SpaceGeneratorNode, Object)
void VisitAttrs(tvm::AttrVisitor *v)
Definition: space_generator.h:85
virtual void InitializeWithTuneContext(const TuneContext &context)
Initialize the design space generator with tuning context.
Optional< Map< Mutator, FloatImm > > mutator_probs
The probability of using certain mutator.
Definition: space_generator.h:83
virtual Array< tir::Schedule > GenerateDesignSpace(const IRModule &mod)=0
Generate design spaces given a module.
virtual SpaceGenerator Clone() const =0
Clone the space generator.
Managed reference to SpaceGeneratorNode.
Definition: space_generator.h:122
static SpaceGenerator SpaceGeneratorUnion(Array< SpaceGenerator, void > space_generators, Optional< Array< ScheduleRule >> sch_rules, Optional< Array< Postproc >> postprocs, Optional< Map< Mutator, FloatImm >> mutator_probs)
Create a design space generator that is union of multiple design space generators.
static SpaceGenerator ScheduleFn(PackedFunc schedule_fn, Optional< Array< ScheduleRule >> sch_rules, Optional< Array< Postproc >> postprocs, Optional< Map< Mutator, FloatImm >> mutator_probs)
Create a design space generator with customized schedule function.
TVM_DEFINE_MUTABLE_NOTNULLABLE_OBJECT_REF_METHODS(SpaceGenerator, ObjectRef, SpaceGeneratorNode)
runtime::TypedPackedFunc< void(const TuneContext &)> FInitializeWithTuneContext
The function type of InitializeWithTuneContext method.
Definition: space_generator.h:128
runtime::TypedPackedFunc< Array< tir::Schedule >(const IRModule &)> FGenerateDesignSpace
The function type of GenerateDesignSpace method.
Definition: space_generator.h:134
static SpaceGenerator PySpaceGenerator(Optional< Array< ScheduleRule >> sch_rules, Optional< Array< Postproc >> postprocs, Optional< 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.
runtime::TypedPackedFunc< SpaceGenerator()> FClone
The function type of Clone method.
Definition: space_generator.h:139
static SpaceGenerator PostOrderApply(runtime::PackedFunc f_block_filter, Optional< Array< ScheduleRule >> sch_rules, Optional< Array< Postproc >> postprocs, Optional< Map< Mutator, FloatImm >> mutator_probs)
Create a design space generator that generates design spaces by applying schedule rules to blocks in ...
Managed reference to TuneContextNode.
Definition: tune_context.h:95
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
Map container of NodeRef->NodeRef in DSL graph. Map implements copy on write semantics,...
Definition: map.h:1271
Base class of all object reference.
Definition: object.h:519
base class of all object containers.
Definition: object.h:171
Optional container that to represent to a Nullable variant of T.
Definition: optional.h:51
Packed function is a type-erased function. The arguments are passed by packed format.
Definition: packed_func.h:141
Please refer to TypedPackedFunc<R(Args..)>.
Definition: packed_func.h:63
IRModule that holds the functions and type definitions.
tvm::PrimExpr mod(const tvm::PrimExpr &a, const tvm::PrimExpr &b)
Definition: broadcast.h:290
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.
Compilation target object.