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>
23 #include <tvm/node/reflection.h>
25 #include <tvm/runtime/object.h>
28 
29 namespace tvm {
30 namespace meta_schedule {
31 
32 // Forward declaration
33 class TuneContext;
34 class SpaceGenerator;
35 
73  public:
75  virtual ~SpaceGeneratorNode() = default;
76 
82  virtual void InitializeWithTuneContext(const TuneContext& context) = 0;
83 
90 
95  virtual SpaceGenerator Clone() const = 0;
96 
97  static constexpr const char* _type_key = "meta_schedule.SpaceGenerator";
99 };
100 
106  public:
123 
124  protected:
125  SpaceGenerator() = default;
126 
127  public:
135  TVM_DLL static SpaceGenerator PySpaceGenerator(
136  FInitializeWithTuneContext f_initialize_with_tune_context,
137  FGenerateDesignSpace f_generate_design_space, FClone f_clone);
145  TVM_DLL static SpaceGenerator ScheduleFn(PackedFunc schedule_fn);
151  TVM_DLL static SpaceGenerator SpaceGeneratorUnion(Array<SpaceGenerator, void> space_generators);
156  TVM_DLL static SpaceGenerator PostOrderApply(runtime::PackedFunc f_block_filter = nullptr);
158 };
159 
162  public:
172 
174  // `f_initialize_with_tune_context` is not visited
175  // `f_generate_design_space` is not visited
176  // `f_clone` is not visited
177  }
178 
179  void InitializeWithTuneContext(const TuneContext& context) final;
181  SpaceGenerator Clone() const final;
182 
183  static constexpr const char* _type_key = "meta_schedule.PySpaceGenerator";
185 };
186 
187 } // namespace meta_schedule
188 } // namespace tvm
189 
190 #endif // TVM_META_SCHEDULE_SPACE_GENERATOR_H_
virtual ~SpaceGeneratorNode()=default
Default destructor.
runtime::TypedPackedFunc< SpaceGenerator()> FClone
The function type of Clone method.
Definition: space_generator.h:122
TVM_DECLARE_BASE_OBJECT_INFO(SpaceGeneratorNode, Object)
#define TVM_DEFINE_MUTABLE_NOTNULLABLE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName)
Definition: object.h:758
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:161
base class of all object containers.
Definition: object.h:167
Managed reference to TuneContextNode.
Definition: tune_context.h:135
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:72
virtual void InitializeWithTuneContext(const TuneContext &context)=0
Initialize the design space generator with tuning context.
runtime::TypedPackedFunc< void(const TuneContext &)> FInitializeWithTuneContext
The function type of InitializeWithTuneContext method.
Definition: space_generator.h:111
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:117
Base class of all object reference.
Definition: object.h:511
void VisitAttrs(tvm::AttrVisitor *v)
Definition: space_generator.h:173
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:352
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:167
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:171
FGenerateDesignSpace f_generate_design_space
The packed function to the GenerateDesignSpace function.
Definition: space_generator.h:169
static constexpr const char * _type_key
Definition: space_generator.h:97
Type-erased function used across TVM API.
Managed reference to SpaceGeneratorNode.
Definition: space_generator.h:105