tvm
Loading...
Searching...
No Matches
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_S_TIR_META_SCHEDULE_MUTATOR_H_
21#define TVM_S_TIR_META_SCHEDULE_MUTATOR_H_
22
23#include <tvm/ffi/function.h>
24#include <tvm/ffi/optional.h>
25#include <tvm/ffi/reflection/registry.h>
26#include <tvm/ir/prim/expr.h>
27#include <tvm/runtime/base.h>
31
32namespace tvm {
33namespace s_tir {
34using namespace tvm::prim;
35namespace meta_schedule {
36
37class TuneContext;
38class Mutator;
39
41class MutatorNode : public ffi::Object {
42 public:
44 virtual ~MutatorNode() = default;
45
46 static void RegisterReflection() {
47 namespace refl = tvm::ffi::reflection;
48 refl::ObjectDef<MutatorNode>();
49 }
50
57
64 virtual ffi::Optional<s_tir::Trace> Apply(const s_tir::Trace& trace,
66
71 virtual Mutator Clone() const = 0;
72
73 static constexpr const bool _type_mutable = true;
74 TVM_FFI_DECLARE_OBJECT_INFO("s_tir.meta_schedule.Mutator", MutatorNode, ffi::Object);
75};
76
81class Mutator : public ffi::ObjectRef {
82 public:
87 using FInitializeWithTuneContext = ffi::TypedFunction<void(const TuneContext&)>;
93 using FApply = ffi::TypedFunction<ffi::Optional<s_tir::Trace>(
99 using FClone = ffi::TypedFunction<Mutator()>;
130 TVM_DLL static Mutator PyMutator(FInitializeWithTuneContext f_initialize_with_tune_context,
131 FApply f_apply, FClone f_clone);
133 TVM_DLL static ffi::Map<Mutator, FloatImm, void> DefaultLLVM();
135 TVM_DLL static ffi::Map<Mutator, FloatImm, void> DefaultCUDA();
137 TVM_DLL static ffi::Map<Mutator, FloatImm, void> DefaultCUDATensorCore();
139 TVM_DLL static ffi::Map<Mutator, FloatImm, void> DefaultHexagon();
140
142};
143
146 public:
156
157 static void RegisterReflection() {
158 namespace refl = tvm::ffi::reflection;
159 refl::ObjectDef<PyMutatorNode>();
160 // `f_initialize_with_tune_context` is not registered
161 // `f_apply` is not registered
162 // `f_clone` is not registered
163 }
164
166 ffi::Optional<s_tir::Trace> Apply(const s_tir::Trace& trace,
167 LinearCongruentialEngine::TRandState* rand_state) final;
170};
171
172} // namespace meta_schedule
173} // namespace s_tir
174} // namespace tvm
175
176#endif // TVM_S_TIR_META_SCHEDULE_MUTATOR_H_
RAII wrapper function to enter and exit a context object similar to python's with syntax.
Definition with_context.h:59
int64_t TRandState
Definition random_engine.h:49
Managed reference to TraceNode.
Definition trace.h:146
Mutator is designed to mutate the trace to explore the design space.
Definition mutator.h:41
static constexpr const bool _type_mutable
Definition mutator.h:73
TVM_FFI_DECLARE_OBJECT_INFO("s_tir.meta_schedule.Mutator", MutatorNode, ffi::Object)
static void RegisterReflection()
Definition mutator.h:46
virtual void InitializeWithTuneContext(const TuneContext &context)=0
Initialize the design space generator with tuning context.
virtual Mutator Clone() const =0
Clone the mutator.
virtual ffi::Optional< s_tir::Trace > Apply(const s_tir::Trace &trace, LinearCongruentialEngine::TRandState *rand_state)=0
Apply the mutator function to the given trace.
virtual ~MutatorNode()=default
Virtual destructor.
Managed reference to MutatorNode.
Definition mutator.h:81
static ffi::Map< Mutator, FloatImm, void > DefaultCUDATensorCore()
Create default mutators for CUDA with TensorCore.
ffi::TypedFunction< ffi::Optional< s_tir::Trace >(const s_tir::Trace &, LinearCongruentialEngine::TRandState rand_state)> FApply
Apply the mutator function to the given trace.
Definition mutator.h:94
static ffi::Map< Mutator, FloatImm, void > DefaultHexagon()
Create default mutators for Hexagon.
ffi::TypedFunction< Mutator()> FClone
Clone the mutator.
Definition mutator.h:99
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(Mutator, ffi::ObjectRef, MutatorNode)
static Mutator MutateThreadBinding()
Create a Mutator that mutates auto thread binding.
static Mutator MutateParallel(int64_t max_jobs_per_core)
Create a Mutator that mutates the parallel extent.
static ffi::Map< Mutator, FloatImm, void > DefaultLLVM()
Create default mutators for LLVM.
static ffi::Map< Mutator, FloatImm, void > DefaultCUDA()
Create default mutators for CUDA.
static Mutator PyMutator(FInitializeWithTuneContext f_initialize_with_tune_context, FApply f_apply, FClone f_clone)
Create a mutator with customized methods on the python-side.
static Mutator MutateUnroll()
Create a Mutator that mutates auto unroll step.
static Mutator MutateComputeLocation()
Create a Mutator that mutates the outcome of SampleComputeLocation.
ffi::TypedFunction< void(const TuneContext &)> FInitializeWithTuneContext
The function type of InitializeWithTuneContext method.
Definition mutator.h:87
static Mutator MutateTileSize()
Create a Mutator that mutates the decision of instruction Sample-Perfect-Tile.
The mutator with customized methods on the python-side.
Definition mutator.h:145
Mutator Clone() const final
Clone the mutator.
FInitializeWithTuneContext f_initialize_with_tune_context
The packed function to the InitializeWithTuneContext function.
Definition mutator.h:151
static void RegisterReflection()
Definition mutator.h:157
ffi::Optional< s_tir::Trace > Apply(const s_tir::Trace &trace, LinearCongruentialEngine::TRandState *rand_state) final
Apply the mutator function to the given trace.
FApply f_apply
The packed function to the Apply function.
Definition mutator.h:153
Mutator::FApply FApply
Definition mutator.h:148
FClone f_clone
The packed function to the Clone function.
Definition mutator.h:155
void InitializeWithTuneContext(const TuneContext &context) final
Initialize the design space generator with tuning context.
Mutator::FInitializeWithTuneContext FInitializeWithTuneContext
Definition mutator.h:147
Mutator::FClone FClone
Definition mutator.h:149
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.meta_schedule.PyMutator", PyMutatorNode, MutatorNode)
Managed reference to TuneContextNode.
Definition tune_context.h:101
TIR expressions.
Definition builtin.h:25
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition analyzer.h:40
Random number generator. It provides a generic interface consistent with std::uniform_random_bit_gene...