tvm
task_scheduler.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_TASK_SCHEDULER_H_
20 #define TVM_META_SCHEDULE_TASK_SCHEDULER_H_
21 
26 
27 namespace tvm {
28 namespace meta_schedule {
29 
67  public:
71  Builder builder{nullptr};
73  Runner runner{nullptr};
75  Database database{nullptr};
76 
78  virtual ~TaskSchedulerNode() = default;
79 
81  v->Visit("tasks", &tasks);
82  v->Visit("builder", &builder);
83  v->Visit("runner", &runner);
84  v->Visit("database", &database);
85  }
86 
88  virtual void Tune();
89 
94  virtual void InitializeTask(int task_id);
95 
100  virtual void SetTaskStopped(int task_id);
101 
107  virtual bool IsTaskRunning(int task_id);
108 
113  virtual void JoinRunningTask(int task_id);
114 
119  virtual int NextTaskId() = 0;
120 
121  static constexpr const char* _type_key = "meta_schedule.TaskScheduler";
123 };
124 
125 class TaskScheduler;
126 
129  public:
132 
135 
141 
148 
154 
160 
173 
175  // `f_tune` is not visited
176  // `f_initialize_task` is not visited
177  // `f_set_task_stopped` is not visited
178  // `f_is_task_running` is not visited
179  // `f_join_running_task` is not visited
180  // `f_next_task_id` is not visited
181  }
182 
183  void Tune() final {
184  if (f_tune == nullptr) {
186  } else {
187  f_tune();
188  }
189  }
190 
191  void InitializeTask(int task_id) final {
192  if (f_initialize_task == nullptr) {
194  } else {
195  f_initialize_task(task_id);
196  }
197  }
198 
199  void SetTaskStopped(int task_id) final {
200  if (f_set_task_stopped == nullptr) {
202  } else {
203  f_set_task_stopped(task_id);
204  }
205  }
206 
207  bool IsTaskRunning(int task_id) final {
208  if (f_is_task_running == nullptr) {
209  return TaskSchedulerNode::IsTaskRunning(task_id);
210  } else {
211  return f_is_task_running(task_id);
212  }
213  }
214 
215  void JoinRunningTask(int task_id) final {
216  if (f_join_running_task == nullptr) {
217  return TaskSchedulerNode::JoinRunningTask(task_id);
218  } else {
219  return f_join_running_task(task_id);
220  }
221  }
222 
223  int NextTaskId() final {
224  ICHECK(f_next_task_id != nullptr) << "PyTaskScheduler's NextTaskId method not implemented!";
225  return f_next_task_id();
226  }
227 
228  static constexpr const char* _type_key = "meta_schedule.PyTaskScheduler";
230 };
231 
237  public:
245  TVM_DLL static TaskScheduler RoundRobin(Array<TuneContext> tasks, //
246  Builder builder, //
247  Runner runner, //
248  Database database); //
249  TVM_DLL static TaskScheduler PyTaskScheduler(
250  Array<TuneContext> tasks, //
251  Builder builder, //
252  Runner runner, //
253  Database database, //
254  PyTaskSchedulerNode::FTune f_tune, //
255  PyTaskSchedulerNode::FInitializeTask f_initialize_task, //
256  PyTaskSchedulerNode::FSetTaskStopped f_set_task_stopped, //
257  PyTaskSchedulerNode::FIsTaskRunning f_is_task_running, //
258  PyTaskSchedulerNode::FJoinRunningTask f_join_running_task, //
259  PyTaskSchedulerNode::FNextTaskId f_next_task_id);
261 };
262 
263 } // namespace meta_schedule
264 } // namespace tvm
265 
266 #endif // TVM_META_SCHEDULE_TASK_SCHEDULER_H_
FIsTaskRunning f_is_task_running
The packed function to the IsTaskRunning function.
Definition: task_scheduler.h:168
virtual int NextTaskId()=0
Fetch the next task id.
virtual bool IsTaskRunning(int task_id)
Check whether the task is running.
Runner runner
The runner of the scheduler.
Definition: task_scheduler.h:73
#define TVM_DEFINE_MUTABLE_NOTNULLABLE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName)
Definition: object.h:751
int NextTaskId() final
Fetch the next task id.
Definition: task_scheduler.h:223
void Tune() final
Auto-tuning.
Definition: task_scheduler.h:183
virtual void InitializeTask(int task_id)
Initialize modules of the given task.
FInitializeTask f_initialize_task
The packed function to the InitializeTask funcion.
Definition: task_scheduler.h:164
Performance counters for profiling via the PAPI library.
Definition: analyzer.h:36
Managed reference to TaskSchedulerNode.
Definition: task_scheduler.h:236
virtual void SetTaskStopped(int task_id)
Set specific task to be stopped.
void JoinRunningTask(int task_id) final
Wait until the task is finished.
Definition: task_scheduler.h:215
The task scheduler with customized methods on the python-side.
Definition: task_scheduler.h:128
base class of all object containers.
Definition: object.h:165
void InitializeTask(int task_id) final
Initialize modules of the given task.
Definition: task_scheduler.h:191
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
Managed reference to DatabaseNode.
Definition: database.h:262
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:270
virtual void JoinRunningTask(int task_id)
Wait until the task is finished.
Managed reference to BuilderNode.
Definition: builder.h:118
void SetTaskStopped(int task_id) final
Set specific task to be stopped.
Definition: task_scheduler.h:199
virtual void Tune()
Auto-tuning.
FNextTaskId f_next_task_id
The packed function to the NextTaskId function.
Definition: task_scheduler.h:172
void VisitAttrs(tvm::AttrVisitor *v)
Definition: task_scheduler.h:80
Base class of all object reference.
Definition: object.h:504
virtual ~TaskSchedulerNode()=default
The default desctructor.
Builder builder
The builder of the scheduler.
Definition: task_scheduler.h:71
FSetTaskStopped f_set_task_stopped
The packed function to the SetTaskStopped function.
Definition: task_scheduler.h:166
#define TVM_DECLARE_FINAL_OBJECT_INFO(TypeName, ParentType)
helper macro to declare type information in a final class.
Definition: object.h:664
Array< TuneContext > tasks
The tasks to be tuned.
Definition: task_scheduler.h:69
Managed reference to RunnerNode.
Definition: runner.h:187
FJoinRunningTask f_join_running_task
The packed function to the JoinRunningTask function.
Definition: task_scheduler.h:170
void VisitAttrs(tvm::AttrVisitor *v)
Definition: task_scheduler.h:174
The abstract interface of task schedulers.
Definition: task_scheduler.h:66
Database database
The database of the scheduler.
Definition: task_scheduler.h:75
static constexpr const char * _type_key
Definition: task_scheduler.h:121
bool IsTaskRunning(int task_id) final
Check whether the task is running.
Definition: task_scheduler.h:207
FTune f_tune
The packed function to the Tune funcion.
Definition: task_scheduler.h:162
TVM_DECLARE_BASE_OBJECT_INFO(TaskSchedulerNode, Object)