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 {
38namespace meta_schedule {
39
41 public:
43 if (deferred_ != nullptr) {
44 deferred_();
45 }
46 }
47
48 private:
49 friend class Profiler;
50
51 explicit ScopedTimer(ffi::TypedFunction<void()> deferred) : deferred_(deferred) {}
52 ffi::TypedFunction<void()> deferred_;
53};
54
56class ProfilerObj : public ffi::Object {
57 public:
59 std::unordered_map<std::string, double> stats_sec;
61 ffi::Function total_timer;
62
63 static void RegisterReflection() {
64 namespace refl = tvm::ffi::reflection;
65 refl::ObjectDef<ProfilerObj>();
66 }
67
68 static constexpr const bool _type_mutable = true;
69 TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.meta_schedule.Profiler", ProfilerObj, ffi::Object);
70
71 public:
73 ffi::Map<ffi::String, FloatImm> Get() const;
75 ffi::String Table() const;
76};
77
82class Profiler : public ffi::ObjectRef {
83 public:
86
92 static ffi::Optional<Profiler> Current();
98 static ScopedTimer TimedScope(ffi::String name);
99};
100
101} // namespace meta_schedule
102} // namespace s_tir
103} // namespace tvm
104
105#endif // TVM_S_TIR_META_SCHEDULE_PROFILER_H_
A generic profiler.
Definition profiler.h:56
ffi::String Table() const
Return a summary of profiling results as table format.
std::unordered_map< std::string, double > stats_sec
The segments that are already profiled.
Definition profiler.h:59
static constexpr const bool _type_mutable
Definition profiler.h:68
TVM_FFI_DECLARE_OBJECT_INFO_FINAL("s_tir.meta_schedule.Profiler", ProfilerObj, ffi::Object)
ffi::Function total_timer
Counter for the total time used.
Definition profiler.h:61
ffi::Map< ffi::String, FloatImm > Get() const
Get the internal stats of the running time.
static void RegisterReflection()
Definition profiler.h:63
Managed reference to ProfilerObj.
Definition profiler.h:82
void EnterWithScope()
Entering the scope of the context manager.
void ExitWithScope()
Exiting the scope of the context manager.
static ffi::Optional< Profiler > Current()
Returns the current profiler.
TVM_FFI_DEFINE_OBJECT_REF_METHODS_NOTNULLABLE(Profiler, ffi::ObjectRef, ProfilerObj)
static ScopedTimer TimedScope(ffi::String name)
Profile the time usage in the given scope in the given name.
~ScopedTimer()
Definition profiler.h:42
TIR expressions.
IRModule that holds the functions and type definitions.
An object that builds and maintains block scope and StmtSref mapping for Dependence analysis.
Definition attr.h:23
Compilation target object.