diff --git a/python/scripts/nvbench_compare.py b/python/scripts/nvbench_compare.py index 180e42d..276643d 100644 --- a/python/scripts/nvbench_compare.py +++ b/python/scripts/nvbench_compare.py @@ -7,10 +7,12 @@ import argparse import math import os import sys +import warnings from collections import Counter from dataclasses import dataclass from enum import Enum -from typing import Any, Mapping +from functools import cached_property +from typing import Any, Callable, Mapping import jsondiff import numpy as np @@ -41,10 +43,34 @@ GPU_TIME_IR_RELATIVE_TAG = "nv/cold/time/gpu/ir/relative" SAMPLE_TIMES_TAG = "nv/json/bin:nv/cold/sample_times" SAMPLE_FREQUENCIES_TAG = "nv/json/freqs-bin:nv/cold/sample_freqs" +# The reader returns an object supporting the buffer protocol. Python 3.10 does +# not provide a standard Buffer type annotation. +Float32Reader = Callable[[str], object] + + +def read_float32_file(filename: str) -> object: + return np.fromfile(filename, dtype=" np.ndarray | None: + return read_float32_binary( + self.count, self.filename, self.json_dir, self.description, self.reader + ) + + @dataclass(frozen=True) class GpuTimingData: minimum: float | None @@ -55,8 +81,20 @@ class GpuTimingData: median: float | None interquartile_range: float | None interquartile_range_relative: float | None - samples: np.ndarray | None = None - frequencies: np.ndarray | None = None + sample_source: Float32BinarySource | None = None + frequency_source: Float32BinarySource | None = None + + @cached_property + def samples(self) -> np.ndarray | None: + if self.sample_source is None: + return None + return self.sample_source.values + + @cached_property + def frequencies(self) -> np.ndarray | None: + if self.frequency_source is None: + return None + return self.frequency_source.values @dataclass(frozen=True) @@ -342,45 +380,76 @@ def resolve_binary_filename(json_dir, binary_filename): return json_relative_filename -def read_float32_binary(count, filename, json_dir): - if count is None or filename is None or json_dir is None: - return None +def warn_unavailable_bulk_data(description, message): + warnings.warn( + f"Could not use NVBench {description} data: {message}; treating it as unavailable", + RuntimeWarning, + stacklevel=3, + ) + +def read_float32_binary(count, filename, json_dir, description, reader): filename = resolve_binary_filename(json_dir, filename) try: - values = np.fromfile(filename, dtype="