tvm
mutator.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 
20 #ifndef TVM_META_SCHEDULE_MUTATOR_H_
21 #define TVM_META_SCHEDULE_MUTATOR_H_
22 
23 #include <tvm/node/reflection.h>
25 #include <tvm/runtime/object.h>
29 #include <tvm/tir/schedule/trace.h>
30 
31 namespace tvm {
32 namespace meta_schedule {
33 
34 class TuneContext;
35 class Mutator;
36 
38 class MutatorNode : public runtime::Object {
39  public:
41  virtual ~MutatorNode() = default;
42 
44 
50  virtual void InitializeWithTuneContext(const TuneContext& context) = 0;
51 
58  virtual Optional<tir::Trace> Apply(const tir::Trace& trace,
60 
65  virtual Mutator Clone() const = 0;
66 
67  static constexpr const char* _type_key = "meta_schedule.Mutator";
69 };
70 
75 class Mutator : public runtime::ObjectRef {
76  public:
100  TVM_DLL static Mutator MutateTileSize();
106  TVM_DLL static Mutator MutateParallel(int64_t max_jobs_per_core);
111  TVM_DLL static Mutator MutateUnroll();
116  TVM_DLL static Mutator MutateComputeLocation();
121  TVM_DLL static Mutator MutateThreadBinding();
130  TVM_DLL static Mutator PyMutator(FInitializeWithTuneContext f_initialize_with_tune_context,
131  FApply f_apply, FClone f_clone, FAsString f_as_string);
140 
142 };
143 
145 class PyMutatorNode : public MutatorNode {
146  public:
159 
161  // `f_initialize_with_tune_context` is not visited
162  // `f_apply` is not visited
163  // `f_clone` is not visited
164  // `f_as_string` is not visited
165  }
166 
167  void InitializeWithTuneContext(const TuneContext& context) final;
170  Mutator Clone() const final;
171 
172  static constexpr const char* _type_key = "meta_schedule.PyMutator";
174 };
175 
176 } // namespace meta_schedule
177 } // namespace tvm
178 
179 #endif // TVM_META_SCHEDULE_MUTATOR_H_
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
Mutator is designed to mutate the trace to explore the design space.
Definition: mutator.h:38
static constexpr const char * _type_key
Definition: mutator.h:67
virtual ~MutatorNode()=default
Virtual destructor.
TVM_DECLARE_BASE_OBJECT_INFO(MutatorNode, Object)
virtual void InitializeWithTuneContext(const TuneContext &context)=0
Initialize the design space generator with tuning context.
virtual Optional< tir::Trace > Apply(const tir::Trace &trace, support::LinearCongruentialEngine::TRandState *rand_state)=0
Apply the mutator function to the given trace.
virtual Mutator Clone() const =0
Clone the mutator.
void VisitAttrs(tvm::AttrVisitor *v)
Definition: mutator.h:43
Managed reference to MutatorNode.
Definition: mutator.h:75
static Mutator MutateThreadBinding()
Create a Mutator that mutates auto thread binding.
static Map< Mutator, FloatImm, void > DefaultLLVM()
Create default mutators for LLVM.
static Mutator MutateComputeLocation()
Create a Mutator that mutates the outcome of SampleComputeLocation.
static Map< Mutator, FloatImm, void > DefaultHexagon()
Create default mutators for Hexagon.
static Mutator MutateUnroll()
Create a Mutator that mutates auto unroll step.
static Map< Mutator, FloatImm, void > DefaultCUDA()
Create default mutators for CUDA.
TVM_DEFINE_MUTABLE_OBJECT_REF_METHODS(Mutator, ObjectRef, MutatorNode)
static Mutator MutateTileSize()
Create a Mutator that mutates the decision of instruction Sample-Perfect-Tile.
runtime::TypedPackedFunc< Mutator()> FClone
Clone the mutator.
Definition: mutator.h:93
static Mutator MutateParallel(int64_t max_jobs_per_core)
Create a Mutator that mutates the parallel extent.
static Mutator PyMutator(FInitializeWithTuneContext f_initialize_with_tune_context, FApply f_apply, FClone f_clone, FAsString f_as_string)
Create a mutator with customized methods on the python-side.
runtime::TypedPackedFunc< Optional< tir::Trace >(const tir::Trace &, support::LinearCongruentialEngine::TRandState rand_state)> FApply
Apply the mutator function to the given trace.
Definition: mutator.h:88
runtime::TypedPackedFunc< void(const TuneContext &)> FInitializeWithTuneContext
The function type of InitializeWithTuneContext method.
Definition: mutator.h:81
static Map< Mutator, FloatImm, void > DefaultCUDATensorCore()
Create default mutators for CUDA with TensorCore.
runtime::TypedPackedFunc< String()> FAsString
Get the mutator as string with name.
Definition: mutator.h:98
The mutator with customized methods on the python-side.
Definition: mutator.h:145
FInitializeWithTuneContext f_initialize_with_tune_context
The packed function to the InitializeWithTuneContext function.
Definition: mutator.h:152
FAsString f_as_string
The packed function to the AsString function.
Definition: mutator.h:158
FApply f_apply
The packed function to the Apply function.
Definition: mutator.h:154
void VisitAttrs(tvm::AttrVisitor *v)
Definition: mutator.h:160
void InitializeWithTuneContext(const TuneContext &context) final
Initialize the design space generator with tuning context.
Mutator Clone() const final
Clone the mutator.
static constexpr const char * _type_key
Definition: mutator.h:172
TVM_DECLARE_FINAL_OBJECT_INFO(PyMutatorNode, MutatorNode)
FClone f_clone
The packed function to the Clone function.
Definition: mutator.h:156
Optional< tir::Trace > Apply(const tir::Trace &trace, support::LinearCongruentialEngine::TRandState *rand_state) final
Apply the mutator function to the given trace.
Managed reference to TuneContextNode.
Definition: tune_context.h:95
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
Reference to string objects.
Definition: string.h:98
Please refer to TypedPackedFunc<R(Args..)>.
Definition: packed_func.h:63
int64_t TRandState
Definition: random_engine.h:46
Managed reference to TraceNode.
Definition: trace.h:141
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
A managed object in the TVM runtime.
Runtime Optional container types.
Type-erased function used across TVM API.
Random number generator. It provides a generic interface consistent with std::uniform_random_bit_gene...
Reflection and serialization of compiler IR/AST nodes.