tvm
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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:
155  TVM_DLL static SpaceGenerator PySpaceGenerator(
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,
182  TVM_DLL static SpaceGenerator SpaceGeneratorUnion(Array<SpaceGenerator, void> space_generators,
195  TVM_DLL static SpaceGenerator PostOrderApply(runtime::PackedFunc f_block_filter,
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_
virtual ~SpaceGeneratorNode()=default
Default destructor.
Optional< Map< Mutator, FloatImm > > mutator_probs
The probability of using certain mutator.
Definition: space_generator.h:83
runtime::TypedPackedFunc< SpaceGenerator()> FClone
The function type of Clone method.
Definition: space_generator.h:139
TVM_DECLARE_BASE_OBJECT_INFO(SpaceGeneratorNode, Object)
#define TVM_DEFINE_MUTABLE_NOTNULLABLE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName)
Definition: object.h:758
virtual void InitializeWithTuneContext(const TuneContext &context)
Initialize the design space generator with tuning context.
IRModule that holds the functions and type definitions.
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
The design space generator with customized methods on the python-side.
Definition: space_generator.h:203
Optional< Array< Postproc > > postprocs
The postprocessors.
Definition: space_generator.h:81
Optional< Array< ScheduleRule > > sch_rules
The schedule rules.
Definition: space_generator.h:79
base class of all object containers.
Definition: object.h:167
void VisitAttrs(tvm::AttrVisitor *v)
Definition: space_generator.h:85
Managed reference to TuneContextNode.
Definition: tune_context.h:95
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
virtual Array< tir::Schedule > GenerateDesignSpace(const IRModule &mod)=0
Generate design spaces given a module.
The abstract class for design space generation.
Definition: space_generator.h:76
runtime::TypedPackedFunc< void(const TuneContext &)> FInitializeWithTuneContext
The function type of InitializeWithTuneContext method.
Definition: space_generator.h:128
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
Please refer to TypedPackedFunc<R(Args..)>.
Definition: packed_func.h:60
runtime::TypedPackedFunc< Array< tir::Schedule >(const IRModule &)> FGenerateDesignSpace
The function type of GenerateDesignSpace method.
Definition: space_generator.h:134
Base class of all object reference.
Definition: object.h:511
void VisitAttrs(tvm::AttrVisitor *v)
Definition: space_generator.h:215
A managed object in the TVM runtime.
#define TVM_DECLARE_FINAL_OBJECT_INFO(TypeName, ParentType)
helper macro to declare type information in a final class.
Definition: object.h:671
Managed reference class to IRModuleNode.
Definition: module.h:348
Compilation target object.
Map container of NodeRef->NodeRef in DSL graph. Map implements copy on write semantics, which means map is mutable but copy will happen when array is referenced in more than two places.
Definition: map.h:1271
Packed function is a type-erased function. The arguments are passed by packed format.
Definition: packed_func.h:138
FInitializeWithTuneContext f_initialize_with_tune_context
The packed function to the InitializeWithTuneContext function.
Definition: space_generator.h:209
Optional container that to represent to a Nullable variant of T.
Definition: optional.h:51
tvm::PrimExpr mod(const tvm::PrimExpr &a, const tvm::PrimExpr &b)
Definition: broadcast.h:290
Reflection and serialization of compiler IR/AST nodes.
virtual SpaceGenerator Clone() const =0
Clone the space generator.
FClone f_clone
The packed function to the Clone function.
Definition: space_generator.h:213
FGenerateDesignSpace f_generate_design_space
The packed function to the GenerateDesignSpace function.
Definition: space_generator.h:211
static constexpr const char * _type_key
Definition: space_generator.h:114
Type-erased function used across TVM API.
Managed reference to SpaceGeneratorNode.
Definition: space_generator.h:122