3. NvRules API
- class NvRules.IAction
Bases:
object
The
IAction
represents a profile result such as a CUDA kernel in a single range or a range itself in range-based profiling, for which zero or more metrics were collected.- __iter__()
- __len__()
- name(*args)
Get the name of the result the
IAction
object represents.- Parameters
name_base (
int
, optional) – The desired name base. Defaults toNameBase_FUNCTION
.- Returns
The name of the result (potentially in a specific name base).
- Return type
- nvtx_state()
Get the NVTX state associated with this action.
- Returns
The associated
INvtxState
orNone
if no state is associated.- Return type
- ptx_by_pc(address)
Get the PTX associated with an address.
- sass_by_pc(address)
Get the SASS associated with an address.
- source_files()
Get the source files associated with this action along with their content.
If content is not available for a file (e.g. because it hadn’t been imported into the report), the file name will map to an empty string.
- source_info(address)
Get the source info for a function address within this action.
Addresses are commonly obtained as correlation IDs of source-correlated metrics.
- class NvRules.IContext
Bases:
NvRules.IBaseContext
The
IContext
class is the top-level object representing an open report.It can be created by calling the
load_report
function.- __getitem__(key)
Get one or more
IRange
objects by index or by slice.Returns:
IRange
|tuple
ofIRange
: AnIRange
object or atuple
ofIRange
objects.- Raises
IndexError – If
key
is out of range for theIContext
.
- __iter__()
- __len__()
- controller()
Get the controller object.
- Returns
The controller object.
- Return type
- num_ranges()
- class NvRules.IController
Bases:
object
Controller interface.
The controller can be used to interact with the tool runtime, e.g., to signal the tools to propose a follow-up rule.
- get_message_vault()
Get an
IMessageVault
object that can be used for message passing between rules.- Returns
- class NvRules.IEvaluator
Bases:
NvRules.IBaseContext
Evaluator interface.
The evaluator is used during rule setup to pass information about rule dependencies to the tool. For most cases, its Python wrapper functions
require_metrics
andrequire_rules
should be used instead for convenience.
- class NvRules.IFrontend
Bases:
object
The frontend is responsible for relaying messages and results to the caller via user interfaces, logs or output files.
- Deprecated Attributes and Their Replacement:
MarkerKind_SASS -
MarkerKind.SASS
MarkerKind_SOURCE -
MarkerKind.SOURCE
MsgType_MSG_NONE -
MsgType.NONE
MsgType_MSG_OK -
MsgType.OK
MsgType_MSG_OPTIMIZATION -
MsgType.OPTIMIZATION
MsgType_MSG_WARNING -
MsgType.WARNING
MsgType_MSG_ERROR -
MsgType.ERROR
- SpeedupType_LOCAL
The proportional increase in efficiency of the hardware usage when viewing the performance problem in isolation.
- Type
- focus_metric(message_id, metric_name, metric_value, severity, info)
Create a rule focus metric message.
Issues a focus metric message to the frontend, e.g. to indicate a key metric that triggered the rule output.
- Parameters
message_id (
int
) – The prior message to associate with.metric_name (
str
) – Name of the focus metric.metric_value (
float
) – Value of the focus metric.severity (
int
) – Indicates the impact orseverity on the result.info (
str
) – Descriptive string for further information, e.g., the calculation leading to this metric being focused.
- Returns
- Return type
- generate_table(message_id, header, data, config=None)
Generate a table in the frontend.
This function attaches a table to the pre-existing rule message given by message_id. It can be called multiple times to attach multiple tables to the same message.
The table can be customized by passing a dict to the config parameter. The table can contain a title, description, a column to sort by, and a global styling. Additionally, the table can have per-column configurations, which can specify a header tooltip, relative column width, and styling for the header and data cells.
This is an example of a valid config dict:
config = { "title": "My table title", "description": "Short description of the table", "sort_by": { "column": "MyColumn", # specify column by name or index "order": "ascending", # in ascending order (default) }, "per_column_configs": { # overwrites global styling for individual columns "MyColumn": { # can use column name or index "tooltip": "Explanation of MyColumn", # tooltip for the header "relative_width": 0.5, # relative width of the column "style": { "header": {"bold": True}, "data": {"italic": True}, } }, }, }
- Parameters
message_id (int) – The message to which to attach the table to.
data (list[list[int | float | str | Any]]) –
The table data in row-major format. Any refers to any type that implements __str__. Each column must only have elements of the same type, and all columns must have the same length.
- class:str values may contain substrings with the following special link formats
@url:<hypertext>:<external link>@ - To add a external link for a hypertext.
@sass:<address>:<hypertext>@ - To add a link to the hypertext to open the SASS address line on the Source page.
@source:<file name>:<line number>:<hypertext>@ - To add a link to the hypertext to open the source file at the specified line number on the Source page.
@section:<section identifier>:<hypertext>@ - To add a link to the hypertext to jump to the respective section.
config (dict[str, Any] | None) – Configuration options for the table. Defaults to None.
- Raises
TypeError – If types of elements within a column are mixed.
ValueError – If columns have different lengths, or len(header) does not match the number of columns in data.
- load_chart_from_file(filename)
Load a ProfilerSection google protocol buffer chart from a file.
- Parameters
filename (
str
) – The file name.
- message(*args)
Issues a message to the frontend.
- Parameters
type (
int
, optional) – The message type.str (
str
) –The message content.
- The message may contain substrings with the following special link formats:
@url:<hypertext>:<external link>@ - To add a external link for a hypertext.
@sass:<address>:<text>@ - To add a SASS address to the cell.
@source:<file name>:<line number>:<hypertext>@ - To add a link to the hypertext to open the source file at the specified line number on the Source page.
@section:<section identifier>:<hypertext>@ - To add a link to the hypertext to jump to the respective section.
name (
str
, optional) – The name of the message.
- Returns
A message ID that is unique in this rule invocation.
- Return type
- receive_dict_from_parent(parent_id)
Receive a dictionary from a parent rule.
Receive a dictionary of type dict[str,float] sent using
IFrontend.send_dict_to_children
. If the parent id does not represent a pre-specified parent rule of this rule, or in case the parent rule has not been executed, an empty dict will be returned.
- send_dict_to_children(dict)
Send a dictionary to all child rules.
Sends a Python dictionary of type dict[str,float] to all rules that specify this rule as a parent rule. Child rules can retrieve the message using
IFrontend.receive_dict_from_parent
. In case this function is called repeatedly, the dict is updated accordingly, thereby adding new key-value pairs, and overwriting values of pre-existing keys.- Parameters
dict (
dict
) – The dictionary to send.
- source_marker(*args)
Create a rule source marker.
- speedup(message_id, type, estimated_speedup)
Rule estimated speedup message.
Issues an estimated speedup associated with a message to the frontend.
- Parameters
message_id (
int
) – ID of the existing message.type (
int
) – The SpeedupType. If GLOBAL, it indicates what proportional decrease in workload runtime could potentially be achieved, when following the guidelines of the rule. If LOCAL, it indicates what increase in the efficiency of the hardware usage within the context of the performance problem could be achieved.
- Returns
- Return type
- class NvRules.IMessageVault
Bases:
object
Passes messages between rules.
- Get(ruleId)
Retrieve the message associated with a rule from the vault.
In case the rule is unknown, an empty message is returned.
- Put(ruleId, message)
Commit a message associated with a rule to the vault.
In case multiple messages associated with the same rule are committed, the messages are merged, in such a way that new key-value pairs are added, and values of pre-existing keys are updated.
- class NvRules.IMetric
Bases:
object
Represents a single, named metric. An
IMetric
can carry one value or multiple ones if it is an instanced metric.- MetricSubtype_PEAK_SUSTAINED_ACTIVE_PER_SECOND
Metric subtype for peak sustained active per-second metrics.
- Type
- MetricSubtype_PEAK_SUSTAINED_ELAPSED_PER_SECOND
Metric subtype for peak sustained elapsed per-second metrics.
- Type
- MetricSubtype_PCT_OF_PEAK_SUSTAINED_ACTIVE
Metric subtype for percentage of peak sustained active metrics.
- Type
- MetricSubtype_PCT_OF_PEAK_SUSTAINED_ELAPSED
Metric subtype for percentage of peak sustained elapsed metrics.
- Type
- correlation_ids()
Get a metric object for this metric’s instance value’s correlation IDs.
Returns a new
IMetric
representing the correlation IDs for the metric’s instance values. UseIMetric.has_correlation_ids
to check if this metric has correlation IDs for its instance values. Correlation IDs are used to associate instance values with the instance their value represents. In the returned new metric object, the correlation IDs are that object’s instance values.If the metric does not have any correlation IDs, this function will return
None
.
- has_correlation_ids()
Check if the metric has correlation IDs.
- has_value(*args)
Check if the metric or metric instance has a value.
- kind(*args)
Get the metric or metric instance value kind.
- num_instances()
Get the number of instance values for this metric.
Not all metrics have instance values. If a metric has instance values, it may also have
IMetric.correlation_ids
matching these instance values.- Returns
The number of instances for this metric.
- Return type
- rollup_operation()
Get the type of rollup operation for this metric.
- Returns
The rollup operation type.
- Return type
- class NvRules.IMutableMetric
Bases:
NvRules.IMetric
Represents a single, named mutable metric. An
IMutableMetric
can carry one value or multiple ones if it is an instanced metric. In comparison toIMetric
,IMutableMetric
can be modified by assigning it a new value and/or instance values. The metric kind is determined by the assigned value(s).- mutable_correlation_ids()
Get a mutable metric object for this metric’s instance value’s correlation IDs.
Returns a new
IMutableMetric
representing the correlation IDs for the metric’s instance values. Correlation IDs are used to associate instance values with the instance their value represents. In the returned new metric object, the correlation IDs are that object’s instance values.- Returns
The new
IMutableMetric
object representing the correlation IDs for this metric’s instance values.- Return type
- class NvRules.INvtxDomainInfo
Bases:
object
Represents a single NVTX domain of the NVTX state, including all ranges associated with this domain.
- __str__()
Get a human-readable representation of this
INvtxDomainInfo
.- Returns
The name of the
INvtxDomainInfo
.- Return type
- name()
Get a human-readable representation of this
INvtxDomainInfo
.- Returns
The name of the
INvtxDomainInfo
.- Return type
- push_pop_range(idx)
Get a push/pop range object by index.
The index is identical to the range’s order on the call stack.
- Returns
The requested
INvtxRange
orNone
if the index is out of range.- Return type
- push_pop_ranges()
Get a sorted list of push/pop range names.
Get the sorted list of stacked push/pop range names in this domain, associated with the current
INvtxState
.
- start_end_range(idx)
Get a start/end range object by index.
- Returns
The requested
INvtxRange
orNone
if the index is out of range.- Return type
- start_end_ranges()
Get a sorted list of start/end range names.
Get the sorted list of start/end range names in this domain, associated with the current
INvtxState
.
- class NvRules.INvtxRange
Bases:
object
Represents a single NVTX Push/Pop or Start/End range.
- category()
Get the category attribute value.
- Returns
The category attribute value. If
INvtxRange.has_attributes
returnsFalse
, this will return0
.- Return type
- color()
Get the color attribute value.
- Returns
The color attribute value. If
INvtxRange.has_attributes
returnsFalse
, this will return0
.- Return type
- has_attributes()
Check if range has event attributes.
- message()
Get the message attribute value.
- Returns
The message attribute value. If
INvtxRange.has_attributes
returnsFalse
, this will return the empty string.- Return type
- class NvRules.INvtxState
Bases:
object
Represents the NVTX (Nvidia Tools Extensions) state associated with a single
IAction
.- __getitem__(key)
Get an
INvtxDomainInfo
object by ID.- Parameters
key (
int
) – The ID of theINvtxDomainInfo
object.- Returns
An
INvtxDomainInfo
object.- Return type
- Raises
- __iter__()
Get an iterator over the
INvtxDomainInfo
objects of thisINvtxState
.- Returns
An iterator over the
INvtxDomainInfo
objects.- Return type
- __len__()
Get the number of
INvtxDomainInfo
objects of thisINvtxState
.- Returns
The number of
INvtxDomainInfo
objects.- Return type
- domain_by_id(id)
Get a
INvtxDomainInfo
object by ID.Use
INvtxState.domains
to retrieve the list of valid domain IDs.- Parameters
id (
int
) – The ID of the request domain.- Returns
The requested
INvtxDomainInfo
object.- Return type
- class NvRules.IRange
Bases:
object
Represents a serial, ordered stream of execution, such as a CUDA stream. It holds one or more actions that were logically executing in this range.
- __getitem__(key)
- __len__()
Get the number of
IAction
objects in thisIRange
.- Returns
The number of class:IAction objects.
- Return type
- actions_by_nvtx(includes, excludes)
Get a set of indices to IAction objects by their NVTX state. The state is defined using a series of includes and excludes.
- class NvRules.MarkerKind
Bases:
enum.IntEnum
Enum representing the kind of a source marker.
- SASS
The marker will be associated with a SASS instruction.
- SOURCE
The marker will be associated with a Source line.
- NONE
No specific kind of marker.
- class NvRules.MsgType
Bases:
enum.IntEnum
Enum representing the type of the message.
- NONE
No specific type for this message.
- OK
The message is informative.
- OPTIMIZATION
The message represents a suggestion for performance optimization.
- WARNING
The message represents a warning or fixable issue.
- ERROR
The message represents an error, potentially in executing the rule.
- NvRules.get_evaluator(h)
Return the
IEvaluator
object from the context handle.- Parameters
h (
int
) – The context handle.- Returns
The evaluator object.
- Return type
- NvRules.get_version(h)
Get version number of this interface.
- NvRules.require_metrics(handle, metrics)
Convenience wrapper for
NvRules.IEvaluator.require_metric
.- Parameters
handle (
int
) – The context handle, obtained fromget_context
.metrics (
list
) – List of metric names.
- NvRules.require_rules(handle, rules)
Convenience wrapper for
NvRules.IEvaluator.require_rule
.- Parameters
handle (
int
) – The context handle, obtained fromget_context
.rules (
list
) – List of rule identifiers.
Notices
Notices
ALL NVIDIA DESIGN SPECIFICATIONS, REFERENCE BOARDS, FILES, DRAWINGS, DIAGNOSTICS, LISTS, AND OTHER DOCUMENTS (TOGETHER AND SEPARATELY, “MATERIALS”) ARE BEING PROVIDED “AS IS.” NVIDIA MAKES NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
Information furnished is believed to be accurate and reliable. However, NVIDIA Corporation assumes no responsibility for the consequences of use of such information or for any infringement of patents or other rights of third parties that may result from its use. No license is granted by implication of otherwise under any patent rights of NVIDIA Corporation. Specifications mentioned in this publication are subject to change without notice. This publication supersedes and replaces all other information previously supplied. NVIDIA Corporation products are not authorized as critical components in life support devices or systems without express written approval of NVIDIA Corporation.
Trademarks
NVIDIA and the NVIDIA logo are trademarks or registered trademarks of NVIDIA Corporation in the U.S. and other countries. Other company and product names may be trademarks of the respective companies with which they are associated.