cupti.profiler_host#
The cupti.profiler_host module provides the pythonic layer for the CUPTI Profiler Host API, built on top of cupti.cupti.
APIs#
- class cupti.profiler_host.ProfilerHost(
- chip_name: str,
- profiler_type: ProfilerType,
- single_pass_metric_set_name: str | None = None,
Bases:
objectHost-side helper to build profiler metric configs and read metric values.
For one GPU chip and profiler kind, can produce configuration data used when collecting metrics on the device, and can turn decoded counter data into floating-point metric values per sample or range. Call
initialize()after construction. The chip name, profiler kind, and metric names must be valid for the installed CUPTI and hardware.- initialize() None#
Initializes the CUPTI profiler host object.
- Raises:
ValueError – If the chip name is not valid for the installed CUPTI or hardware (
ERROR_INVALID_CHIP_NAMEfrom the underlying call).ValueError – If
single_pass_metric_set_nameis invalid for the chip.RuntimeError – If the nvperf* libraries could not be loaded.
cupti.cupti.cuptiError – If CUPTI fails for other reasons (e.g. internal errors).
- create_config_image( ) ndarray#
Build a binary configuration buffer for the given metrics.
The returned buffer is used when enabling collection on the device.
- Parameters:
metrics – Metric names to include; must be supported on this chip.
- Returns:
Configuration image as a
uint8array.- Raises:
RuntimeError – If this object is not usable because
initialize()has not been called (or afterdeinitialize()without a subsequentinitialize()). This method does not run in that state.ValueError – When one or more of the passed metrics is invalid.
cupti.cupti.cuptiError – If there is an internal CUPTI error.
- evaluate_metric_values( ) ndarray#
Get the floating-point metric values for one sample/range index in counter data.
- Parameters:
counter_data_image – Decoded counter payload as a
uint8array.metrics – Metric names to evaluate, in the order values should appear.
index – Index of the sample or range in
counter_data_image.
- Returns:
New
float64array of shape(len(metrics),).- Raises:
RuntimeError – If this object is not usable because
initialize()has not been called (or afterdeinitialize()without a subsequentinitialize()). This method does not run in that state.ValueError – When one or more of the passed metrics is invalid.
cupti.cupti.cuptiError – On invalid index, bad counter data, or if there is an internal CUPTI error.
- get_base_metrics(
- metric_type: MetricType,
Get base metrics supported for a metric type on this chip.
- Parameters:
metric_type – Metric type to query (for example counter, ratio, throughput).
- Returns:
Base metric names for the requested metric type.
- Raises:
RuntimeError – If this object is not usable because
initialize()has not been called (or afterdeinitialize()without a subsequentinitialize()).ValueError – If
metric_typeis invalid.cupti.cupti.cuptiError – If CUPTI reports an internal failure.
- get_sub_metrics(
- metric_name: str,
- metric_type: MetricType,
Get sub-metrics for a metric name and metric type.
- Parameters:
metric_name – Metric name to query (with or without extension).
metric_type – Metric type for the queried metric.
- Returns:
Sub-metric names supported for
metric_name.- Raises:
RuntimeError – If this object is not usable because
initialize()has not been called (or afterdeinitialize()without a subsequentinitialize()).ValueError – If the metric name or metric type is invalid.
cupti.cupti.cuptiError – If CUPTI reports a internal failure.
- get_metric_properties(
- metric_name: str,
Get properties for a metric.
- Parameters:
metric_name – Metric name to query (with or without extension).
- Returns:
A
MetricPropertiesobject with description, units, metric type, and collection scope.- Raises:
RuntimeError – If this object is not usable because
initialize()has not been called (or afterdeinitialize()without a subsequentinitialize()).ValueError – If
metric_nameis invalid or unsupported.cupti.cupti.cuptiError – If CUPTI reports an internal failure.
- cupti.profiler_host.get_supported_chips() list[str]#
Get the list of supported chips
- Returns:
Supported chip names.
- Return type:
- Raises:
cupti.cupti.cuptiError – If CUPTI reports internal failures.
- cupti.profiler_host.get_single_pass_sets(chip_name: str) list[str]#
Get single-pass metric set names for a chip.
- Parameters:
chip_name – Chip name for which single-pass metric sets are queried.
- Returns:
Single-pass metric set names supported on the chip.
- Return type:
- Raises:
ValueError – If
chip_nameis invalid or not supported.cupti.cupti.cuptiError – If CUPTI reports internal failures.
Note
This API is primarily useful for PM Sampling workflows where you need to select metrics that can be collected in a single pass.
- cupti.profiler_host.get_metrics_in_single_pass_set( ) list[str]#
Get metric names in a single-pass metric set for a chip.
- Parameters:
chip_name – Chip name to query.
set_name – Single-pass metric set name to query.
- Returns:
Metric names in the single-pass set.
- Return type:
- Raises:
ValueError – If
chip_nameorset_nameis invalid or unsupported.cupti.cupti.cuptiError – If CUPTI reports internal failures.
Note
This API is primarily useful for PM Sampling workflows when choosing metrics from a specific single-pass metric set.
- cupti.profiler_host.get_num_of_passes(config_image: ndarray) int#
Get the number of passes required to collect scheduled metrics.
- Parameters:
config_image – Config image returned by
ProfilerHost.create_config_image().- Returns:
Number of passes required for profiling.
- Return type:
- Raises:
ValueError – If
config_imageis empty.cupti.cupti.cuptiError – If CUPTI reports internal failures.
- cupti.profiler_host.get_max_num_hardware_metrics_per_pass(
- chip_name: str,
- profiler_type: ProfilerType,
Get the upper bound of hardware metrics (metric names which do not include _sass_ keyword) schedulable in one pass.
- Parameters:
chip_name – Chip name to query.
profiler_type – Profiler kind (for example
ProfilerType.PM_SAMPLING).
- Returns:
Maximum number of hardware metrics that can be scheduled in one pass.
- Return type:
- Raises:
ValueError – If
chip_nameorprofiler_typeis invalid or unsupported.cupti.cupti.cuptiError – If CUPTI reports internal failures.
Data structures#
- class cupti.profiler_host.MetricProperties(
- description: str,
- hw_unit: str,
- dim_unit: str,
- metric_type: MetricType,
- metric_collection_scope: MetricCollectionScope,
Bases:
objectProperties for a metric reported by
ProfilerHost.get_metric_properties().
Enumerations#
- class cupti.profiler_host.MetricType(value)#
Bases:
IntEnumSee
CUpti_MetricType.- COUNTER = 0#
- RATIO = 1#
- THROUGHPUT = 2#