tvm
profiler.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_PROFILER_H_
20 #define TVM_META_SCHEDULE_PROFILER_H_
21 
22 #include <tvm/ir/module.h>
23 #include <tvm/node/reflection.h>
27 #include <tvm/runtime/object.h>
29 #include <tvm/target/target.h>
30 
31 #include <string>
32 #include <unordered_map>
33 #include <utility>
34 #include <vector>
35 
36 namespace tvm {
37 namespace meta_schedule {
38 
39 class ScopedTimer {
40  public:
42  if (deferred_ != nullptr) {
43  deferred_();
44  }
45  }
46 
47  private:
48  friend class Profiler;
49 
50  explicit ScopedTimer(runtime::TypedPackedFunc<void()> deferred) : deferred_(deferred) {}
51  runtime::TypedPackedFunc<void()> deferred_;
52 };
53 
55 class ProfilerNode : public runtime::Object {
56  public:
58  std::unordered_map<std::string, double> stats_sec;
61 
63  // `stats_sec` is not visited.
64  // `total_timer` is not visited.
65  }
66 
67  static constexpr const char* _type_key = "meta_schedule.Profiler";
69 
70  public:
74  String Table() const;
75 };
76 
81 class Profiler : public runtime::ObjectRef {
82  public:
85 
89  void ExitWithScope();
98 };
99 
100 } // namespace meta_schedule
101 } // namespace tvm
102 
103 #endif // TVM_META_SCHEDULE_PROFILER_H_
Runtime Array container types.
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
A generic profiler.
Definition: profiler.h:55
Map< String, FloatImm > Get() const
Get the internal stats of the running time.
String Table() const
Return a summary of profiling results as table format.
TVM_DECLARE_FINAL_OBJECT_INFO(ProfilerNode, runtime::Object)
runtime::PackedFunc total_timer
Counter for the total time used.
Definition: profiler.h:60
std::unordered_map< std::string, double > stats_sec
The segments that are already profiled.
Definition: profiler.h:58
static constexpr const char * _type_key
Definition: profiler.h:67
void VisitAttrs(tvm::AttrVisitor *v)
Definition: profiler.h:62
Managed reference to ProfilerNode.
Definition: profiler.h:81
static ScopedTimer TimedScope(String name)
Profile the time usage in the given scope in the given name.
void EnterWithScope()
Entering the scope of the context manager.
static Optional< Profiler > Current()
Returns the current profiler.
void ExitWithScope()
Exiting the scope of the context manager.
TVM_DEFINE_MUTABLE_NOTNULLABLE_OBJECT_REF_METHODS(Profiler, runtime::ObjectRef, ProfilerNode)
Definition: profiler.h:39
~ScopedTimer()
Definition: profiler.h:41
Map container of NodeRef->NodeRef in DSL graph. Map implements copy on write semantics,...
Definition: map.h:1271
Base class of all object reference.
Definition: object.h:519
base class of all object containers.
Definition: object.h:171
Optional container that to represent to a Nullable variant of T.
Definition: optional.h:51
Packed function is a type-erased function. The arguments are passed by packed format.
Definition: packed_func.h:141
Reference to string objects.
Definition: string.h:98
Please refer to TypedPackedFunc<R(Args..)>.
Definition: packed_func.h:63
IRModule that holds the functions and type definitions.
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
A managed object in the TVM runtime.
Runtime Optional container types.
Type-erased function used across TVM API.
Reflection and serialization of compiler IR/AST nodes.
Runtime String container types.
Compilation target object.