tvm
si_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 
24 #ifndef TVM_IR_SI_BUILDER_H_
25 #define TVM_IR_SI_BUILDER_H_
26 
27 #include <tvm/relay/expr.h>
28 #include <tvm/relay/expr_functor.h>
29 #include <tvm/tir/stmt.h>
30 
31 #include <memory>
32 #include <unordered_set>
33 
34 namespace tvm {
35 
40 class SIBuilder {
41  public:
45  explicit SIBuilder(const Span& span = Span());
46 
50  explicit SIBuilder(const Array<Span>& spans = Array<Span>());
51  explicit SIBuilder(const std::initializer_list<Span>& init);
52 
60  template <typename T, typename = std::enable_if_t<std::is_base_of<BaseExpr, T>::value>>
61  explicit SIBuilder(const T& entry, const tvm::Array<T>& inputs = {});
62  explicit SIBuilder(const tir::Stmt& entry, const tvm::Array<PrimExpr>& inputs = {});
63  explicit SIBuilder(const tir::Stmt& entry, const tvm::Array<tir::Stmt>& inputs = {});
64 
66 
67  SIBuilder(const SIBuilder&) = delete;
68  SIBuilder& operator=(const SIBuilder&) = delete;
69 
75  Span Build() const;
76 
83  template <typename T, typename = std::enable_if_t<std::is_base_of<BaseExpr, T>::value>>
85  const T& entry, const std::unordered_set<T, ObjectPtrHash, ObjectPtrEqual>& inputs) const;
86 
88  const tir::Stmt& entry,
89  const std::unordered_set<PrimExpr, ObjectPtrHash, ObjectPtrEqual>& inputs) const;
91  const tir::Stmt& entry,
92  const std::unordered_set<tir::Stmt, ObjectPtrHash, ObjectPtrEqual>& inputs) const;
93 
94  private:
95  struct Impl;
96  std::unique_ptr<Impl> impl_;
97 
98  std::unique_ptr<Impl> CreateImpl(const Span& span);
99 };
100 
101 } // namespace tvm
102 
103 #endif // TVM_IR_SI_BUILDER_H_
Source Information Builder, SIBuilder provides helper APIs for filling spans, particularly useful for...
Definition: si_builder.h:40
Span Build() const
build a span of source information, which is based on the given span or subgraph.
SIBuilder & operator=(const SIBuilder &)=delete
SIBuilder(const Span &span=Span())
Create SIBuilder from a given span.
SIBuilder(const Array< Span > &spans=Array< Span >())
Create SIBuilder from a given span sequence.
void RecursivelyFillSpan(const tir::Stmt &entry, const std::unordered_set< tir::Stmt, ObjectPtrHash, ObjectPtrEqual > &inputs) const
SIBuilder(const tir::Stmt &entry, const tvm::Array< PrimExpr > &inputs={})
SIBuilder(const tir::Stmt &entry, const tvm::Array< tir::Stmt > &inputs={})
SIBuilder(const SIBuilder &)=delete
SIBuilder(const T &entry, const tvm::Array< T > &inputs={})
Create SIBuilder via a subgraph, Will construct span based on the exprs in the subgraph....
void RecursivelyFillSpan(const tir::Stmt &entry, const std::unordered_set< PrimExpr, ObjectPtrHash, ObjectPtrEqual > &inputs) const
SIBuilder(const std::initializer_list< Span > &init)
void RecursivelyFillSpan(const T &entry, const std::unordered_set< T, ObjectPtrHash, ObjectPtrEqual > &inputs) const
Recursively fill all span of exprs in subgraph from entry until inputs.
Definition: source_map.h:120
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
Container of all statements.
Definition: stmt.h:59
tvm::Span Span
Definition: base.h:65
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
Relay expression language.
A more powerful visitor which enables defining arbitrary function signatures with type based dispatch...
TIR statements.