tvm
builder.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_BUILDER_H_
20 #define TVM_META_SCHEDULE_BUILDER_H_
21 
22 #include <tvm/ir/module.h>
23 #include <tvm/node/reflection.h>
28 #include <tvm/runtime/ndarray.h>
29 #include <tvm/runtime/object.h>
31 #include <tvm/target/target.h>
32 
33 namespace tvm {
34 namespace meta_schedule {
35 
38  public:
45 
47  v->Visit("mod", &mod);
48  v->Visit("target", &target);
49  v->Visit("params", &params);
50  }
51 
52  static constexpr const char* _type_key = "meta_schedule.BuilderInput";
54 };
55 
61  public:
68  TVM_DLL explicit BuilderInput(IRModule mod, Target target,
71 };
72 
75  public:
80 
82  v->Visit("artifact_path", &artifact_path);
83  v->Visit("error_msg", &error_msg);
84  }
85 
86  static constexpr const char* _type_key = "meta_schedule.BuilderResult";
88 };
89 
95  public:
101  TVM_DLL explicit BuilderResult(Optional<String> artifact_path, Optional<String> error_msg);
103 };
104 
106 class BuilderNode : public runtime::Object {
107  public:
109  virtual ~BuilderNode() = default;
115  virtual Array<BuilderResult> Build(const Array<BuilderInput>& build_inputs) = 0;
122 
123  static constexpr const char* _type_key = "meta_schedule.Builder";
125 };
126 
131 class Builder : public runtime::ObjectRef {
132  public:
140 };
141 
143 class PyBuilderNode : public BuilderNode {
144  public:
147 
149  // `f_build` is not visited
150  }
151 
152  Array<BuilderResult> Build(const Array<BuilderInput>& build_inputs) final {
153  ICHECK(f_build != nullptr) << "PyBuilder's Build method not implemented!";
154  return f_build(build_inputs);
155  }
156 
157  static constexpr const char* _type_key = "meta_schedule.PyBuilder";
159 };
160 
161 } // namespace meta_schedule
162 } // namespace tvm
163 
164 #endif // TVM_META_SCHEDULE_BUILDER_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
Managed reference class to IRModuleNode.
Definition: module.h:366
Managed reference class to TargetNode.
Definition: target.h:200
The builder's input, containing an IRModule and the target.
Definition: builder.h:37
static constexpr const char * _type_key
Definition: builder.h:52
Optional< Map< String, runtime::NDArray > > params
Parameters for Relay build module.
Definition: builder.h:44
IRModule mod
The IRModule to be built.
Definition: builder.h:40
TVM_DECLARE_FINAL_OBJECT_INFO(BuilderInputNode, runtime::Object)
void VisitAttrs(tvm::AttrVisitor *v)
Definition: builder.h:46
Target target
The target to be built for.
Definition: builder.h:42
Managed reference to BuilderInputNode.
Definition: builder.h:60
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(BuilderInput, runtime::ObjectRef, BuilderInputNode)
BuilderInput(IRModule mod, Target target, Optional< Map< String, runtime::NDArray >> params=NullOpt)
Constructor of BuilderInput.
The abstract builder interface.
Definition: builder.h:106
virtual Array< BuilderResult > Build(const Array< BuilderInput > &build_inputs)=0
Generate the build results from build inputs.
TVM_DECLARE_BASE_OBJECT_INFO(BuilderNode, runtime::Object)
static constexpr const char * _type_key
Definition: builder.h:123
virtual ~BuilderNode()=default
Default destructor.
The builder's output, containing the artifact path or error message if any.
Definition: builder.h:74
static constexpr const char * _type_key
Definition: builder.h:86
Optional< String > error_msg
The error message if any.
Definition: builder.h:79
Optional< String > artifact_path
The path to the built artifact.
Definition: builder.h:77
void VisitAttrs(tvm::AttrVisitor *v)
Definition: builder.h:81
TVM_DECLARE_FINAL_OBJECT_INFO(BuilderResultNode, runtime::Object)
Managed reference to BuilderResultNode.
Definition: builder.h:94
BuilderResult(Optional< String > artifact_path, Optional< String > error_msg)
Constructor of BuilderResult.
TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(BuilderResult, runtime::ObjectRef, BuilderResultNode)
Managed reference to BuilderNode.
Definition: builder.h:131
static Builder PyBuilder(BuilderNode::FBuild f_build)
Create a builder with customized build method on the python-side.
TVM_DEFINE_MUTABLE_NOTNULLABLE_OBJECT_REF_METHODS(Builder, runtime::ObjectRef, BuilderNode)
An abstract builder with customized build method on the python-side.
Definition: builder.h:143
TVM_DECLARE_FINAL_OBJECT_INFO(PyBuilderNode, BuilderNode)
Array< BuilderResult > Build(const Array< BuilderInput > &build_inputs) final
Generate the build results from build inputs.
Definition: builder.h:152
FBuild f_build
The packed function to the Build function.
Definition: builder.h:146
static constexpr const char * _type_key
Definition: builder.h:157
void VisitAttrs(tvm::AttrVisitor *v)
Definition: builder.h:148
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
Map container of NodeRef->NodeRef in DSL graph. Map implements copy on write semantics,...
Definition: map.h:1271
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
Please refer to TypedPackedFunc<R(Args..)>.
Definition: packed_func.h:63
IRModule that holds the functions and type definitions.
Runtime Map container types.
tvm::PrimExpr mod(const tvm::PrimExpr &a, const tvm::PrimExpr &b)
Definition: broadcast.h:290
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
constexpr runtime::NullOptType NullOpt
Definition: optional.h:169
A device-independent managed NDArray abstraction.
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.
Compilation target object.