tvm
Public Member Functions | List of all members
tvm::runtime::profiling::Profiler Class Reference

#include <profiling.h>

Collaboration diagram for tvm::runtime::profiling::Profiler:

Public Member Functions

 Profiler (std::vector< Device > devs, std::vector< MetricCollector > metric_collectors, std::unordered_map< String, ObjectRef > configuration={})
 
void Start ()
 Start the profiler. More...
 
void Stop ()
 Stop the profiler. More...
 
void StartCall (String name, Device dev, std::unordered_map< std::string, ObjectRef > extra_metrics={})
 Start a function call. More...
 
void StopCall (std::unordered_map< std::string, ObjectRef > extra_metrics={})
 Stop the last StartCall. More...
 
profiling::Report Report ()
 A report of total runtime between Start and Stop as well as individual statistics for each StartCall-StopCall pair. More...
 
bool IsRunning () const
 Check if the profiler is currently running. More...
 

Detailed Description

Runtime profiler for function and/or operator calls. Used in the graph runtime and VM to provide profiling information for all operators.

Example usage:

Device cpu, gpu;
Profiler prof({cpu, gpu});
my_gpu_kernel(); // do a warmup iteration
prof.Start();
prof.StartCall("my_gpu_kernel", gpu);
my_gpu_kernel();
prof.StopCall();
prof.StartCall("my_cpu_function", cpu);
my_cpu_function();
prof.StopCall();
prof.Stop();
std::cout << prof.Report << std::endl; // print profiling report
Profiler(std::vector< Device > devs, std::vector< MetricCollector > metric_collectors, std::unordered_map< String, ObjectRef > configuration={})
DLDevice Device
Definition: ndarray.h:43

Constructor & Destructor Documentation

◆ Profiler()

tvm::runtime::profiling::Profiler::Profiler ( std::vector< Device devs,
std::vector< MetricCollector metric_collectors,
std::unordered_map< String, ObjectRef configuration = {} 
)
explicit

Constructor.

The profiler should be constructed before you do any warmup iterations.

Note
Calling this constructor will reset the TVM threadpool. It is necessary in order to install thread handlers required by certain collectors.
Parameters
devsThe list of devices the profiler will be running on. Should include all devices used by profiled operators.
metric_collectorsAdditional MetricCollectors to use with this profiler.
configurationAdditional configuration data to add to the outputted profiling report.

Member Function Documentation

◆ IsRunning()

bool tvm::runtime::profiling::Profiler::IsRunning ( ) const
inline

Check if the profiler is currently running.

Returns
Whether or not the profiler is running.

◆ Report()

profiling::Report tvm::runtime::profiling::Profiler::Report ( )

A report of total runtime between Start and Stop as well as individual statistics for each StartCall-StopCall pair.

Returns
A Report that can either be formatted as CSV (with .AsCSV) or as a human readable table (with .AsTable).

◆ Start()

void tvm::runtime::profiling::Profiler::Start ( )

Start the profiler.

This function should only be called once per object.

◆ StartCall()

void tvm::runtime::profiling::Profiler::StartCall ( String  name,
Device  dev,
std::unordered_map< std::string, ObjectRef extra_metrics = {} 
)

Start a function call.

Parameters
nameThe name of the function being called.
devThe device on which the function is running.
extra_metricsOptional additional profiling information to add to the frame (input sizes, allocations).

StartCall may be nested, but each StartCall needs a matching StopCall. Function calls are stopped in LIFO order, so calls to StartCall and StopCall must be nested properly.

◆ Stop()

void tvm::runtime::profiling::Profiler::Stop ( )

Stop the profiler.

This function should only be called once per object after start has been called.

◆ StopCall()

void tvm::runtime::profiling::Profiler::StopCall ( std::unordered_map< std::string, ObjectRef extra_metrics = {})

Stop the last StartCall.

Parameters
extra_metricsOptional additional profiling information to add to the frame (input sizes, allocations).

The documentation for this class was generated from the following file: