mirror of
https://github.com/NVIDIA/nvbench.git
synced 2026-07-12 18:17:49 +00:00
Do not resolve missing bulk files against CWD
Introduce has_robust_interval predicate and used it. It is used to check whether robust interval can be constructed before attempting that and falling back to mean/stdev construction otherwise
This commit is contained in:
@@ -865,9 +865,6 @@ def resolve_binary_filename(json_dir, binary_filename):
|
||||
if os.path.exists(parent_relative_filename):
|
||||
return parent_relative_filename
|
||||
|
||||
if os.path.exists(binary_filename):
|
||||
return binary_filename
|
||||
|
||||
return json_relative_filename
|
||||
|
||||
|
||||
@@ -1778,6 +1775,15 @@ def has_robust_estimate(summary):
|
||||
)
|
||||
|
||||
|
||||
def has_robust_interval(summary):
|
||||
return (
|
||||
summary.minimum is not None
|
||||
and summary.first_quartile is not None
|
||||
and summary.median is not None
|
||||
and summary.third_quartile is not None
|
||||
)
|
||||
|
||||
|
||||
def has_mean_estimate(summary):
|
||||
return summary.mean is not None and (
|
||||
summary.stdev_relative is not None or summary.stdev is not None
|
||||
@@ -1791,7 +1797,12 @@ def select_relative_dispersion(relative_dispersion, absolute_dispersion, center)
|
||||
|
||||
|
||||
def compute_common_time_estimates(ref_timing, cmp_timing):
|
||||
if has_robust_estimate(ref_timing) and has_robust_estimate(cmp_timing):
|
||||
if (
|
||||
has_robust_estimate(ref_timing)
|
||||
and has_robust_interval(ref_timing)
|
||||
and has_robust_estimate(cmp_timing)
|
||||
and has_robust_interval(cmp_timing)
|
||||
):
|
||||
return (
|
||||
TimeEstimate(
|
||||
center=ref_timing.median,
|
||||
|
||||
@@ -658,6 +658,31 @@ def test_gpu_timing_data_warns_when_lazy_sample_read_fails(tmp_path, nvbench_com
|
||||
assert timing.samples is None
|
||||
|
||||
|
||||
def test_bulk_file_resolution_does_not_fall_back_to_cwd(
|
||||
monkeypatch, tmp_path, nvbench_compare
|
||||
):
|
||||
json_dir = tmp_path / "json"
|
||||
cwd = tmp_path / "cwd"
|
||||
json_dir.mkdir()
|
||||
cwd.mkdir()
|
||||
np.array([123.0], dtype="<f4").tofile(cwd / "samples.bin")
|
||||
monkeypatch.chdir(cwd)
|
||||
|
||||
assert nvbench_compare.resolve_binary_filename(str(json_dir), "samples.bin") == str(
|
||||
json_dir / "samples.bin"
|
||||
)
|
||||
|
||||
timing = nvbench_compare.extract_gpu_timing_data(
|
||||
[
|
||||
make_binary_summary(nvbench_compare, "SAMPLE_TIMES_TAG", "samples.bin", 1),
|
||||
],
|
||||
str(json_dir),
|
||||
)
|
||||
|
||||
with pytest.warns(RuntimeWarning, match="failed to read"):
|
||||
assert timing.samples is None
|
||||
|
||||
|
||||
def test_compare_gpu_timings_classifies_common_cases(tmp_path, nvbench_compare):
|
||||
ref_timing = make_gpu_timing_data(nvbench_compare, mean=1.0, stdev_relative=0.05)
|
||||
|
||||
@@ -674,6 +699,34 @@ def test_compare_gpu_timings_classifies_common_cases(tmp_path, nvbench_compare):
|
||||
assert undecided.max_noise == pytest.approx(0.05)
|
||||
assert undecided.reason.code == "noise_too_high"
|
||||
|
||||
partial_robust = nvbench_compare.compare_gpu_timings(
|
||||
make_gpu_timing_data(
|
||||
nvbench_compare,
|
||||
minimum=0.8,
|
||||
maximum=1.2,
|
||||
mean=1.0,
|
||||
stdev=0.1,
|
||||
stdev_relative=0.1,
|
||||
median=10.0,
|
||||
interquartile_range_relative=0.01,
|
||||
),
|
||||
make_gpu_timing_data(
|
||||
nvbench_compare,
|
||||
minimum=0.85,
|
||||
maximum=1.25,
|
||||
mean=1.05,
|
||||
stdev=0.1,
|
||||
stdev_relative=0.1,
|
||||
median=11.0,
|
||||
interquartile_range_relative=0.01,
|
||||
),
|
||||
)
|
||||
assert partial_robust is not None
|
||||
assert partial_robust.ref_time == pytest.approx(1.0)
|
||||
assert partial_robust.cmp_time == pytest.approx(1.05)
|
||||
assert partial_robust.ref_interval.center == pytest.approx(1.0)
|
||||
assert partial_robust.cmp_interval.center == pytest.approx(1.05)
|
||||
|
||||
ref_interval_timing = make_gpu_timing_data(
|
||||
nvbench_compare,
|
||||
minimum=1.0,
|
||||
|
||||
Reference in New Issue
Block a user