reprospect.tools.ncu.report module
- class reprospect.tools.ncu.report.Action(index: int, nvtx_range: dataclasses.InitVar[Any])View on GitHub
Bases:
objectWrapper around IAction.
- __init__(index: int, nvtx_range: dataclasses.InitVar[Any]) None
- domains: tuple[NvtxDomain, ...]
- nvtx_range: dataclasses.InitVar[Any]
- class reprospect.tools.ncu.report.NvtxDomain(index: int, nvtx_state: dataclasses.InitVar[Any])View on GitHub
Bases:
objectWrapper around INvtxDomainInfo.
- __init__(index: int, nvtx_state: dataclasses.InitVar[Any]) None
- nvtx_state: dataclasses.InitVar[Any]
- reprospect.tools.ncu.report.ProfilingMetricData: TypeAlias = int | float | dict[str, int | float] | reprospect.tools.ncu.metrics.MetricCorrelationData | str
Metric data in profiling results.
- class reprospect.tools.ncu.report.ProfilingMetrics(data: dict[str, int | float | dict[str, int | float] | MetricCorrelationData | str])View on GitHub
Bases:
Mapping[str,int|float|dict[str,int|float] |MetricCorrelationData|str]Mapping of profiling metric keys to their values.
Note
It is not decorated with
dataclasses.dataclass()because of https://github.com/mypyc/mypyc/issues/1061.
- class reprospect.tools.ncu.report.ProfilingResults(data: dict[str, ProfilingResults | ProfilingMetrics] | None = None)View on GitHub
Bases:
TreeMixinNested tree data structure for storing profiling results.
The data structure consists of internal nodes and leaf nodes:
The internal nodes are themselves
ProfilingResultsinstances. They organise results hierarchically by the profiling range (e.g. NVTX range) that they were obtained from, terminating by the kernel name.The leaf nodes contain the actual profiling metric key-value pairs. Any type implementing the protocol
ProfilingMetricscan be used as a profiling metrics entry.
This class provides convenient methods for hierarchical data access and manipulation.
Example structure:
Profiling results └── 'nvtx range' ├── 'nvtx region' │ └── 'kernel' │ ├── 'metric i' -> ProfilingMetricData │ └── 'metric ii' -> ProfilingMetricData └── 'other nvtx region' └── 'other kernel' ├── 'metric i' -> ProfilingMetricData └── 'metric ii' -> ProfilingMetricDataNote
Using a hierarchical data structure from a package such as hatchet could be a direction to explore in the future.
Note
It is not decorated with
dataclasses.dataclass()because of https://github.com/mypyc/mypyc/issues/1061.- __init__(data: dict[str, ProfilingResults | ProfilingMetrics] | None = None) NoneView on GitHub
- aggregate_metrics(accessors: Iterable[str], keys: Iterable[str] | None = None) dict[str, int | float]View on GitHub
Aggregate metric values across multiple leaf nodes with profiling metrics at accessor path accessors.
- Parameters:
keys – Specific metric keys to aggregate. If
None, uses all keys from the first leaf node.
- assign_metrics(accessors: Sequence[str], data: ProfilingMetrics) NoneView on GitHub
Set the leaf node with profiling metrics data at accessor path accessors.
Creates the internal nodes in the hierarchy if needed.
- data: Final[dict[str, ProfilingResults | ProfilingMetrics]]
- iter_metrics(accessors: Iterable[str] = ()) Generator[tuple[str, ProfilingMetrics], None, None]View on GitHub
Query the accessor path accessors, check that it leads to an internal node, check that all entries are leaf nodes with profiling metrics, and return an iterator over these leaf nodes with profiling metrics.
- query(accessors: Iterable[str]) ProfilingResults | ProfilingMetricsView on GitHub
Get the internal node in the hierarchy or the leaf node with profiling metrics at accessor path accessors.
- query_filter(accessors: Iterable[str], predicate: Callable[[str], bool]) ProfilingResultsView on GitHub
Query the accessor path accessors, check that it leads to an internal node, and return a new
ProfilingResultswith only the entries whose key satisfies predicate.
- query_metrics(accessors: Iterable[str]) ProfilingMetricsView on GitHub
Query the accessor path accessors, check that it leads to a leaf node with profiling metrics, and return this leaf node with profiling metrics.
- query_single_next(accessors: Iterable[str]) tuple[str, ProfilingResults | ProfilingMetrics]View on GitHub
Query the accessor path accessors, check that it leads to an internal node with exactly one entry, and return this single entry.
This member function is useful for instance to access a single kernel within an NVTX range or region.
>>> from reprospect.tools.ncu import ProfilingResults >>> results = ProfilingResults() >>> results.assign_metrics(('my_nvtx_range', 'my_nvtx_region', 'my_kernel'), {'my_metric' : 42}) >>> results.query_single_next(('my_nvtx_range', 'my_nvtx_region')) ('my_kernel', {'my_metric': 42})
- query_single_next_metrics(accessors: Iterable[str]) tuple[str, ProfilingMetrics]View on GitHub
Query the accessor path accessors, check that it leads to an internal node with exactly one entry, check that this entry is a leaf node with profiling metrics, and return this leaf node with profiling metrics.
- to_tree() TreeView on GitHub
Convert to a
rich.tree.Treefor nice printing.
- class reprospect.tools.ncu.report.Range(index: int, report: dataclasses.InitVar[Any], includes: dataclasses.InitVar[Optional[Iterable[str]]] = None, excludes: dataclasses.InitVar[Optional[Iterable[str]]] = None)View on GitHub
Bases:
objectWrapper around IRange.
This class loads the actions that are in the range.
If both
includesandexcludesare empty, load all actions inrange.- __init__(index: int, report: dataclasses.InitVar[Any], includes: dataclasses.InitVar[Optional[Iterable[str]]] = None, excludes: dataclasses.InitVar[Optional[Iterable[str]]] = None) None
- excludes: dataclasses.InitVar[Optional[Iterable[str]]] = None
- includes: dataclasses.InitVar[Optional[Iterable[str]]] = None
- report: dataclasses.InitVar[Any]
- class reprospect.tools.ncu.report.Report(*, path: Path | None = None, name: str | None = None, command: Command | None = None)View on GitHub
Bases:
objectThis class is a wrapper around the Python tool provided by NVIDIA Nsight Compute to parse its reports.
In particular, the NVIDIA Python tool (
ncu_report) provides low-level access to the collected data by iterating over ranges and actions. This class uses these functionalities to extract all the collected data into a custom data structure of typeProfilingResults. This data structures is a nested tree data structure that provides a higher level, direct access to the data of interest by NVTX range (if NVTX is used) and by demangled kernel name.References:
https://docs.nvidia.com/nsight-compute/CustomizationGuide/index.html#python-report-interface
https://docs.python.org/3/library/importlib.html#importing-a-source-file-directly
- __init__(*, path: Path | None = None, name: str | None = None, command: Command | None = None) NoneView on GitHub
Load the report
<path>/<name>.ncu-repor the report generated byreprospect.tools.ncu.session.Command.
- collect_metrics_from_action(*, metrics: Iterable[Metric | MetricCorrelation | MetricDeviceAttribute], action: Action) dict[str, int | float | dict[str, int | float] | MetricCorrelationData | str]View on GitHub
Collect values of the metrics in the action.
References:
- extract_results_in_range(metrics: Collection[Metric | MetricCorrelation | MetricDeviceAttribute], range_idx: int = 0, includes: Iterable[str] | None = None, excludes: Iterable[str] | None = None, demangler: type[CuppFilt | LlvmCppFilt] | None = None) ProfilingResultsView on GitHub
Extract the metrics of the actions in the range with ID range_idx. Possibly filter by NVTX with includes and excludes.
- Parameters:
metrics – Must be iterable from start to end many times.
- classmethod fill_metric(action: Action, metric: Metric) int | float | dict[str, int | float]View on GitHub
Loop over submetrics of metric.
- classmethod get_metric_by_name(*, action: Action, metric: str)View on GitHub
Read a metric in action.
- reprospect.tools.ncu.report.load_ncu_report() ModuleTypeView on GitHub
Attempt to load the Nsight Compute Python interface (
ncu_report).Priority:
If
ncu_reportis already imported, return it.Try a regular
import ncu_report(for users who setPYTHONPATH).Try to locate
ncuviashutil.which, deduce version, and load the bundled Python module from Nsight Compute installation path.