OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[GPU] Introduce OV_GPU_AVERAGE_COUNTERS env variable (#35673)
Egor Duplenskii42df57ead527
diff --git a/src/plugins/intel_gpu/include/intel_gpu/runtime/debug_configuration.hpp b/src/plugins/intel_gpu/include/intel_gpu/runtime/debug_configuration.hppindex d5e8b2c0562..ce9fa64e408 100644--- a/src/plugins/intel_gpu/include/intel_gpu/runtime/debug_configuration.hpp+++ b/src/plugins/intel_gpu/include/intel_gpu/runtime/debug_configuration.hpp@@ -59,9 +59,11 @@ static constexpr const char* prefix = "GPU_Debug: ";#define GPU_DEBUG_DEFINE_MEM_LOGGER(stage) \cldnn::instrumentation::mem_usage_logger mem_logger{stage, ov::intel_gpu::ExecutionConfig::get_verbose() >= 2};-#define GPU_DEBUG_PROFILED_STAGE(stage) \+#define GPU_DEBUG_PROFILED_STAGE(stage) \auto stage_prof = cldnn::instrumentation::profiled_stage<primitive_inst>( \- !get_config().get_dump_profiling_data_path().empty(), *this, stage)+ !get_config().get_dump_profiling_data_path().empty() || \+ !get_config().get_average_counters().empty(), \+ *this, stage)#define GPU_DEBUG_PROFILED_STAGE_CACHE_HIT(val) stage_prof.set_cache_hit(val)#define GPU_DEBUG_PROFILED_STAGE_MEMALLOC_INFO(info) stage_prof.add_memalloc_info(info)diff --git a/src/plugins/intel_gpu/include/intel_gpu/runtime/internal_properties.hpp b/src/plugins/intel_gpu/include/intel_gpu/runtime/internal_properties.hppindex 35d02bb6bfe..3ff1d121895 100644--- a/src/plugins/intel_gpu/include/intel_gpu/runtime/internal_properties.hpp+++ b/src/plugins/intel_gpu/include/intel_gpu/runtime/internal_properties.hpp@@ -146,6 +146,7 @@ static constexpr Property<bool, ov::PropertyMutability::RW> disable_onednn_post_static constexpr Property<std::string, PropertyMutability::RW> dump_graphs_path{"GPU_DUMP_GRAPHS_PATH"};static constexpr Property<std::string, ov::PropertyMutability::RW> dump_profiling_data_path{"GPU_DUMP_PROFILING_DATA_PATH"};static constexpr Property<bool, ov::PropertyMutability::RW> dump_profiling_data_per_iter{"GPU_DUMP_PROFILING_DATA_PER_ITER"};+static constexpr Property<std::string, ov::PropertyMutability::RW> average_counters{"GPU_AVERAGE_COUNTERS"};static constexpr Property<std::string, ov::PropertyMutability::RW> dump_sources_path{"GPU_DUMP_SOURCES_PATH"};static constexpr Property<std::string, ov::PropertyMutability::RW> dump_tensors_path{"GPU_DUMP_TENSORS_PATH"};static constexpr Property<std::string, ov::PropertyMutability::RW> dry_run_path{"GPU_DRY_RUN_PATH"};diff --git a/src/plugins/intel_gpu/include/intel_gpu/runtime/options.inl b/src/plugins/intel_gpu/include/intel_gpu/runtime/options.inlindex dcdd6ab71d6..7104d60393c 100644--- a/src/plugins/intel_gpu/include/intel_gpu/runtime/options.inl+++ b/src/plugins/intel_gpu/include/intel_gpu/runtime/options.inl@@ -74,6 +74,7 @@ OV_CONFIG_DEBUG_GLOBAL_OPTION(ov::intel_gpu, debug_config, "", "Path to debug coOV_CONFIG_DEBUG_OPTION(ov::intel_gpu, disable_onednn_post_ops_opt, false, "Disable optimization pass for onednn post-ops")OV_CONFIG_DEBUG_OPTION(ov::intel_gpu, dump_profiling_data_path, "", "Save csv file with per-stage and per-primitive profiling data to specified folder")+OV_CONFIG_DEBUG_OPTION(ov::intel_gpu, average_counters, "", "Save csv file with per-primitive averaged execution time. Output format matches benchmark_app --report_type average_counters and OV_CPU_AVERAGE_COUNTERS")OV_CONFIG_DEBUG_OPTION(ov::intel_gpu, dump_graphs_path, "", "Save intermediate graph representations during model compilation pipeline to specified folder")OV_CONFIG_DEBUG_OPTION(ov::intel_gpu, dump_sources_path, "", "Save generated sources for each kernel to specified folder")OV_CONFIG_DEBUG_OPTION(ov::intel_gpu, dump_tensors_path, "", "Save intermediate in/out tensors of each primitive to specified folder")diff --git a/src/plugins/intel_gpu/src/graph/impls/onednn/primitive_onednn_base.h b/src/plugins/intel_gpu/src/graph/impls/onednn/primitive_onednn_base.hindex 4970986e7f0..394855a1de9 100644--- a/src/plugins/intel_gpu/src/graph/impls/onednn/primitive_onednn_base.h+++ b/src/plugins/intel_gpu/src/graph/impls/onednn/primitive_onednn_base.h@@ -69,7 +69,8 @@ struct typed_primitive_onednn_impl : public typed_primitive_impl<PType> {_pd(),_prim() {_enable_profiling = config.get_enable_profiling();- GPU_DEBUG_IF(!config.get_dump_profiling_data_path().empty()) {+ GPU_DEBUG_IF(!config.get_dump_profiling_data_path().empty() ||+ !config.get_average_counters().empty()) {_enable_profiling = true;}}diff --git a/src/plugins/intel_gpu/src/graph/network.cpp b/src/plugins/intel_gpu/src/graph/network.cppindex 8bcd6c6b3a4..2b71b98e845 100644--- a/src/plugins/intel_gpu/src/graph/network.cpp+++ b/src/plugins/intel_gpu/src/graph/network.cpp@@ -55,6 +55,7 @@#include <sys/stat.h>#include <chrono>#include <thread>+#include <filesystem>#endifnamespace cldnn {@@ -139,8 +140,80 @@ void dump_perf_data_raw(std::string dump_path, bool per_iter_mode, const std::li}}+// Dumps a per-primitive averaged execution time CSV with the same schema as+// benchmark_app --report_type average_counters and the CPU plugin's+// OV_CPU_AVERAGE_COUNTERS feature, so that aggregate-average-counters.py and+// other tooling can be reused across plugins.+void dump_average_counters(std::string dump_path,+ uint32_t net_id,+ const std::list<std::shared_ptr<primitive_inst>>& exec_order) {+ if (dump_path.empty())+ return;++ std::filesystem::path file_name{dump_path};+ file_name += "_" + std::to_string(net_id) + ".csv";+ std::ofstream file(file_name);+ if (!file.is_open())+ return;++ const std::string header = "layerName;execStatus;layerType;execType;realTime (ms);cpuTime (ms);";+ file << header << "\n";++ auto to_ms = [](uint64_t value_us) {+ return static_cast<double>(std::chrono::microseconds(value_us).count()) / 1000.0;+ };++ uint64_t total_us = 0;++ for (const auto& inst : exec_order) {+ if (inst->is_constant())+ continue;++ // Aggregate inference-stage entries only, mirroring the CPU plugin which+ // reports just the executed-kernel time. Other GPU pipeline stages+ // (shape_inference, set_arguments, memory_allocation, ...) are host-side+ // overhead that has no CPU-plugin counterpart.+ const auto& perf_data = inst->get_profiling_data();+ const auto& perf_info = inst->get_profiling_info();+ uint64_t prim_total_us = 0;+ size_t prim_total_iters = 0;+ std::string impl_name;+ size_t max_iters_for_impl = 0;+ for (const auto& kv : perf_data) {+ const auto& key = perf_info.at(kv.first);+ if (key.stage != instrumentation::pipeline_stage::inference)+ continue;+ const auto cur_time = static_cast<uint64_t>(std::get<0>(kv.second));+ const auto cur_iters = std::get<1>(kv.second);+ prim_total_us += cur_time;+ prim_total_iters += cur_iters;+ // For dynamic shapes a primitive may have multiple inference entries+ // (one per shape). Pick the impl_name that ran the most iterations+ // as the representative execType.+ if (cur_iters > max_iters_for_impl) {+ max_iters_for_impl = cur_iters;+ impl_name = key.impl_name;+ }+ }++ const uint64_t avg_us = prim_total_iters > 0 ? prim_total_us / prim_total_iters : 0;+ const std::string status = avg_us > 0 ? "EXECUTED" : "NOT_RUN";+ const auto cpu_time = to_ms(avg_us);+ const auto real_time = cpu_time;++ file << inst->id() << ";" << status << ";" << inst->desc()->type_string() << ";"+ << impl_name << ";" << real_time << ";" << cpu_time << ";" << "\n";++ total_us += avg_us;+ }++ const auto total_ms = to_ms(total_us);+ file << "Total;;;;" << total_ms << ";" << total_ms << ";\n";+}+#elsevoid dump_perf_data_raw(std::string, bool per_iter_mode, const std::list<std::shared_ptr<primitive_inst>>&) {}+void dump_average_counters(std::string, uint32_t, const std::list<std::shared_ptr<primitive_inst>>&) {}#endif} // namespace@@ -214,6 +287,10 @@ network::~network() {GPU_DEBUG_IF(!dump_path.empty()) {dump_perf_data_raw(dump_path + "/perf_raw" + std::to_string(net_id) + ".csv", false, _exec_order);}+ std::string avg_counters_path = GPU_DEBUG_VALUE_OR(get_config().get_average_counters(), "");+ GPU_DEBUG_IF(!avg_counters_path.empty()) {+ dump_average_counters(avg_counters_path, net_id, _exec_order);+ }}network::ptr network::allocate_network(stream::ptr stream, program::ptr program, bool is_internal, bool is_primary_stream) {diff --git a/src/plugins/intel_gpu/src/graph/primitive_inst.cpp b/src/plugins/intel_gpu/src/graph/primitive_inst.cppindex 2d8dbc10a31..dd8a395c336 100644--- a/src/plugins/intel_gpu/src/graph/primitive_inst.cpp+++ b/src/plugins/intel_gpu/src/graph/primitive_inst.cpp@@ -2287,7 +2287,8 @@ void primitive_inst::execute() {set_out_event(_impl->execute(_impl_params->dep_events, *this));- GPU_DEBUG_IF(!get_config().get_dump_profiling_data_path().empty()) {+ GPU_DEBUG_IF(!get_config().get_dump_profiling_data_path().empty() ||+ !get_config().get_average_counters().empty()) {auto ev = _impl_params->out_event;get_network().get_stream().wait_for_events({ev});@@ -2623,7 +2624,8 @@ void primitive_inst::update_weights() {reorder_impl->set_arguments(*reorder_inst, args);add_dep_event(reorder_impl->execute({}, *reorder_inst));- GPU_DEBUG_IF(!get_config().get_dump_profiling_data_path().empty()) {+ GPU_DEBUG_IF(!get_config().get_dump_profiling_data_path().empty() ||+ !get_config().get_average_counters().empty()) {stream.wait_for_events(_impl_params->dep_events);}diff --git a/src/plugins/intel_gpu/src/runtime/execution_config.cpp b/src/plugins/intel_gpu/src/runtime/execution_config.cppindex 54d71cf484d..4f06218c0bb 100644--- a/src/plugins/intel_gpu/src/runtime/execution_config.cpp+++ b/src/plugins/intel_gpu/src/runtime/execution_config.cpp@@ -316,6 +316,14 @@ void ExecutionConfig::finalize_impl(const IRemoteContext* context) {// For now we apply config file only for build with debug caps, but it can be updated in the future to allow// reading release options for any build typeapply_config_options(context->get_device_name(), get_debug_config());++ // Auto-enable queue-level profiling when a per-primitive timing dump is requested.+ // Without this, OCL/L0 streams are created without CL_QUEUE_PROFILING_ENABLE and+ // event::get_profiling_info() yields no data, leaving average_counters with zero times.+ // Mirrors CPU plugin's Config::applyDebugCapsProperties().+ if (!get_dump_profiling_data_path().empty() || !get_average_counters().empty()) {+ m_enable_profiling = true;+ }#endif // ENABLE_DEBUG_CAPS}