Repository navigation
feat(hipdnn-integration-tests): add --benchmark timing for verified graphs #13915
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
SamuelReeder
merged 7 commits into
develop
from
users/sareeder/hipdnn-integration-perf-driver
Oct 27, 2026
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5d3bdf2
feat(hipdnn-integration-tests): add --benchmark timing for verified g…
SamuelReeder 4c34711
fix(hipdnn-integration-tests): address --benchmark review
SamuelReeder cdfbcd9
refactor(hipdnn-integration-tests): time --benchmark with Graph::auto…
SamuelReeder 5e480ee
fix(hipdnn-integration-tests): default --benchmark-warmup to 30
SamuelReeder 6d118ad
feat(hipdnn-integration-tests): report whether --benchmark timed a tu…
SamuelReeder 2929e22
fix(hipdnn-integration-tests): address --benchmark review comments
SamuelReeder 5e24c33
Merge branch 'develop' into users/sareeder/hipdnn-integration-perf-dr…
SamuelReeder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
160 changes: 160 additions & 0 deletions
160
dnn-providers/integration-tests/src/harness/Benchmark.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,160 @@ | ||
| // Copyright © Advanced Micro Devices, Inc., or its affiliates. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <iomanip> | ||
| #include <iostream> | ||
| #include <optional> | ||
| #include <sstream> | ||
| #include <string> | ||
|
|
||
| #include <gtest/gtest.h> | ||
|
|
||
| #include <hipdnn_frontend/Types.hpp> | ||
| #include <hipdnn_frontend/autotune/AutotuneTypes.hpp> | ||
| #include <hipdnn_plugin_sdk/GlobalKnobDefines.hpp> | ||
|
|
||
| namespace hipdnn_integration_tests | ||
| { | ||
|
|
||
| /// How --benchmark times one verified graph. | ||
| struct BenchmarkSettings | ||
| { | ||
| static constexpr int DEFAULT_TIMED_ITERATIONS = 20; | ||
| // The GPU idles between tests (input fill, reference, comparison), so each test | ||
| // starts cold. On MI210, quick-tier bundles read 4-60% slow with 1-10 warmup | ||
| // executions and settle after about 30. More timed iterations do not fix this. | ||
| static constexpr int DEFAULT_WARMUP_ITERATIONS = 30; | ||
|
|
||
| int timedIterations = DEFAULT_TIMED_ITERATIONS; | ||
| int warmupIterations = DEFAULT_WARMUP_ITERATIONS; | ||
| }; | ||
|
|
||
| /// The benchmark flags as typed, plus the flags that stop a test before it executes. | ||
| struct BenchmarkRequest | ||
| { | ||
| bool enabled = false; | ||
| std::optional<int> timedIterations; | ||
| std::optional<int> warmupIterations; | ||
| bool skipGraphValidation = false; | ||
| bool captureBundles = false; | ||
| bool writeSupportClaims = false; | ||
| }; | ||
|
|
||
| struct BenchmarkResolution | ||
| { | ||
| std::optional<BenchmarkSettings> settings; | ||
| std::optional<std::string> error; | ||
| }; | ||
|
|
||
| /// Settings for --benchmark, or the reason the flags cannot be used together. | ||
| /// | ||
| /// A mode that stops a test before it executes would leave --benchmark timing | ||
| /// nothing and the run green. Those combinations are refused instead. | ||
| inline BenchmarkResolution resolveBenchmark(const BenchmarkRequest& request) | ||
| { | ||
| if(!request.enabled) | ||
| { | ||
| if(request.timedIterations.has_value() || request.warmupIterations.has_value()) | ||
| { | ||
| return {std::nullopt, | ||
| "--benchmark-iterations and --benchmark-warmup require --benchmark"}; | ||
| } | ||
| return {}; | ||
| } | ||
|
|
||
| if(request.skipGraphValidation || request.captureBundles || request.writeSupportClaims) | ||
| { | ||
| return {std::nullopt, | ||
| "--benchmark cannot be combined with --skip-graph-validation, " | ||
| "--capture-bundles or --write-support-claims: those modes do not " | ||
| "execute the graph"}; | ||
| } | ||
|
|
||
| BenchmarkSettings settings; | ||
| settings.timedIterations = request.timedIterations.value_or(settings.timedIterations); | ||
| settings.warmupIterations = request.warmupIterations.value_or(settings.warmupIterations); | ||
| if(settings.timedIterations < 1) | ||
| { | ||
| return {std::nullopt, "--benchmark-iterations must be at least 1"}; | ||
| } | ||
| if(settings.warmupIterations < 0) | ||
| { | ||
| return {std::nullopt, "--benchmark-warmup must not be negative"}; | ||
| } | ||
| return {settings, std::nullopt}; | ||
| } | ||
|
|
||
| inline const char* toString(hipdnn_frontend::TimingQuality quality) | ||
| { | ||
| switch(quality) | ||
| { | ||
| case hipdnn_frontend::TimingQuality::DEVICE_ONLY: | ||
| return "DEVICE_ONLY"; | ||
| case hipdnn_frontend::TimingQuality::UNSTALLED: | ||
| return "UNSTALLED"; | ||
| case hipdnn_frontend::TimingQuality::INVALID: | ||
| default: | ||
| return "INVALID"; | ||
| } | ||
| } | ||
|
|
||
| /// True when the engine selected its solution by benchmarking candidates rather than | ||
| /// by its heuristics. The harness sets no knobs, so global.benchmarking keeps its | ||
| /// default (0 in every hipDNN provider). Only HIPDNN_FORCE_BENCHMARKING turns it on, | ||
| /// and only for engines that expose the knob (AutotuneResult::supportsExhaustive). | ||
| inline bool selectedByBenchmarking(const hipdnn_frontend::AutotuneResult& result) | ||
| { | ||
| return result.supportsExhaustive | ||
| && hipdnn_plugin_sdk::benchmarkingOverrideFromEnv().value_or(false); | ||
| } | ||
|
|
||
| /// Publishes the autotune result of one engine for the running test: a | ||
| /// "[ BENCHMARK ]" line on stdout and benchmark_* properties in --gtest_output | ||
| /// files. A result that did not succeed fails the test. | ||
| inline void reportBenchmark(const hipdnn_frontend::AutotuneResult& result) | ||
| { | ||
| if(!result.succeeded) | ||
| { | ||
| ADD_FAILURE() << "benchmark failed: " | ||
| << (result.errorMessage.empty() ? "the engine was not benchmarked" | ||
| : result.errorMessage); | ||
| return; | ||
| } | ||
|
|
||
| const auto ms = [](float value) { | ||
| std::ostringstream out; | ||
| out << std::fixed << std::setprecision(4) << value; | ||
| return out.str(); | ||
| }; | ||
|
|
||
| const auto minMs = ms(result.minTimeMs); | ||
| const auto robustMs = ms(result.robustTimeMs); | ||
| const auto meanMs = ms(result.avgTimeMs); | ||
| const auto stddevMs = ms(result.stddevMs); | ||
| const int tuned = selectedByBenchmarking(result) ? 1 : 0; | ||
|
|
||
| ::testing::Test::RecordProperty("benchmark_engine", result.engineName); | ||
| ::testing::Test::RecordProperty("benchmark_timing", toString(result.timingQuality)); | ||
| ::testing::Test::RecordProperty("benchmark_samples", result.iterationsRun); | ||
| ::testing::Test::RecordProperty("benchmark_min_ms", minMs); | ||
| ::testing::Test::RecordProperty("benchmark_robust_ms", robustMs); | ||
| ::testing::Test::RecordProperty("benchmark_mean_ms", meanMs); | ||
| ::testing::Test::RecordProperty("benchmark_stddev_ms", stddevMs); | ||
| ::testing::Test::RecordProperty("benchmark_tuned", tuned); | ||
|
|
||
| std::string testName = "<unknown test>"; | ||
|
SamuelReeder marked this conversation as resolved.
Resolved
|
||
| if(const auto* info = ::testing::UnitTest::GetInstance()->current_test_info()) | ||
| { | ||
| testName = std::string(info->test_suite_name()) + "." + info->name(); | ||
| } | ||
|
|
||
| std::cout << "[ BENCHMARK ] " << testName << ": engine=" << result.engineName | ||
| << " tuned=" << tuned << " timing=" << toString(result.timingQuality) | ||
| << " samples=" << result.iterationsRun << " min=" << minMs | ||
| << " ms robust=" << robustMs << " ms mean=" << meanMs << " ms stddev=" << stddevMs | ||
| << " ms\n"; | ||
| } | ||
|
|
||
| } // namespace hipdnn_integration_tests | ||
66 changes: 66 additions & 0 deletions
66
dnn-providers/integration-tests/src/harness/GraphBenchmark.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| // Copyright © Advanced Micro Devices, Inc., or its affiliates. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <cstdint> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| #include <hipdnn_frontend/Graph.hpp> | ||
| #include <hipdnn_frontend/autotune/AutotuneTypes.hpp> | ||
|
|
||
| #include "harness/Benchmark.hpp" | ||
| #include "harness/PlanWorkspace.hpp" | ||
| #include "harness/VariantPack.hpp" | ||
|
|
||
| namespace hipdnn_integration_tests | ||
| { | ||
|
|
||
| /// Times the engine of the plan `graph` already built, on the tensors in | ||
| /// `variantPack`. Graph::autotune() does the timing, limited to that one engine, | ||
| /// so the warmup, the stall gate, the retries and the statistics are the same as | ||
| /// in autotune. | ||
| inline hipdnn_frontend::AutotuneResult benchmarkGraph(hipdnn_frontend::graph::Graph& graph, | ||
| hipdnnHandle_t handle, | ||
| VariantPack& variantPack, | ||
| const BenchmarkSettings& settings) | ||
| { | ||
| hipdnn_frontend::AutotuneResult failed; | ||
|
|
||
| int64_t engineId = -1; | ||
| if(auto status = graph.get_execution_plan_engine_id(engineId); !status.is_good()) | ||
| { | ||
| failed.errorMessage = status.get_message(); | ||
| return failed; | ||
| } | ||
|
|
||
| auto workspace = allocatePlanWorkspace(graph, failed.errorMessage); | ||
| if(!workspace.has_value()) | ||
| { | ||
| return failed; | ||
| } | ||
|
|
||
| hipdnn_frontend::AutotuneConfig config; | ||
| config.strategy = hipdnn_frontend::AutotuneStrategy::FIXED_AVERAGE; | ||
|
SamuelReeder marked this conversation as resolved.
Resolved
|
||
| config.timedIterations = settings.timedIterations; | ||
| config.warmupIterations = settings.warmupIterations; | ||
| config.engineIdFilter = {engineId}; | ||
|
|
||
| // autotune() returns an error when no engine succeeds. The engine's own result | ||
| // explains why, so look for it first. | ||
| std::vector<hipdnn_frontend::AutotuneResult> results; | ||
| const auto status = graph.autotune(handle, variantPack, workspace->get(), config, {}, &results); | ||
| for(const auto& result : results) | ||
|
SamuelReeder marked this conversation as resolved.
Resolved
|
||
| { | ||
| if(result.engineId == engineId && !result.excludedByCaller) | ||
| { | ||
| return result; | ||
| } | ||
| } | ||
| failed.errorMessage = status.is_good() ? "autotune returned no result for the engine under test" | ||
| : status.get_message(); | ||
| return failed; | ||
| } | ||
|
|
||
| } // namespace hipdnn_integration_tests | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.