tvm
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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:
138  static Builder PyBuilder(BuilderNode::FBuild f_build);
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_
TVM_DECLARE_FINAL_OBJECT_INFO(BuilderInputNode, runtime::Object)
Managed reference to BuilderResultNode.
Definition: builder.h:94
Runtime Optional container types.
#define TVM_DEFINE_MUTABLE_NOTNULLABLE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName)
Definition: object.h:758
Runtime String container types.
void VisitAttrs(tvm::AttrVisitor *v)
Definition: builder.h:81
IRModule that holds the functions and type definitions.
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
static constexpr const char * _type_key
Definition: builder.h:52
void VisitAttrs(tvm::AttrVisitor *v)
Definition: builder.h:148
Optional< String > artifact_path
The path to the built artifact.
Definition: builder.h:77
base class of all object containers.
Definition: object.h:167
IRModule mod
The IRModule to be built.
Definition: builder.h:40
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
A device-independent managed NDArray abstraction.
The abstract builder interface.
Definition: builder.h:106
FBuild f_build
The packed function to the Build function.
Definition: builder.h:146
Target target
The target to be built for.
Definition: builder.h:42
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
The builder&#39;s input, containing an IRModule and the target.
Definition: builder.h:37
Please refer to TypedPackedFunc<R(Args..)>.
Definition: packed_func.h:60
Managed reference to BuilderNode.
Definition: builder.h:131
Managed reference class to TargetNode.
Definition: target.h:183
Managed reference to BuilderInputNode.
Definition: builder.h:60
Base class of all object reference.
Definition: object.h:511
An abstract builder with customized build method on the python-side.
Definition: builder.h:143
A managed object in the TVM runtime.
Managed reference class to IRModuleNode.
Definition: module.h:348
The builder&#39;s output, containing the artifact path or error message if any.
Definition: builder.h:74
runtime::Module Build(IRModule mod, Target target)
Build a module from array of lowered function.
void VisitAttrs(tvm::AttrVisitor *v)
Definition: builder.h:46
Compilation target object.
Map container of NodeRef->NodeRef in DSL graph. Map implements copy on write semantics, which means map is mutable but copy will happen when array is referenced in more than two places.
Definition: map.h:1271
Runtime Map container types.
Optional< Map< String, runtime::NDArray > > params
Parameters for Relay build module.
Definition: builder.h:44
Optional container that to represent to a Nullable variant of T.
Definition: optional.h:51
constexpr runtime::NullOptType NullOpt
Definition: optional.h:160
Array< BuilderResult > Build(const Array< BuilderInput > &build_inputs) final
Generate the build results from build inputs.
Definition: builder.h:152
Optional< String > error_msg
The error message if any.
Definition: builder.h:79
Reflection and serialization of compiler IR/AST nodes.
#define TVM_DECLARE_BASE_OBJECT_INFO(TypeName, ParentType)
helper macro to declare a base object type that can be inherited.
Definition: object.h:648
#define TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName)
Definition: object.h:728
Type-erased function used across TVM API.