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/ffi/reflection/registry.h>
30 #include <tvm/ffi/string.h>
31 #include <tvm/node/node.h>
32 
33 #include <utility>
34 #include <vector>
35 
36 namespace tvm {
37 
38 class IRModule;
39 
40 // Forward class for PassInstrumentNode methods
41 namespace transform {
42 class PassInfo;
43 } // namespace transform
44 
45 namespace instrument {
46 
103 class PassInstrumentNode : public Object {
104  public:
106  String name;
107 
108  virtual ~PassInstrumentNode() {}
109 
111  virtual void EnterPassContext() const = 0;
112 
114  virtual void ExitPassContext() const = 0;
115 
124  virtual bool ShouldRun(const IRModule& mod, const transform::PassInfo& info) const = 0;
125 
131  virtual void RunBeforePass(const IRModule& mod, const transform::PassInfo& info) const = 0;
132 
138  virtual void RunAfterPass(const IRModule& mod, const transform::PassInfo& info) const = 0;
139 
140  static void RegisterReflection() {
141  namespace refl = tvm::ffi::reflection;
142  refl::ObjectDef<PassInstrumentNode>().def_ro("name", &PassInstrumentNode::name);
143  }
144 
145  static constexpr const char* _type_key = "instrument.PassInstrument";
147 };
148 
153 class PassInstrument : public ObjectRef {
154  public:
156 };
157 
158 } // namespace instrument
159 } // namespace tvm
160 
161 #endif // TVM_IR_INSTRUMENT_H_
Managed reference class to IRModuleNode.
Definition: module.h:257
PassInstrumentNode forms an instrument implementation. It provides API for users to register callback...
Definition: instrument.h:103
virtual void ExitPassContext() const =0
Instrument when exiting PassContext. Called once within a PassContext.
static constexpr const char * _type_key
Definition: instrument.h:145
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:108
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:106
static void RegisterReflection()
Definition: instrument.h:140
TVM_DECLARE_BASE_OBJECT_INFO(PassInstrumentNode, Object)
Managed reference class for PassInstrumentNode.
Definition: instrument.h:153
TVM_DEFINE_OBJECT_REF_METHODS(PassInstrument, ObjectRef, PassInstrumentNode)
Managed reference class for PassInfoNode.
Definition: transform.h:349
Definition: repr_printer.h:91
IRModuleFrame IRModule()
The IRModule declaration statement.
Definition: module.h:250
tvm::PrimExpr mod(const tvm::PrimExpr &a, const tvm::PrimExpr &b)
Definition: broadcast.h:306
Performance counters for profiling via the PAPI library.
Definition: analyzer.h:37
Definitions and helper macros for IR/AST nodes.