tvm
tune_context.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_TUNE_CONTEXT_H_
20 #define TVM_META_SCHEDULE_TUNE_CONTEXT_H_
21 
22 #include <tvm/ir/expr.h>
23 #include <tvm/ir/module.h>
31 #include <tvm/node/reflection.h>
36 #include <tvm/runtime/object.h>
39 #include <tvm/target/target.h>
40 
41 namespace tvm {
42 namespace meta_schedule {
43 
44 class TaskSchedulerNode;
45 class MeasureCallback;
46 
49  public:
72 
74  bool is_terminated; // TODO(@junrushao1994): move to TaskScheduler
81 
83  v->Visit("mod", &mod);
84  v->Visit("target", &target);
85  v->Visit("space_generator", &space_generator);
86  v->Visit("search_strategy", &search_strategy);
87  v->Visit("sch_rules", &sch_rules);
88  v->Visit("postprocs", &postprocs);
89  v->Visit("mutator_probs", &mutator_probs);
90  v->Visit("task_name", &task_name);
91  // `logging_func` is not visited
92  v->Visit("rand_state", &rand_state);
93  v->Visit("num_threads", &num_threads);
94  v->Visit("is_terminated", &is_terminated);
95  v->Visit("measure_candidates", &measure_candidates);
96  v->Visit("builder_results", &builder_results);
97  v->Visit("runner_futures", &runner_futures);
98  }
99 
101  void Initialize();
103  void _SetMeasureCandidates(const Array<MeasureCandidate>& candidates);
108  void _SendToBuilder(const Builder& builder);
113  void _SendToRunner(const Runner& runner);
120  void _ClearMeasureState();
121  static constexpr const char* _type_key = "meta_schedule.TuneContext";
123 };
124 
130  public:
145  TVM_DLL explicit TuneContext(Optional<IRModule> mod, //
155  int num_threads);
157 };
158 
159 } // namespace meta_schedule
160 } // namespace tvm
161 
162 #endif // TVM_META_SCHEDULE_TUNE_CONTEXT_H_
void _SendToBuilder(const Builder &builder)
Send the measure candidates to builder.
Array< ScheduleRule > sch_rules
The schedule rules.
Definition: tune_context.h:59
Optional< Target > target
The target to be tuned for.
Definition: tune_context.h:53
Runtime Optional container types.
#define TVM_DEFINE_MUTABLE_NOTNULLABLE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName)
Definition: object.h:758
void Initialize()
Initialize members that needs initialization with tune context.
void _SetMeasureCandidates(const Array< MeasureCandidate > &candidates)
Set the measure candidates from the SearchStrategy.
Runtime String container types.
Random number generator. It provides a generic interface consistent with std::uniform_random_bit_gene...
Optional< Array< MeasureCandidate > > measure_candidates
The measure candidates.
Definition: tune_context.h:76
Base expr nodes in TVM.
IRModule that holds the functions and type definitions.
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
void _ClearMeasureState()
Set measure_candidates, builder_results and runner_futures to null.
support::LinearCongruentialEngine::TRandState rand_state
The random state.
Definition: tune_context.h:69
Optional< String > task_name
The name of the tuning task.
Definition: tune_context.h:65
base class of all object containers.
Definition: object.h:167
Optional< SpaceGenerator > space_generator
The design space generator.
Definition: tune_context.h:55
Optional< IRModule > mod
The workload to be tuned.
Definition: tune_context.h:51
Managed reference to TuneContextNode.
Definition: tune_context.h:129
int64_t TRandState
Definition: random_engine.h:54
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
Array< Postproc > postprocs
The postprocessors.
Definition: tune_context.h:61
int num_threads
The number of threads to be used.
Definition: tune_context.h:71
Optional< SearchStrategy > search_strategy
The search strategy.
Definition: tune_context.h:57
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:270
Array< RunnerResult > _Join()
Join the running tasks.
The auto tuning context.
Definition: tune_context.h:48
bool is_terminated
Whether the tuning task has been stopped or finished.
Definition: tune_context.h:74
TVM_DECLARE_FINAL_OBJECT_INFO(TuneContextNode, Object)
Managed reference to BuilderNode.
Definition: builder.h:131
void VisitAttrs(tvm::AttrVisitor *v)
Definition: tune_context.h:82
Base class of all object reference.
Definition: object.h:511
PackedFunc logging_func
The tuning task&#39;s logging function. t.
Definition: tune_context.h:67
A managed object in the TVM runtime.
Managed reference to RunnerNode.
Definition: runner.h:199
Map< Mutator, FloatImm > mutator_probs
The probability of using certain mutator.
Definition: tune_context.h:63
static constexpr const char * _type_key
Definition: tune_context.h:121
Optional< Array< BuilderResult > > builder_results
The building results.
Definition: tune_context.h:78
Compilation target object.
Map container of NodeRef->NodeRef in DSL graph. Map implements copy on write semantics, which means map is mutable but copy will happen when array is referenced in more than two places.
Definition: map.h:1268
Runtime Map container types.
Optional< Array< RunnerFuture > > runner_futures
Packed functions to fetch the runner results asynchronously.
Definition: tune_context.h:80
Packed function is a type-erased function. The arguments are passed by packed format.
Definition: packed_func.h:138
Optional container that to represent to a Nullable variant of T.
Definition: optional.h:51
void _SendToRunner(const Runner &runner)
Send the built measure candidates to runner.
Reflection and serialization of compiler IR/AST nodes.
Type-erased function used across TVM API.