tvm
instrument.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 
26 #ifndef TVM_IR_INSTRUMENT_H_
27 #define TVM_IR_INSTRUMENT_H_
28 
29 #include <tvm/node/reflection.h>
31 
32 #include <utility>
33 #include <vector>
34 
35 namespace tvm {
36 
37 class IRModule;
38 
39 // Forward class for PassInstrumentNode methods
40 namespace transform {
41 class PassInfo;
42 } // namespace transform
43 
44 namespace instrument {
45 
102 class PassInstrumentNode : public Object {
103  public:
106 
107  virtual ~PassInstrumentNode() {}
108 
110  virtual void EnterPassContext() const = 0;
111 
113  virtual void ExitPassContext() const = 0;
114 
123  virtual bool ShouldRun(const IRModule& mod, const transform::PassInfo& info) const = 0;
124 
130  virtual void RunBeforePass(const IRModule& mod, const transform::PassInfo& info) const = 0;
131 
137  virtual void RunAfterPass(const IRModule& mod, const transform::PassInfo& info) const = 0;
138 
139  void VisitAttrs(AttrVisitor* v) { v->Visit("name", &name); }
140 
141  static constexpr const char* _type_key = "instrument.PassInstrument";
143 };
144 
149 class PassInstrument : public ObjectRef {
150  public:
152 };
153 
154 } // namespace instrument
155 } // namespace tvm
156 
157 #endif // TVM_IR_INSTRUMENT_H_
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
PassInstrumentNode forms an instrument implementation. It provides API for users to register callback...
Definition: instrument.h:102
virtual void ExitPassContext() const =0
Instrument when exiting PassContext. Called once within a PassContext.
static constexpr const char * _type_key
Definition: instrument.h:141
virtual bool ShouldRun(const IRModule &mod, const transform::PassInfo &info) const =0
Determine whether to run the pass or not. Called multiple times depend on number of passes.
virtual void RunAfterPass(const IRModule &mod, const transform::PassInfo &info) const =0
Instrument after pass run. Called multiple time depend on number of passes.
virtual void RunBeforePass(const IRModule &mod, const transform::PassInfo &info) const =0
Instrument before pass run. Called multiple times depend on number of passes.
virtual ~PassInstrumentNode()
Definition: instrument.h:107
void VisitAttrs(AttrVisitor *v)
Definition: instrument.h:139
virtual void EnterPassContext() const =0
Instrument when entering PassContext. Called once within a PassContext.
String name
Name of this pass instrument object.
Definition: instrument.h:105
TVM_DECLARE_BASE_OBJECT_INFO(PassInstrumentNode, Object)
Managed reference class for PassInstrumentNode.
Definition: instrument.h:149
TVM_DEFINE_OBJECT_REF_METHODS(PassInstrument, ObjectRef, PassInstrumentNode)
Base class of all object reference.
Definition: object.h:519
base class of all object containers.
Definition: object.h:171
Reference to string objects.
Definition: string.h:98
Managed reference class for PassInfoNode.
Definition: transform.h:373
IRModuleFrame IRModule()
The IRModule declaration statement.
Definition: module.h:359
tvm::PrimExpr mod(const tvm::PrimExpr &a, const tvm::PrimExpr &b)
Definition: broadcast.h:290
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
Reflection and serialization of compiler IR/AST nodes.
Runtime String container types.