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/target/target.h>
24 
25 namespace tvm {
26 namespace meta_schedule {
27 
30  public:
35 
37  v->Visit("mod", &mod);
38  v->Visit("target", &target);
39  }
40 
41  static constexpr const char* _type_key = "meta_schedule.BuilderInput";
43 };
44 
50  public:
56  TVM_DLL explicit BuilderInput(IRModule mod, Target target);
58 };
59 
62  public:
67 
69  v->Visit("artifact_path", &artifact_path);
70  v->Visit("error_msg", &error_msg);
71  }
72 
73  static constexpr const char* _type_key = "meta_schedule.BuilderResult";
75 };
76 
82  public:
88  TVM_DLL explicit BuilderResult(Optional<String> artifact_path, Optional<String> error_msg);
90 };
91 
93 class BuilderNode : public runtime::Object {
94  public:
96  virtual ~BuilderNode() = default;
102  virtual Array<BuilderResult> Build(const Array<BuilderInput>& build_inputs) = 0;
109 
110  static constexpr const char* _type_key = "meta_schedule.Builder";
112 };
113 
118 class Builder : public runtime::ObjectRef {
119  public:
125  static Builder PyBuilder(BuilderNode::FBuild f_build);
127 };
128 
130 class PyBuilderNode : public BuilderNode {
131  public:
134 
136  // `f_build` is not visited
137  }
138 
139  Array<BuilderResult> Build(const Array<BuilderInput>& build_inputs) final {
140  ICHECK(f_build != nullptr) << "PyBuilder's Build method not implemented!";
141  return f_build(build_inputs);
142  }
143 
144  static constexpr const char* _type_key = "meta_schedule.PyBuilder";
146 };
147 
148 } // namespace meta_schedule
149 } // namespace tvm
150 
151 #endif // TVM_META_SCHEDULE_BUILDER_H_
TVM_DECLARE_FINAL_OBJECT_INFO(BuilderInputNode, runtime::Object)
Managed reference to BuilderResultNode.
Definition: builder.h:81
#define TVM_DEFINE_MUTABLE_NOTNULLABLE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName)
Definition: object.h:751
void VisitAttrs(tvm::AttrVisitor *v)
Definition: builder.h:68
IRModule that holds the functions and type definitions.
Performance counters for profiling via the PAPI library.
Definition: analyzer.h:36
static constexpr const char * _type_key
Definition: builder.h:41
void VisitAttrs(tvm::AttrVisitor *v)
Definition: builder.h:135
Optional< String > artifact_path
The path to the built artifact.
Definition: builder.h:64
base class of all object containers.
Definition: object.h:165
IRModule mod
The IRModule to be built.
Definition: builder.h:32
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
The abstract builder interface.
Definition: builder.h:93
FBuild f_build
The packed function to the Build function.
Definition: builder.h:133
Target target
The target to be built for.
Definition: builder.h:34
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:270
The builder&#39;s input, containing an IRModule and the target.
Definition: builder.h:29
Please refer to TypedPackedFunc<R(Args..)>.
Definition: packed_func.h:136
Managed reference to BuilderNode.
Definition: builder.h:118
Managed reference class to TargetNode.
Definition: target.h:132
Managed reference to BuilderInputNode.
Definition: builder.h:49
Base class of all object reference.
Definition: object.h:504
An abstract builder with customized build method on the python-side.
Definition: builder.h:130
Managed reference class to IRModuleNode.
Definition: module.h:352
The builder&#39;s output, containing the artifact path or error message if any.
Definition: builder.h:61
runtime::Module Build(IRModule mod, Target target)
Build a module from array of lowered function.
void VisitAttrs(tvm::AttrVisitor *v)
Definition: builder.h:36
Compilation target object.
Optional container that to represent to a Nullable variant of T.
Definition: optional.h:51
Array< BuilderResult > Build(const Array< BuilderInput > &build_inputs) final
Generate the build results from build inputs.
Definition: builder.h:139
Optional< String > error_msg
The error message if any.
Definition: builder.h:66
#define TVM_DECLARE_BASE_OBJECT_INFO(TypeName, ParentType)
helper macro to declare a base object type that can be inherited.
Definition: object.h:641
#define TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName)
Definition: object.h:721