tvm
Loading...
Searching...
No Matches
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
32#include <utility>
33#include <vector>
34
35namespace tvm {
36
37class IRModule;
38
39// Forward class for PassInstrumentNode methods
40namespace transform {
41class PassInfo;
42} // namespace transform
43
44namespace instrument {
45
102class PassInstrumentNode : public ffi::Object {
103 public:
105 ffi::String name;
106
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 static void RegisterReflection() {
140 namespace refl = tvm::ffi::reflection;
141 refl::ObjectDef<PassInstrumentNode>().def_ro("name", &PassInstrumentNode::name);
142 }
143 TVM_FFI_DECLARE_OBJECT_INFO("instrument.PassInstrument", PassInstrumentNode, ffi::Object);
144};
145
150class PassInstrument : public ffi::ObjectRef {
151 public:
153};
154
155} // namespace instrument
156} // namespace tvm
157
158#endif // TVM_IR_INSTRUMENT_H_
Managed reference class to IRModuleNode.
Definition module.h:255
RAII wrapper function to enter and exit a context object similar to python's with syntax.
Definition with_context.h:59
PassInstrumentNode forms an instrument implementation. It provides API for users to register callback...
Definition instrument.h:102
TVM_FFI_DECLARE_OBJECT_INFO("instrument.PassInstrument", PassInstrumentNode, ffi::Object)
virtual void ExitPassContext() const =0
Instrument when exiting PassContext. Called once within a PassContext.
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
virtual void EnterPassContext() const =0
Instrument when entering PassContext. Called once within a PassContext.
static void RegisterReflection()
Definition instrument.h:139
ffi::String name
Name of this pass instrument object.
Definition instrument.h:105
Managed reference class for PassInstrumentNode.
Definition instrument.h:150
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NULLABLE(PassInstrument, ffi::ObjectRef, PassInstrumentNode)
Managed reference class for PassInfoNode.
Definition transform.h:367
IRModuleFrame IRModule()
The IRModule declaration statement.
Definition module.h:248
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition analyzer.h:40