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>
24 
25 namespace tvm {
26 namespace meta_schedule {
27 
28 // Forward declaration
29 class TuneContext;
30 
67 class SpaceGeneratorNode : public Object {
68  public:
70  virtual ~SpaceGeneratorNode() = default;
71 
77  virtual void InitializeWithTuneContext(const TuneContext& tune_context) = 0;
78 
85 
86  static constexpr const char* _type_key = "meta_schedule.SpaceGenerator";
88 };
89 
92  public:
104 
109 
111  // `f_initialize_with_tune_context` is not visited
112  // `f_generate_design_space` is not visited
113  }
114 
115  void InitializeWithTuneContext(const TuneContext& tune_context) final {
116  ICHECK(f_initialize_with_tune_context != nullptr)
117  << "PySpaceGenerator's InitializeWithTuneContext !";
118  f_initialize_with_tune_context(tune_context);
119  }
120 
122  ICHECK(f_generate_design_space != nullptr)
123  << "PySpaceGenerator's GenerateDesignSpace method not implemented!";
124  return f_generate_design_space(mod);
125  }
126 
127  static constexpr const char* _type_key = "meta_schedule.PySpaceGenerator";
129 };
130 
135 class SpaceGenerator : public ObjectRef {
136  protected:
137  SpaceGenerator() = default;
138 
139  public:
146  TVM_DLL static SpaceGenerator PySpaceGenerator(
147  PySpaceGeneratorNode::FInitializeWithTuneContext initialize_with_tune_context_func,
148  PySpaceGeneratorNode::FGenerateDesignSpace generate_design_space_func);
149 
155  TVM_DLL static SpaceGenerator SpaceGeneratorUnion(Array<SpaceGenerator, void> space_generators);
157 };
158 
159 } // namespace meta_schedule
160 } // namespace tvm
161 
162 #endif // TVM_META_SCHEDULE_SPACE_GENERATOR_H_
virtual ~SpaceGeneratorNode()=default
Default destructor.
TVM_DECLARE_BASE_OBJECT_INFO(SpaceGeneratorNode, Object)
#define TVM_DEFINE_MUTABLE_NOTNULLABLE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName)
Definition: object.h:751
Array< tir::Schedule > GenerateDesignSpace(const IRModule &mod) final
Generate design spaces given a module.
Definition: space_generator.h:121
IRModule that holds the functions and type definitions.
Performance counters for profiling via the PAPI library.
Definition: analyzer.h:36
The design space generator with customized methods on the python-side.
Definition: space_generator.h:91
base class of all object containers.
Definition: object.h:165
Managed reference to TuneContextNode.
Definition: tune_context.h:76
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:67
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:270
virtual void InitializeWithTuneContext(const TuneContext &tune_context)=0
Initialize the design space generator with tuning context.
Base class of all object reference.
Definition: object.h:504
void VisitAttrs(tvm::AttrVisitor *v)
Definition: space_generator.h:110
#define TVM_DECLARE_FINAL_OBJECT_INFO(TypeName, ParentType)
helper macro to declare type information in a final class.
Definition: object.h:664
Managed reference class to IRModuleNode.
Definition: module.h:352
void InitializeWithTuneContext(const TuneContext &tune_context) final
Initialize the design space generator with tuning context.
Definition: space_generator.h:115
FInitializeWithTuneContext f_initialize_with_tune_context
The packed function to the InitializeWithTuneContext funcion.
Definition: space_generator.h:106
tvm::PrimExpr mod(const tvm::PrimExpr &a, const tvm::PrimExpr &b)
Definition: broadcast.h:271
FGenerateDesignSpace f_generate_design_space
The packed function to the GenerateDesignSpace function.
Definition: space_generator.h:108
static constexpr const char * _type_key
Definition: space_generator.h:86
Managed reference to SpaceGeneratorNode.
Definition: space_generator.h:135