tvm
Loading...
Searching...
No Matches
runner.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_S_TIR_META_SCHEDULE_RUNNER_H_
20#define TVM_S_TIR_META_SCHEDULE_RUNNER_H_
21
22#include <tvm/ffi/container/array.h>
23#include <tvm/ffi/function.h>
24#include <tvm/ffi/optional.h>
25#include <tvm/ffi/reflection/registry.h>
26#include <tvm/ffi/string.h>
27#include <tvm/ir/expr.h>
28#include <tvm/ir/prim/expr.h>
30
31namespace tvm {
32namespace s_tir {
33namespace meta_schedule {
34
36class RunnerInputObj : public ffi::Object {
37 public:
39 ffi::String artifact_path;
41 ffi::String device_type;
43 ffi::Array<ArgInfo> args_info;
44
45 static void RegisterReflection() {
46 namespace refl = tvm::ffi::reflection;
47 refl::ObjectDef<RunnerInputObj>()
48 .def_ro("artifact_path", &RunnerInputObj::artifact_path)
49 .def_ro("device_type", &RunnerInputObj::device_type)
50 .def_ro("args_info", &RunnerInputObj::args_info);
51 }
52 TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.meta_schedule.RunnerInput", RunnerInputObj, ffi::Object);
53};
54
59class RunnerInput : public ffi::ObjectRef {
60 public:
67 TVM_DLL explicit RunnerInput(ffi::String artifact_path, ffi::String device_type,
68 ffi::Array<ArgInfo> args_info);
70};
71
73class RunnerResultObj : public ffi::Object {
74 public:
76 ffi::Optional<ffi::Array<FloatImm>> run_secs;
78 ffi::Optional<ffi::String> error_msg;
79
80 static void RegisterReflection() {
81 namespace refl = tvm::ffi::reflection;
82 refl::ObjectDef<RunnerResultObj>()
83 .def_ro("run_secs", &RunnerResultObj::run_secs)
84 .def_ro("error_msg", &RunnerResultObj::error_msg);
85 }
86 TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.meta_schedule.RunnerResult", RunnerResultObj,
87 ffi::Object);
88};
89
94class RunnerResult : public ffi::ObjectRef {
95 public:
101 TVM_DLL explicit RunnerResult(ffi::Optional<ffi::Array<FloatImm>> run_secs,
102 ffi::Optional<ffi::String> error_msg);
104};
105
111class RunnerFutureObj : public ffi::Object {
112 public:
117 using FDone = ffi::TypedFunction<bool()>;
122 using FResult = ffi::TypedFunction<RunnerResult()>;
123
128
129 static void RegisterReflection() {
130 // `f_done` is not registered
131 // `f_result` is not registered
132 namespace refl = tvm::ffi::reflection;
133 refl::ObjectDef<RunnerFutureObj>();
134 }
135
140 bool Done() const {
141 TVM_FFI_ICHECK(f_done != nullptr) << "PyRunnerFuture's Done method not implemented!";
142 return f_done();
143 }
149 TVM_FFI_ICHECK(f_result != nullptr) << "PyRunnerFuture's Result method not implemented!";
150 return f_result();
151 }
152 TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.meta_schedule.RunnerFuture", RunnerFutureObj,
153 ffi::Object);
154};
155
160class RunnerFuture : public ffi::ObjectRef {
161 public:
164
170 TVM_DLL explicit RunnerFuture(FDone f_done, FResult f_result);
172};
173
175class RunnerObj : public ffi::Object {
176 public:
183 using FRun = ffi::TypedFunction<ffi::Array<RunnerFuture>(ffi::Array<RunnerInput>)>;
184
186 virtual ~RunnerObj() = default;
187
193 virtual ffi::Array<RunnerFuture> Run(ffi::Array<RunnerInput> runner_inputs) = 0;
194
195 static void RegisterReflection() {
196 namespace refl = tvm::ffi::reflection;
197 refl::ObjectDef<RunnerObj>();
198 }
199
200 static constexpr const bool _type_mutable = true;
201 TVM_FFI_DECLARE_OBJECT_INFO("s_tir.meta_schedule.Runner", RunnerObj, ffi::Object);
202};
203
208class Runner : public ffi::ObjectRef {
209 public:
215 explicit Runner(ffi::ObjectPtr<RunnerObj> data) : ffi::ObjectRef(data) {
216 TVM_FFI_ICHECK(data != nullptr);
217 }
223 TVM_DLL static Runner PyRunner(FRun f_run);
225};
226
228class PyRunnerObj : public RunnerObj {
229 public:
232
233 static void RegisterReflection() {
234 // `f_run` is not registered
235 namespace refl = tvm::ffi::reflection;
236 refl::ObjectDef<PyRunnerObj>();
237 }
238
239 ffi::Array<RunnerFuture> Run(ffi::Array<RunnerInput> runner_inputs) final {
240 TVM_FFI_ICHECK(f_run != nullptr) << "PyRunner's Run method not implemented!";
241 return f_run(runner_inputs);
242 }
243 TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.meta_schedule.PyRunner", PyRunnerObj, RunnerObj);
244};
245
246} // namespace meta_schedule
247} // namespace s_tir
248} // namespace tvm
249
250#endif // TVM_S_TIR_META_SCHEDULE_RUNNER_H_
An abstract runner with customized build method on the python-side.
Definition runner.h:228
ffi::Array< RunnerFuture > Run(ffi::Array< RunnerInput > runner_inputs) final
Run the built artifact and get runner futures.
Definition runner.h:239
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.meta_schedule.PyRunner", PyRunnerObj, RunnerObj)
static void RegisterReflection()
Definition runner.h:233
FRun f_run
The packed function to run the built artifacts and get runner futures.
Definition runner.h:231
A class to asynchronously fetch runner's output.
Definition runner.h:111
ffi::TypedFunction< bool()> FDone
The function type to check whether the runner has finished.
Definition runner.h:117
FDone f_done
The packed function to check whether the runner has finished.
Definition runner.h:125
static void RegisterReflection()
Definition runner.h:129
bool Done() const
Check whether the runner has finished.
Definition runner.h:140
RunnerResult Result() const
Fetch the runner's output if it is ready.
Definition runner.h:148
FResult f_result
The packed function to fetch runner output if it is ready.
Definition runner.h:127
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.meta_schedule.RunnerFuture", RunnerFutureObj, ffi::Object)
ffi::TypedFunction< RunnerResult()> FResult
The function type to fetch runner output if it is ready.
Definition runner.h:122
Managed reference to RunnerFutureObj.
Definition runner.h:160
RunnerFutureObj::FResult FResult
Definition runner.h:163
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(RunnerFuture, ffi::ObjectRef, RunnerFutureObj)
RunnerFuture(FDone f_done, FResult f_result)
Constructor of RunnerFuture.
RunnerFutureObj::FDone FDone
Definition runner.h:162
Runner's input containing path of artifact, type of device and argument info.
Definition runner.h:36
ffi::String device_type
The type of device.
Definition runner.h:41
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.meta_schedule.RunnerInput", RunnerInputObj, ffi::Object)
ffi::String artifact_path
The path to the built artifact.
Definition runner.h:39
static void RegisterReflection()
Definition runner.h:45
ffi::Array< ArgInfo > args_info
The argument information.
Definition runner.h:43
Managed reference to RunnerInputObj.
Definition runner.h:59
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(RunnerInput, ffi::ObjectRef, RunnerInputObj)
RunnerInput(ffi::String artifact_path, ffi::String device_type, ffi::Array< ArgInfo > args_info)
Constructor of RunnerInput.
The abstract runner interface.
Definition runner.h:175
virtual ~RunnerObj()=default
Default destructor.
static void RegisterReflection()
Definition runner.h:195
TVM_FFI_DECLARE_OBJECT_INFO("s_tir.meta_schedule.Runner", RunnerObj, ffi::Object)
virtual ffi::Array< RunnerFuture > Run(ffi::Array< RunnerInput > runner_inputs)=0
Run the built artifact and get runner futures.
static constexpr const bool _type_mutable
Definition runner.h:200
ffi::TypedFunction< ffi::Array< RunnerFuture >(ffi::Array< RunnerInput >)> FRun
The function type to run the built artifacts and get runner futures.
Definition runner.h:183
Runner's output containing measurement result of MeasureCandidate or error msg if any.
Definition runner.h:73
ffi::Optional< ffi::Array< FloatImm > > run_secs
The run time in seconds.
Definition runner.h:76
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.meta_schedule.RunnerResult", RunnerResultObj, ffi::Object)
ffi::Optional< ffi::String > error_msg
The error message, if any.
Definition runner.h:78
static void RegisterReflection()
Definition runner.h:80
Managed reference to RunnerResultObj.
Definition runner.h:94
RunnerResult(ffi::Optional< ffi::Array< FloatImm > > run_secs, ffi::Optional< ffi::String > error_msg)
Constructor.
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(RunnerResult, ffi::ObjectRef, RunnerResultObj)
Managed reference to RunnerObj.
Definition runner.h:208
RunnerObj::FRun FRun
Definition runner.h:210
static Runner PyRunner(FRun f_run)
Create a runner with customized build method on the python-side.
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(Runner, ffi::ObjectRef, RunnerObj)
Runner(ffi::ObjectPtr< RunnerObj > data)
Constructor from ffi::ObjectPtr<RunnerObj>.
Definition runner.h:215
Base expr nodes in TVM.
TIR expressions.
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition attr.h:23