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 
37 class MutatorNode : public runtime::Object {
38  public:
40  virtual ~MutatorNode() = default;
41 
43 
49  virtual void InitializeWithTuneContext(const TuneContext& context) = 0;
50 
57  virtual Optional<tir::Trace> Apply(const tir::Trace& trace,
59 
60  static constexpr const char* _type_key = "meta_schedule.Mutator";
62 };
63 
65 class PyMutatorNode : public MutatorNode {
66  public:
84 
91 
93  // `f_initialize_with_tune_context` is not visited
94  // `f_apply` is not visited
95  // `f_as_string` is not visited
96  }
97 
98  void InitializeWithTuneContext(const TuneContext& context) final;
101 
102  static constexpr const char* _type_key = "meta_schedule.PyMutator";
104 };
105 
110 class Mutator : public runtime::ObjectRef {
111  public:
113  TVM_DLL static Mutator MutateTileSize();
119  TVM_DLL static Mutator MutateParallel(int64_t max_jobs_per_core);
124  TVM_DLL static Mutator MutateUnroll();
129  TVM_DLL static Mutator MutateComputeLocation();
134  TVM_DLL static Mutator MutateThreadBinding();
142  TVM_DLL static Mutator PyMutator(
143  PyMutatorNode::FInitializeWithTuneContext f_initialize_with_tune_context, //
144  PyMutatorNode::FApply f_apply, //
145  PyMutatorNode::FAsString f_as_string);
147 };
148 
149 } // namespace meta_schedule
150 } // namespace tvm
151 
152 #endif // TVM_META_SCHEDULE_MUTATOR_H_
Runtime Optional container types.
Random number generator. It provides a generic interface consistent with std::uniform_random_bit_gene...
static constexpr const char * _type_key
Definition: mutator.h:60
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
virtual Optional< tir::Trace > Apply(const tir::Trace &trace, support::LinearCongruentialEngine::TRandState *rand_state)=0
Apply the mutator function to the given trace.
Mutator is designed to mutate the trace to explore the design space.
Definition: mutator.h:37
FApply f_apply
The packed function to the Apply function.
Definition: mutator.h:88
TVM_DECLARE_BASE_OBJECT_INFO(MutatorNode, Object)
FInitializeWithTuneContext f_initialize_with_tune_context
The packed function to the InitializeWithTuneContext function.
Definition: mutator.h:86
virtual ~MutatorNode()=default
Virtual destructor.
base class of all object containers.
Definition: object.h:167
#define TVM_DEFINE_MUTABLE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName)
Definition: object.h:744
void VisitAttrs(tvm::AttrVisitor *v)
Definition: mutator.h:42
Managed reference to TuneContextNode.
Definition: tune_context.h:129
int64_t TRandState
Definition: random_engine.h:54
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
void VisitAttrs(tvm::AttrVisitor *v)
Definition: mutator.h:92
The mutator with customized methods on the python-side.
Definition: mutator.h:65
virtual void InitializeWithTuneContext(const TuneContext &context)=0
Initialize the design space generator with tuning context.
Base class of all object reference.
Definition: object.h:511
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 to TraceNode.
Definition: trace.h:141
Optional container that to represent to a Nullable variant of T.
Definition: optional.h:51
Reflection and serialization of compiler IR/AST nodes.
Managed reference to MutatorNode.
Definition: mutator.h:110
Type-erased function used across TVM API.
FAsString f_as_string
The packed function to the AsString function.
Definition: mutator.h:90