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/base.h>
23#include <tvm/ffi/container/array.h>
24#include <tvm/ffi/function.h>
25#include <tvm/ffi/optional.h>
26#include <tvm/ffi/reflection/registry.h>
27#include <tvm/ffi/string.h>
28#include <tvm/ir/expr.h>
29#include <tvm/ir/prim/expr.h>
31
32namespace tvm {
33namespace s_tir {
34namespace meta_schedule {
35
37class RunnerInputObj : public ffi::Object {
38 public:
40 ffi::String artifact_path;
42 ffi::String device_type;
44 ffi::Array<ArgInfo> args_info;
45
46 static void RegisterReflection() {
47 namespace refl = tvm::ffi::reflection;
48 refl::ObjectDef<RunnerInputObj>()
49 .def_ro("artifact_path", &RunnerInputObj::artifact_path)
50 .def_ro("device_type", &RunnerInputObj::device_type)
51 .def_ro("args_info", &RunnerInputObj::args_info);
52 }
53 TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.meta_schedule.RunnerInput", RunnerInputObj, ffi::Object);
54};
55
60class RunnerInput : public ffi::ObjectRef {
61 public:
68 TVM_DLL explicit RunnerInput(ffi::String artifact_path, ffi::String device_type,
69 ffi::Array<ArgInfo> args_info);
71};
72
74class RunnerResultObj : public ffi::Object {
75 public:
77 ffi::Optional<ffi::Array<FloatImm>> run_secs;
79 ffi::Optional<ffi::String> error_msg;
80
81 static void RegisterReflection() {
82 namespace refl = tvm::ffi::reflection;
83 refl::ObjectDef<RunnerResultObj>()
84 .def_ro("run_secs", &RunnerResultObj::run_secs)
85 .def_ro("error_msg", &RunnerResultObj::error_msg);
86 }
87 TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.meta_schedule.RunnerResult", RunnerResultObj,
88 ffi::Object);
89};
90
95class RunnerResult : public ffi::ObjectRef {
96 public:
102 TVM_DLL explicit RunnerResult(ffi::Optional<ffi::Array<FloatImm>> run_secs,
103 ffi::Optional<ffi::String> error_msg);
105};
106
112class RunnerFutureObj : public ffi::Object {
113 public:
118 using FDone = ffi::TypedFunction<bool()>;
123 using FResult = ffi::TypedFunction<RunnerResult()>;
124
129
130 static void RegisterReflection() {
131 // `f_done` is not registered
132 // `f_result` is not registered
133 namespace refl = tvm::ffi::reflection;
134 refl::ObjectDef<RunnerFutureObj>();
135 }
136
141 bool Done() const {
142 TVM_FFI_ICHECK(f_done != nullptr) << "PyRunnerFuture's Done method not implemented!";
143 return f_done();
144 }
150 TVM_FFI_ICHECK(f_result != nullptr) << "PyRunnerFuture's Result method not implemented!";
151 return f_result();
152 }
153 TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.meta_schedule.RunnerFuture", RunnerFutureObj,
154 ffi::Object);
155};
156
161class RunnerFuture : public ffi::ObjectRef {
162 public:
165
171 TVM_DLL explicit RunnerFuture(FDone f_done, FResult f_result);
173};
174
176class RunnerObj : public ffi::Object {
177 public:
184 using FRun = ffi::TypedFunction<ffi::Array<RunnerFuture>(ffi::Array<RunnerInput>)>;
185
187 virtual ~RunnerObj() = default;
188
194 virtual ffi::Array<RunnerFuture> Run(ffi::Array<RunnerInput> runner_inputs) = 0;
195
196 static void RegisterReflection() {
197 namespace refl = tvm::ffi::reflection;
198 refl::ObjectDef<RunnerObj>();
199 }
200
201 static constexpr const bool _type_mutable = true;
202 TVM_FFI_DECLARE_OBJECT_INFO("s_tir.meta_schedule.Runner", RunnerObj, ffi::Object);
203};
204
209class Runner : public ffi::ObjectRef {
210 public:
216 explicit Runner(ffi::ObjectPtr<RunnerObj> data) : ffi::ObjectRef(data) {
217 TVM_FFI_ICHECK(data != nullptr);
218 }
224 TVM_DLL static Runner PyRunner(FRun f_run);
226};
227
229class PyRunnerObj : public RunnerObj {
230 public:
233
234 static void RegisterReflection() {
235 // `f_run` is not registered
236 namespace refl = tvm::ffi::reflection;
237 refl::ObjectDef<PyRunnerObj>();
238 }
239
240 ffi::Array<RunnerFuture> Run(ffi::Array<RunnerInput> runner_inputs) final {
241 TVM_FFI_ICHECK(f_run != nullptr) << "PyRunner's Run method not implemented!";
242 return f_run(runner_inputs);
243 }
244 TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.meta_schedule.PyRunner", PyRunnerObj, RunnerObj);
245};
246
247} // namespace meta_schedule
248} // namespace s_tir
249} // namespace tvm
250
251#endif // TVM_S_TIR_META_SCHEDULE_RUNNER_H_
Base expr nodes in TVM.
TIR expressions.
An abstract runner with customized build method on the python-side.
Definition runner.h:229
ffi::Array< RunnerFuture > Run(ffi::Array< RunnerInput > runner_inputs) final
Run the built artifact and get runner futures.
Definition runner.h:240
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.meta_schedule.PyRunner", PyRunnerObj, RunnerObj)
static void RegisterReflection()
Definition runner.h:234
FRun f_run
The packed function to run the built artifacts and get runner futures.
Definition runner.h:232
A class to asynchronously fetch runner's output.
Definition runner.h:112
ffi::TypedFunction< bool()> FDone
The function type to check whether the runner has finished.
Definition runner.h:118
FDone f_done
The packed function to check whether the runner has finished.
Definition runner.h:126
static void RegisterReflection()
Definition runner.h:130
bool Done() const
Check whether the runner has finished.
Definition runner.h:141
RunnerResult Result() const
Fetch the runner's output if it is ready.
Definition runner.h:149
FResult f_result
The packed function to fetch runner output if it is ready.
Definition runner.h:128
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:123
Managed reference to RunnerFutureObj.
Definition runner.h:161
RunnerFutureObj::FResult FResult
Definition runner.h:164
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:163
Runner's input containing path of artifact, type of device and argument info.
Definition runner.h:37
ffi::String device_type
The type of device.
Definition runner.h:42
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:40
static void RegisterReflection()
Definition runner.h:46
ffi::Array< ArgInfo > args_info
The argument information.
Definition runner.h:44
Managed reference to RunnerInputObj.
Definition runner.h:60
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:176
virtual ~RunnerObj()=default
Default destructor.
static void RegisterReflection()
Definition runner.h:196
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:201
ffi::TypedFunction< ffi::Array< RunnerFuture >(ffi::Array< RunnerInput >)> FRun
The function type to run the built artifacts and get runner futures.
Definition runner.h:184
Runner's output containing measurement result of MeasureCandidate or error msg if any.
Definition runner.h:74
ffi::Optional< ffi::Array< FloatImm > > run_secs
The run time in seconds.
Definition runner.h:77
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:79
static void RegisterReflection()
Definition runner.h:81
Managed reference to RunnerResultObj.
Definition runner.h:95
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:209
RunnerObj::FRun FRun
Definition runner.h:211
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:216
Parent compiler symbol visibility.
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition analysis.h:41