tvm
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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) {}
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:
72  Map<String, FloatImm> Get() const;
74  String Table() const;
75 };
76 
81 class Profiler : public runtime::ObjectRef {
82  public:
83  Profiler();
85 
87  void EnterWithScope();
89  void ExitWithScope();
91  static Optional<Profiler> Current();
97  static ScopedTimer TimedScope(String name);
98 };
99 
100 } // namespace meta_schedule
101 } // namespace tvm
102 
103 #endif // TVM_META_SCHEDULE_PROFILER_H_
Runtime Optional container types.
#define TVM_DEFINE_MUTABLE_NOTNULLABLE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName)
Definition: object.h:758
runtime::PackedFunc total_timer
Counter for the total time used.
Definition: profiler.h:60
Runtime String container types.
IRModule that holds the functions and type definitions.
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
base class of all object containers.
Definition: object.h:167
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
Reference to string objects.
Definition: string.h:98
Please refer to TypedPackedFunc<R(Args..)>.
Definition: packed_func.h:60
void VisitAttrs(tvm::AttrVisitor *v)
Definition: profiler.h:62
Base class of all object reference.
Definition: object.h:511
std::unordered_map< std::string, double > stats_sec
The segments that are already profiled.
Definition: profiler.h:58
A managed object in the TVM runtime.
#define TVM_DECLARE_FINAL_OBJECT_INFO(TypeName, ParentType)
helper macro to declare type information in a final class.
Definition: object.h:671
~ScopedTimer()
Definition: profiler.h:41
Compilation target object.
Map container of NodeRef->NodeRef in DSL graph. Map implements copy on write semantics, which means map is mutable but copy will happen when array is referenced in more than two places.
Definition: map.h:1271
Packed function is a type-erased function. The arguments are passed by packed format.
Definition: packed_func.h:138
A generic profiler.
Definition: profiler.h:55
Optional container that to represent to a Nullable variant of T.
Definition: optional.h:51
Reflection and serialization of compiler IR/AST nodes.
Managed reference to ProfilerNode.
Definition: profiler.h:81
Definition: profiler.h:39
friend class Profiler
Definition: profiler.h:48
Type-erased function used across TVM API.