tvm
Loading...
Searching...
No Matches
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_S_TIR_META_SCHEDULE_PROFILER_H_
20#define TVM_S_TIR_META_SCHEDULE_PROFILER_H_
21
22#include <tvm/ffi/container/array.h>
23#include <tvm/ffi/function.h>
24#include <tvm/ffi/optional.h>
25#include <tvm/ffi/reflection/registry.h>
26#include <tvm/ffi/string.h>
27#include <tvm/ir/module.h>
28#include <tvm/ir/prim/expr.h>
29#include <tvm/target/target.h>
30
31#include <string>
32#include <unordered_map>
33#include <utility>
34#include <vector>
35
36namespace tvm {
37namespace s_tir {
38using namespace tvm::prim;
39namespace meta_schedule {
40
42 public:
44 if (deferred_ != nullptr) {
45 deferred_();
46 }
47 }
48
49 private:
50 friend class Profiler;
51
52 explicit ScopedTimer(ffi::TypedFunction<void()> deferred) : deferred_(deferred) {}
53 ffi::TypedFunction<void()> deferred_;
54};
55
57class ProfilerNode : public ffi::Object {
58 public:
60 std::unordered_map<std::string, double> stats_sec;
62 ffi::Function total_timer;
63
64 static void RegisterReflection() {
65 namespace refl = tvm::ffi::reflection;
66 refl::ObjectDef<ProfilerNode>();
67 }
68
69 static constexpr const bool _type_mutable = true;
70 TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.meta_schedule.Profiler", ProfilerNode, ffi::Object);
71
72 public:
74 ffi::Map<ffi::String, FloatImm> Get() const;
76 ffi::String Table() const;
77};
78
83class Profiler : public ffi::ObjectRef {
84 public:
87
93 static ffi::Optional<Profiler> Current();
99 static ScopedTimer TimedScope(ffi::String name);
100};
101
102} // namespace meta_schedule
103} // namespace s_tir
104} // namespace tvm
105
106#endif // TVM_S_TIR_META_SCHEDULE_PROFILER_H_
RAII wrapper function to enter and exit a context object similar to python's with syntax.
Definition with_context.h:59
A generic profiler.
Definition profiler.h:57
std::unordered_map< std::string, double > stats_sec
The segments that are already profiled.
Definition profiler.h:60
ffi::Map< ffi::String, FloatImm > Get() const
Get the internal stats of the running time.
ffi::String Table() const
Return a summary of profiling results as table format.
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.meta_schedule.Profiler", ProfilerNode, ffi::Object)
ffi::Function total_timer
Counter for the total time used.
Definition profiler.h:62
static constexpr const bool _type_mutable
Definition profiler.h:69
static void RegisterReflection()
Definition profiler.h:64
Managed reference to ProfilerNode.
Definition profiler.h:83
void EnterWithScope()
Entering the scope of the context manager.
void ExitWithScope()
Exiting the scope of the context manager.
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(Profiler, ffi::ObjectRef, ProfilerNode)
static ffi::Optional< Profiler > Current()
Returns the current profiler.
static ScopedTimer TimedScope(ffi::String name)
Profile the time usage in the given scope in the given name.
~ScopedTimer()
Definition profiler.h:43
TIR expressions.
IRModule that holds the functions and type definitions.
Definition builtin.h:25
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition analyzer.h:40
Compilation target object.