24 #ifndef TVM_RUNTIME_PROFILING_H_ 25 #define TVM_RUNTIME_PROFILING_H_ 36 #include <unordered_map> 56 virtual void Start() = 0;
61 virtual void Stop() = 0;
76 static constexpr
const char*
_type_key =
"TimerNode";
154 namespace profiling {
165 static constexpr
const char*
_type_key =
"runtime.profiling.DeviceWrapper";
220 String AsTable(
bool sort =
true,
bool aggregate =
true,
bool compute_col_sums =
true)
const;
255 static constexpr
const char*
_type_key =
"runtime.profiling.Report";
319 static constexpr
const char*
_type_key =
"runtime.profiling.MetricCollector";
379 explicit Profiler(std::vector<Device> devs, std::vector<MetricCollector> metric_collectors,
380 std::unordered_map<String, ObjectRef> configuration = {});
402 std::unordered_map<std::string, ObjectRef> extra_metrics = {});
407 void StopCall(std::unordered_map<std::string, ObjectRef> extra_metrics = {});
420 std::vector<Device> devs_;
421 bool is_running_{
false};
422 std::vector<CallFrame> calls_;
423 std::stack<CallFrame> in_flight_;
424 std::vector<MetricCollector> collectors_;
425 std::unordered_map<String, ObjectRef> configuration_;
439 static constexpr
const char*
_type_key =
"runtime.profiling.Duration";
454 static constexpr
const char*
_type_key =
"runtime.profiling.Percent";
469 static constexpr
const char*
_type_key =
"runtime.profiling.Count";
484 static constexpr
const char*
_type_key =
"runtime.profiling.Ratio";
587 int limit_zero_time_iterations,
int cooldown_interval_ms,
588 int repeats_to_cooldown,
PackedFunc f_preproc =
nullptr);
594 #endif // TVM_RUNTIME_PROFILING_H_ Definition: profiling.h:459
constexpr const char * device_type
The device type.
Definition: stmt.h:1355
Definition: profiling.h:474
PackedFunc WrapTimeEvaluator(PackedFunc f, Device dev, int number, int repeat, int min_repeat_ms, int limit_zero_time_iterations, int cooldown_interval_ms, int repeats_to_cooldown, PackedFunc f_preproc=nullptr)
Wrap a timer function to measure the time cost of a given packed function.
double microseconds
Definition: profiling.h:432
Definition: profiling.h:429
static constexpr const char * _type_key
Definition: profiling.h:76
bool IsRunning() const
Check if the profiler is currently running.
Definition: profiling.h:417
virtual int64_t SyncAndGetElapsedNanos()=0
Synchronize timer state and return elapsed time between Start and Stop.
CountNode(int64_t a)
Definition: profiling.h:467
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
Device dev
Definition: profiling.h:332
DeviceWrapperNode(Device device)
Definition: profiling.h:163
std::vector< std::pair< MetricCollector, ObjectRef > > extra_collectors
Definition: profiling.h:342
double percent
Definition: profiling.h:447
virtual void Start()=0
Start the timer.
Map< String, Map< String, ObjectRef > > device_metrics
Metrics collected for the entire run of the model on a per-device basis.
Definition: profiling.h:195
base class of all object containers.
Definition: object.h:167
RatioNode(double a)
Definition: profiling.h:482
Timer DefaultTimer(Device dev)
Default timer if one does not exist for the device.
Managed NDArray. The array is backed by reference counted blocks.
Definition: ndarray.h:51
Interface for user defined profiling metric collection.
Definition: profiling.h:296
#define TVM_DEFINE_MUTABLE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName)
Definition: object.h:744
constexpr const char * device_id
The allocation device for global malloc in host.
Definition: stmt.h:1353
virtual void Stop()=0
Stop the timer.
Wrapper for MetricCollectorNode.
Definition: profiling.h:324
DurationNode(double a)
Definition: profiling.h:437
Array, container representing a contiguous sequence of ObjectRefs.
Definition: array.h:289
std::unordered_map< std::string, ObjectRef > extra_metrics
Definition: profiling.h:338
Array< Map< String, ObjectRef > > calls
A list of function calls and the metrics recorded for that call.
Definition: profiling.h:187
Timer timer
Definition: profiling.h:336
Base class for all implementations.
Definition: profiling.h:50
double ratio
Definition: profiling.h:477
Reference to string objects.
Definition: string.h:98
Data collected from a profiling run. Includes per-call metrics and per-device metrics.
Definition: profiling.h:178
Abstract device memory management API.
Tensor shape(const Tensor &src, DataType dtype, const std::string name="T_shape", const std::string tag=kInjective)
Get the shape of input tensor.
Definition: transform.h:1768
DLDevice Device
Definition: ndarray.h:43
Definition: profiling.h:259
Map< String, ObjectRef > configuration
Definition: profiling.h:200
PackedFunc ProfileFunction(Module mod, std::string func_name, int device_type, int device_id, int warmup_iters, Array< MetricCollector > collectors)
Collect performance information of a function execution. Usually used with a compiled PrimFunc (via t...
Base class of all object reference.
Definition: object.h:511
Definition: profiling.h:330
TVM_DECLARE_BASE_OBJECT_INFO(TimerNode, Object)
Definition: profiling.h:444
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
Device device
Definition: profiling.h:160
Module container of TVM.
Definition: module.h:79
int64_t value
Definition: profiling.h:462
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
Wrapper for Device because Device is not passable across the PackedFunc interface.
Definition: profiling.h:158
Runtime Map container types.
Packed function is a type-erased function. The arguments are passed by packed format.
Definition: packed_func.h:138
virtual ~TimerNode()
Definition: profiling.h:74
Tensor repeat(const Tensor &x, int repeats, int axis, std::string name="T_repeat", std::string tag=kBroadcast)
Creates an operation to repeat elements of an array.
Definition: transform.h:1174
virtual ~MetricCollectorNode()
Definition: profiling.h:317
tvm::PrimExpr mod(const tvm::PrimExpr &a, const tvm::PrimExpr &b)
Definition: broadcast.h:290
BlockInitFrame Init()
The block initialization statement.
Wrapper for Device.
Definition: profiling.h:170
Definition: profiling.h:364
#define TVM_DEFINE_NOTNULLABLE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName)
Definition: object.h:728
String ShapeString(const std::vector< int64_t > &shape, DLDataType dtype)
String representation of a shape encoded as a vector.
String name
Definition: profiling.h:334
Type-erased function used across TVM API.
Timer for a specific device.
Definition: profiling.h:86
This file defines the TVM global function registry.
DeviceWrapper(Device dev)
Definition: profiling.h:172
PercentNode(double a)
Definition: profiling.h:452