tvm
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_META_SCHEDULE_RUNNER_H_
20 #define TVM_META_SCHEDULE_RUNNER_H_
21 
22 #include <tvm/ir/expr.h>
24 #include <tvm/node/reflection.h>
28 #include <tvm/runtime/object.h>
30 
31 namespace tvm {
32 namespace meta_schedule {
33 
36  public:
43 
45  v->Visit("artifact_path", &artifact_path);
46  v->Visit("device_type", &device_type);
47  v->Visit("args_info", &args_info);
48  }
49 
50  static constexpr const char* _type_key = "meta_schedule.RunnerInput";
52 };
53 
59  public:
66  TVM_DLL explicit RunnerInput(String artifact_path, String device_type, Array<ArgInfo> args_info);
68 };
69 
72  public:
77 
79  v->Visit("run_secs", &run_secs);
80  v->Visit("error_msg", &error_msg);
81  }
82 
83  static constexpr const char* _type_key = "meta_schedule.RunnerResult";
85 };
86 
92  public:
98  TVM_DLL explicit RunnerResult(Optional<Array<FloatImm>> run_secs, Optional<String> error_msg);
100 };
101 
108  public:
119 
124 
126  // `f_done` is not visited
127  // `f_result` is not visited
128  }
129 
134  bool Done() const {
135  ICHECK(f_done != nullptr) << "PyRunnerFuture's Done method not implemented!";
136  return f_done();
137  }
143  ICHECK(f_result != nullptr) << "PyRunnerFuture's Result method not implemented!";
144  return f_result();
145  }
146 
147  static constexpr const char* _type_key = "meta_schedule.RunnerFuture";
149 };
150 
156  public:
159 
165  TVM_DLL explicit RunnerFuture(FDone f_done, FResult f_result);
168 };
169 
171 class RunnerNode : public runtime::Object {
172  public:
180 
182  virtual ~RunnerNode() = default;
183 
189  virtual Array<RunnerFuture> Run(Array<RunnerInput> runner_inputs) = 0;
190 
191  static constexpr const char* _type_key = "meta_schedule.Runner";
193 };
194 
199 class Runner : public runtime::ObjectRef {
200  public:
202 
208  TVM_DLL static Runner PyRunner(FRun f_run);
210 };
211 
213 class PyRunnerNode : public RunnerNode {
214  public:
217 
219  // `f_run` is not visited
220  }
221 
223  ICHECK(f_run != nullptr) << "PyRunner's Run method not implemented!";
224  return f_run(runner_inputs);
225  }
226 
227  static constexpr const char* _type_key = "meta_schedule.PyRunner";
229 };
230 
231 } // namespace meta_schedule
232 } // namespace tvm
233 
234 #endif // TVM_META_SCHEDULE_RUNNER_H_
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
An abstract runner with customized build method on the python-side.
Definition: runner.h:213
void VisitAttrs(tvm::AttrVisitor *v)
Definition: runner.h:218
static constexpr const char * _type_key
Definition: runner.h:227
TVM_DECLARE_FINAL_OBJECT_INFO(PyRunnerNode, RunnerNode)
Array< RunnerFuture > Run(Array< RunnerInput > runner_inputs) final
Run the built artifact and get runner futures.
Definition: runner.h:222
FRun f_run
The packed function to run the built artifacts and get runner futures.
Definition: runner.h:216
A class to asynchronously fetch runner's output.
Definition: runner.h:107
RunnerResult Result() const
Fetch the runner's output if it is ready.
Definition: runner.h:142
runtime::TypedPackedFunc< RunnerResult()> FResult
The function type to fetch runner output if it is ready.
Definition: runner.h:118
TVM_DECLARE_FINAL_OBJECT_INFO(RunnerFutureNode, runtime::Object)
FDone f_done
The packed function to check whether the runner has finished.
Definition: runner.h:121
FResult f_result
The packed function to fetch runner output if it is ready.
Definition: runner.h:123
static constexpr const char * _type_key
Definition: runner.h:147
bool Done() const
Check whether the runner has finished.
Definition: runner.h:134
void VisitAttrs(tvm::AttrVisitor *v)
Definition: runner.h:125
runtime::TypedPackedFunc< bool()> FDone
The function type to check whether the runner has finished.
Definition: runner.h:113
Managed reference to RunnerFutureNode.
Definition: runner.h:155
RunnerFuture(FDone f_done, FResult f_result)
Constructor of RunnerFuture.
TVM_DEFINE_MUTABLE_NOTNULLABLE_OBJECT_REF_METHODS(RunnerFuture, runtime::ObjectRef, RunnerFutureNode)
Runner's input containing path of artifact, type of device and argument info.
Definition: runner.h:35
TVM_DECLARE_FINAL_OBJECT_INFO(RunnerInputNode, runtime::Object)
String device_type
The type of device.
Definition: runner.h:40
void VisitAttrs(tvm::AttrVisitor *v)
Definition: runner.h:44
Array< ArgInfo > args_info
The argument information.
Definition: runner.h:42
static constexpr const char * _type_key
Definition: runner.h:50
String artifact_path
The path to the built artifact.
Definition: runner.h:38
Managed reference to RunnerInputNode.
Definition: runner.h:58
RunnerInput(String artifact_path, String device_type, Array< ArgInfo > args_info)
Constructor of RunnerInput.
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(RunnerInput, runtime::ObjectRef, RunnerInputNode)
The abstract runner interface.
Definition: runner.h:171
TVM_DECLARE_BASE_OBJECT_INFO(RunnerNode, runtime::Object)
virtual ~RunnerNode()=default
Default destructor.
virtual Array< RunnerFuture > Run(Array< RunnerInput > runner_inputs)=0
Run the built artifact and get runner futures.
runtime::TypedPackedFunc< Array< RunnerFuture >(Array< RunnerInput >)> FRun
The function type to run the built artifacts and get runner futures.
Definition: runner.h:179
static constexpr const char * _type_key
Definition: runner.h:191
Runner's output containing measurement result of MeasureCandidate or error msg if any.
Definition: runner.h:71
Optional< Array< FloatImm > > run_secs
The run time in seconds.
Definition: runner.h:74
Optional< String > error_msg
The error message, if any.
Definition: runner.h:76
void VisitAttrs(tvm::AttrVisitor *v)
Definition: runner.h:78
static constexpr const char * _type_key
Definition: runner.h:83
TVM_DECLARE_FINAL_OBJECT_INFO(RunnerResultNode, runtime::Object)
Managed reference to RunnerResultNode.
Definition: runner.h:91
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(RunnerResult, runtime::ObjectRef, RunnerResultNode)
RunnerResult(Optional< Array< FloatImm >> run_secs, Optional< String > error_msg)
Constructor.
Managed reference to RunnerNode.
Definition: runner.h:199
TVM_DEFINE_MUTABLE_NOTNULLABLE_OBJECT_REF_METHODS(Runner, runtime::ObjectRef, RunnerNode)
static Runner PyRunner(FRun f_run)
Create a runner with customized build method on the python-side.
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
Base class of all object reference.
Definition: object.h:519
base class of all object containers.
Definition: object.h:171
Optional container that to represent to a Nullable variant of T.
Definition: optional.h:51
Reference to string objects.
Definition: string.h:98
Base expr nodes in TVM.
constexpr const char * device_type
The device type.
Definition: stmt.h:1422
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
A managed object in the TVM runtime.
Runtime Optional container types.
Type-erased function used across TVM API.
Reflection and serialization of compiler IR/AST nodes.
Runtime String container types.