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 {
33using namespace tvm::prim;
34namespace meta_schedule {
35
37class RunnerInputNode : 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<RunnerInputNode>()
49 .def_ro("artifact_path", &RunnerInputNode::artifact_path)
50 .def_ro("device_type", &RunnerInputNode::device_type)
51 .def_ro("args_info", &RunnerInputNode::args_info);
52 }
53 TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.meta_schedule.RunnerInput", RunnerInputNode,
54 ffi::Object);
55};
56
61class RunnerInput : public ffi::ObjectRef {
62 public:
69 TVM_DLL explicit RunnerInput(ffi::String artifact_path, ffi::String device_type,
70 ffi::Array<ArgInfo> args_info);
72};
73
75class RunnerResultNode : public ffi::Object {
76 public:
78 ffi::Optional<ffi::Array<FloatImm>> run_secs;
80 ffi::Optional<ffi::String> error_msg;
81
82 static void RegisterReflection() {
83 namespace refl = tvm::ffi::reflection;
84 refl::ObjectDef<RunnerResultNode>()
85 .def_ro("run_secs", &RunnerResultNode::run_secs)
86 .def_ro("error_msg", &RunnerResultNode::error_msg);
87 }
88 TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.meta_schedule.RunnerResult", RunnerResultNode,
89 ffi::Object);
90};
91
96class RunnerResult : public ffi::ObjectRef {
97 public:
103 TVM_DLL explicit RunnerResult(ffi::Optional<ffi::Array<FloatImm>> run_secs,
104 ffi::Optional<ffi::String> error_msg);
106};
107
113class RunnerFutureNode : public ffi::Object {
114 public:
119 using FDone = ffi::TypedFunction<bool()>;
124 using FResult = ffi::TypedFunction<RunnerResult()>;
125
130
131 static void RegisterReflection() {
132 // `f_done` is not registered
133 // `f_result` is not registered
134 namespace refl = tvm::ffi::reflection;
135 refl::ObjectDef<RunnerFutureNode>();
136 }
137
142 bool Done() const {
143 TVM_FFI_ICHECK(f_done != nullptr) << "PyRunnerFuture's Done method not implemented!";
144 return f_done();
145 }
151 TVM_FFI_ICHECK(f_result != nullptr) << "PyRunnerFuture's Result method not implemented!";
152 return f_result();
153 }
154 TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.meta_schedule.RunnerFuture", RunnerFutureNode,
155 ffi::Object);
156};
157
162class RunnerFuture : public ffi::ObjectRef {
163 public:
166
172 TVM_DLL explicit RunnerFuture(FDone f_done, FResult f_result);
174};
175
177class RunnerNode : public ffi::Object {
178 public:
185 using FRun = ffi::TypedFunction<ffi::Array<RunnerFuture>(ffi::Array<RunnerInput>)>;
186
188 virtual ~RunnerNode() = default;
189
195 virtual ffi::Array<RunnerFuture> Run(ffi::Array<RunnerInput> runner_inputs) = 0;
196
197 static void RegisterReflection() {
198 namespace refl = tvm::ffi::reflection;
199 refl::ObjectDef<RunnerNode>();
200 }
201
202 static constexpr const bool _type_mutable = true;
203 TVM_FFI_DECLARE_OBJECT_INFO("s_tir.meta_schedule.Runner", RunnerNode, ffi::Object);
204};
205
210class Runner : public ffi::ObjectRef {
211 public:
217 explicit Runner(ffi::ObjectPtr<RunnerNode> data) : ffi::ObjectRef(data) {
218 TVM_FFI_ICHECK(data != nullptr);
219 }
227};
228
230class PyRunnerNode : public RunnerNode {
231 public:
234
235 static void RegisterReflection() {
236 // `f_run` is not registered
237 namespace refl = tvm::ffi::reflection;
238 refl::ObjectDef<PyRunnerNode>();
239 }
240
241 ffi::Array<RunnerFuture> Run(ffi::Array<RunnerInput> runner_inputs) final {
242 TVM_FFI_ICHECK(f_run != nullptr) << "PyRunner's Run method not implemented!";
243 return f_run(runner_inputs);
244 }
246};
247
248} // namespace meta_schedule
249} // namespace s_tir
250} // namespace tvm
251
252#endif // TVM_S_TIR_META_SCHEDULE_RUNNER_H_
RAII wrapper function to enter and exit a context object similar to python's with syntax.
Definition with_context.h:59
An abstract runner with customized build method on the python-side.
Definition runner.h:230
static void RegisterReflection()
Definition runner.h:235
FRun f_run
The packed function to run the built artifacts and get runner futures.
Definition runner.h:233
ffi::Array< RunnerFuture > Run(ffi::Array< RunnerInput > runner_inputs) final
Run the built artifact and get runner futures.
Definition runner.h:241
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.meta_schedule.PyRunner", PyRunnerNode, RunnerNode)
A class to asynchronously fetch runner's output.
Definition runner.h:113
ffi::TypedFunction< bool()> FDone
The function type to check whether the runner has finished.
Definition runner.h:119
RunnerResult Result() const
Fetch the runner's output if it is ready.
Definition runner.h:150
bool Done() const
Check whether the runner has finished.
Definition runner.h:142
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.meta_schedule.RunnerFuture", RunnerFutureNode, ffi::Object)
ffi::TypedFunction< RunnerResult()> FResult
The function type to fetch runner output if it is ready.
Definition runner.h:124
static void RegisterReflection()
Definition runner.h:131
FResult f_result
The packed function to fetch runner output if it is ready.
Definition runner.h:129
FDone f_done
The packed function to check whether the runner has finished.
Definition runner.h:127
Managed reference to RunnerFutureNode.
Definition runner.h:162
RunnerFuture(FDone f_done, FResult f_result)
Constructor of RunnerFuture.
RunnerFutureNode::FDone FDone
Definition runner.h:164
RunnerFutureNode::FResult FResult
Definition runner.h:165
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(RunnerFuture, ffi::ObjectRef, RunnerFutureNode)
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
static void RegisterReflection()
Definition runner.h:46
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.meta_schedule.RunnerInput", RunnerInputNode, ffi::Object)
ffi::String artifact_path
The path to the built artifact.
Definition runner.h:40
ffi::Array< ArgInfo > args_info
The argument information.
Definition runner.h:44
Managed reference to RunnerInputNode.
Definition runner.h:61
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(RunnerInput, ffi::ObjectRef, RunnerInputNode)
RunnerInput(ffi::String artifact_path, ffi::String device_type, ffi::Array< ArgInfo > args_info)
Constructor of RunnerInput.
The abstract runner interface.
Definition runner.h:177
TVM_FFI_DECLARE_OBJECT_INFO("s_tir.meta_schedule.Runner", RunnerNode, ffi::Object)
static void RegisterReflection()
Definition runner.h:197
ffi::TypedFunction< ffi::Array< RunnerFuture >(ffi::Array< RunnerInput >)> FRun
The function type to run the built artifacts and get runner futures.
Definition runner.h:185
virtual ~RunnerNode()=default
Default destructor.
static constexpr const bool _type_mutable
Definition runner.h:202
virtual ffi::Array< RunnerFuture > Run(ffi::Array< RunnerInput > runner_inputs)=0
Run the built artifact and get runner futures.
Runner's output containing measurement result of MeasureCandidate or error msg if any.
Definition runner.h:75
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.meta_schedule.RunnerResult", RunnerResultNode, ffi::Object)
ffi::Optional< ffi::Array< FloatImm > > run_secs
The run time in seconds.
Definition runner.h:78
static void RegisterReflection()
Definition runner.h:82
ffi::Optional< ffi::String > error_msg
The error message, if any.
Definition runner.h:80
Managed reference to RunnerResultNode.
Definition runner.h:96
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, RunnerResultNode)
Managed reference to RunnerNode.
Definition runner.h:210
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(Runner, ffi::ObjectRef, RunnerNode)
static Runner PyRunner(FRun f_run)
Create a runner with customized build method on the python-side.
Runner(ffi::ObjectPtr< RunnerNode > data)
Constructor from ffi::ObjectPtr<RunnerNode>.
Definition runner.h:217
RunnerNode::FRun FRun
Definition runner.h:212
Base expr nodes in TVM.
TIR expressions.
Definition builtin.h:25
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition analyzer.h:40