Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[GPU] Extract debug code from network::execute() (#26888)

Vladimir Paramuzov5c1e1fba4b70
diff --git a/src/plugins/intel_gpu/include/intel_gpu/graph/network.hpp b/src/plugins/intel_gpu/include/intel_gpu/graph/network.hpp
index 71623f32843..63adae28dda 100644
--- a/src/plugins/intel_gpu/include/intel_gpu/graph/network.hpp
+++ b/src/plugins/intel_gpu/include/intel_gpu/graph/network.hpp
@@ -4,17 +4,15 @@
#pragma once
-#include "openvino/runtime/threading/cpu_streams_executor.hpp"
+#include "openvino/runtime/threading/istreams_executor.hpp"
#include "intel_gpu/graph/topology.hpp"
#include "intel_gpu/graph/program.hpp"
#include "intel_gpu/graph/serialization/binary_buffer.hpp"
-#include "intel_gpu/runtime/compounds.hpp"
#include "intel_gpu/runtime/memory.hpp"
#include "intel_gpu/runtime/engine.hpp"
#include "intel_gpu/runtime/event.hpp"
#include "intel_gpu/runtime/stream.hpp"
-#include "intel_gpu/runtime/lru_cache.hpp"
#include "intel_gpu/runtime/shape_predictor.hpp"
#include "intel_gpu/plugin/variable_state.hpp"
@@ -211,7 +209,7 @@ public:
bool is_dynamic() const { return _is_dynamic; }
size_t get_weights_cache_capacity() const { return _weights_cache_capacity; }
- memory_pool& get_memory_pool() {
+ memory_pool& get_memory_pool() const {
return *_memory_pool;
}
@@ -284,7 +282,9 @@ private:
void dump_memory_pool(std::string dump_path, int64_t curr_iter);
#ifdef GPU_DEBUG_CONFIG
- int64_t iteration = 0;
+ mutable int64_t iteration = 0;
+ friend class NetworkDebugHelper;
+ friend class NodeDebugHelper;
#endif
};
} // namespace cldnn
diff --git a/src/plugins/intel_gpu/src/graph/debug_helper.cpp b/src/plugins/intel_gpu/src/graph/debug_helper.cpp
new file mode 100644
index 00000000000..7f7071e7046
--- /dev/null
+++ b/src/plugins/intel_gpu/src/graph/debug_helper.cpp
@@ -0,0 +1,526 @@
+// Copyright (C) 2024 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "debug_helper.hpp"
+#include "openvino/util/file_util.hpp"
+
+#ifdef GPU_DEBUG_CONFIG
+
+#include "to_string_utils.h"
+#include "loop_inst.h"
+#include "condition_inst.h"
+#include "program_dump_graph.h"
+
+#include <iomanip>
+#include <fstream>
+#include <sys/stat.h>
+
+namespace cldnn {
+
+namespace {
+
+float convert_element(int64_t i) { return static_cast<float>(i); }
+float convert_element(int32_t i) { return static_cast<float>(i); }
+
+float convert_element(float f) { return f; }
+
+float convert_element(ov::float16 h) { return static_cast<float>(h); }
+
+size_t get_x_pitch(const layout& layout) {
+ try {
+ auto tensor_x0 = tensor(batch(0), feature(0), spatial(0, 0, 0, 0));
+ auto tensor_x1 = tensor(batch(0), feature(0), spatial(1, 0, 0, 0));
+ auto x0 = layout.get_linear_offset(tensor_x0);
+ auto x1 = layout.get_linear_offset(tensor_x1);
+ return (x1 - x0);
+ } catch (...) {
+ // When spatial size of x=0, x_pitch is meaningless
+ return 0;
+ }
+}
+
+template <class T>
+void dump(memory::ptr mem, stream& stream, std::ofstream& file_stream, bool dump_raw) {
+ auto&& size = mem->get_layout().get_tensor();
+
+ GPU_DEBUG_GET_INSTANCE(debug_config);
+ auto batch_size = std::max(std::min(debug_config->dump_layers_limit_batch, size.batch[0]), 1);
+ tensor tmp_size(size);
+ tmp_size.batch[0] = batch_size;
+ if (tmp_size == size) {
+ file_stream << "shape: " << size.to_string() << " ";
+ file_stream << "(count: " << size.count()
+ << ", original format: " << cldnn::fmt_to_str(mem->get_layout().format) << ")"
+ << (dump_raw ? " raw data" : "") << std::endl;
+ } else {
+ file_stream << "shape: " << tmp_size.to_string() << " ";
+ file_stream << "(count: " << tmp_size.count()
+ << ", original format: " << cldnn::fmt_to_str(mem->get_layout().format)
+ << ", original shape: " << size.to_string() << ")"
+ << (dump_raw ? " raw data" : "") << std::endl;
+ }
+
+ if (size.count() == 0) {
+ file_stream << "Empty buffer" << std::endl;
+ return;
+ }
+
+ mem_lock<T, mem_lock_type::read> lock(mem, stream);
+ auto mem_ptr = lock.data();
+ auto x_pitch = get_x_pitch(mem->get_layout());
+ std::stringstream buffer;
+
+ if (!dump_raw) {
+ for (cldnn::tensor::value_type g = 0; g < size.group[0]; ++g) {
+ for (cldnn::tensor::value_type b = 0; b < batch_size; ++b) {
+ for (cldnn::tensor::value_type f = 0; f < size.feature[0]; ++f) {
+ for (cldnn::tensor::value_type w = 0; w < size.spatial[3]; ++w) {
+ for (cldnn::tensor::value_type z = 0; z < size.spatial[2]; ++z) {
+ for (cldnn::tensor::value_type y = 0; y < size.spatial[1]; ++y) {
+ cldnn::tensor t(cldnn::group(g), cldnn::batch(b), cldnn::feature(f), cldnn::spatial(0, y, z, w));
+ size_t input_it = mem->get_layout().get_linear_offset(t);
+
+ for (cldnn::tensor::value_type x = 0; x < size.spatial[0]; ++x, input_it += x_pitch) {
+ buffer << std::fixed << std::setprecision(6) << convert_element(mem_ptr[input_it]) << std::endl;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ } else {
+ for (size_t i = 0; i < lock.size(); ++i) {
+ buffer << std::fixed << std::setprecision(6) << convert_element(mem_ptr[i]) << std::endl;
+ }
+ }
+ file_stream << buffer.str();
+}
+
+void unpack(cldnn::data_types type, uint8_t input, int8_t &v0, int8_t &v1) {
+ if (type == cldnn::data_types::i4) {
+ char s_bit = (input & 0x08);
+ char mask = s_bit > 0 ? 0xF0 : 0x00;
+ v0 = (input & 0x0F) | mask;
+
+ input >>= 4;
+ s_bit = (input & 0x08);
+ mask = s_bit > 0 ? 0xF0 : 0x00;
+ v1 = (input & 0x0F) | mask;
+ } else if (type == cldnn::data_types::u4) {
+ v0 = input & 0x0F;
+ v1 = input >> 4;
+ } else {
+ OPENVINO_ASSERT(false, "not supported unpacking");
+ }
+}
+
+void dump_i4u4(cldnn::data_types type, memory::ptr mem, stream& stream, std::ofstream& file_stream, bool dump_raw) {
+ auto&& size = mem->get_layout().get_tensor();
+
+ GPU_DEBUG_GET_INSTANCE(debug_config);
+ auto batch_size = std::max(std::min(debug_config->dump_layers_limit_batch, size.batch[0]), 1);
+ tensor tmp_size(size);
+ tmp_size.batch[0] = batch_size;
+ if (tmp_size == size) {
+ file_stream << "shape: " << size.to_string() << " ";
+ file_stream << "(count: " << size.count()
+ << ", original format: " << cldnn::fmt_to_str(mem->get_layout().format) << ")"
+ << (dump_raw ? " raw data" : "") << std::endl;
+ } else {
+ file_stream << "shape: " << tmp_size.to_string() << " ";
+ file_stream << "(count: " << tmp_size.count()
+ << ", original format: " << cldnn::fmt_to_str(mem->get_layout().format)
+ << ", original shape: " << size.to_string() << ")"
+ << (dump_raw ? " raw data" : "") << std::endl;
+ }
+
+ if (size.count() == 0) {
+ file_stream << "Empty buffer" << std::endl;
+ return;
+ }
+
+ mem_lock<uint8_t, mem_lock_type::read> lock(mem, stream);
+ auto mem_ptr = lock.data();
+ std::stringstream buffer;
+
+ if (dump_raw) {
+ for (size_t i = 0; i < lock.size(); ++i) {
+ int8_t v0, v1;
+ unpack(type, mem_ptr[i], v0, v1);
+ buffer << std::fixed << std::setprecision(6) << static_cast<int>(v0) << std::endl;
+ buffer << std::fixed << std::setprecision(6) << static_cast<int>(v1) << std::endl;
+ }
+ } else {
+ std::cout << __func__ << " supports raw dump only" << std::endl;
+ }
+ file_stream << buffer.str();
+}
+
+void log_memory_to_file(memory::ptr mem, layout data_layout, stream& stream, std::string layerName, bool dump_raw) {
+ std::cout << "Dump " << (dump_raw ? "raw " : "") << layerName << std::endl;
+ GPU_DEBUG_GET_INSTANCE(debug_config);
+ std::string filename = debug_config->get_name_for_dump(layerName);
+ filename = debug_config->dump_layers_path + filename + ".txt";
+ std::ofstream file_stream(filename);
+ if (!mem) {
+ file_stream << "Empty" << std::endl;
+ return;
+ }
+
+ // Reinterpret buffer to represent actual data layout
+ auto actual_mem = mem->get_engine()->reinterpret_buffer(*mem, data_layout);
+
+ auto mem_dt = actual_mem->get_layout().data_type;
+ if (mem_dt == cldnn::data_types::f32)
+ dump<float>(actual_mem, stream, file_stream, dump_raw);
+ else if (mem_dt == cldnn::data_types::f16)
+ dump<ov::float16>(actual_mem, stream, file_stream, dump_raw);
+ else if (mem_dt == cldnn::data_types::i64)
+ dump<int64_t>(actual_mem, stream, file_stream, dump_raw);
+ else if (mem_dt == cldnn::data_types::i32)
+ dump<int32_t>(actual_mem, stream, file_stream, dump_raw);
+ else if (mem_dt == cldnn::data_types::i8)
+ dump<int8_t>(actual_mem, stream, file_stream, dump_raw);
+ else if (mem_dt == cldnn::data_types::u8)
+ dump<uint8_t>(actual_mem, stream, file_stream, dump_raw);
+ else if (mem_dt == cldnn::data_types::u8)
+ dump<uint8_t>(actual_mem, stream, file_stream, dump_raw);
+ else if (mem_dt == cldnn::data_types::i4 || mem_dt == cldnn::data_types::u4)
+ dump_i4u4(mem_dt, actual_mem, stream, file_stream, dump_raw);
+ else
+ std::cout << "Dump for this data type is not supported: " << dt_to_str(mem_dt) << std::endl;
+}
+
+} // namespace
+
+static std::string get_file_path_for_binary_dump(cldnn::layout layout, std::string name) {
+ std::string filename;
+ std::string data_type = ov::element::Type(layout.data_type).get_type_name();
+ std::string format = layout.format.to_string();
+ std::string tensor;
+ auto dims = layout.get_dims();
+ for (size_t r = 0 ; r < layout.get_rank() ; r++) {
+ tensor += ("_" + to_string(dims[r]));
+ }
+
+#ifdef GPU_DEBUG_CONFIG
+ GPU_DEBUG_GET_INSTANCE(debug_config);
+ std::string layer_name = debug_config->get_name_for_dump(name);
+ filename = debug_config->dump_layers_path + layer_name
+ + "__" + data_type + "_" + tensor + "__" + format + ".bin";
+#endif
+ return filename;
+}
+
+NodeDebugHelper::NodeDebugHelper(const primitive_inst& inst)
+ : m_inst(inst)
+ , m_stream(inst.get_network().get_stream())
+ , m_network(inst.get_network())
+ , m_program(inst.get_network().get_program().get())
+ , m_iter(m_network.iteration) {
+ // Load binary dump for input layers
+ if (!debug_config->load_layers_raw_dump.empty()) {
+ const std::string layer_name = m_inst.id();
+ auto files = debug_config->get_filenames_for_matched_layer_loading_binaries(layer_name);
+ if (!files.empty()) {
+ if (m_inst.is_input()) {
+ // Loading binary dumps for output tensors of input-layers : only one output exists or index(dstN) exists
+ auto dump_file = debug_config->get_matched_from_filelist(files, "_dst0__");
+ OPENVINO_ASSERT((files.size() == 1 || dump_file.length() != 0), "Unexpected binary dump for input layer");
+
+ OPENVINO_ASSERT(files.size() == m_inst.outputs_memory_count(), "Mis-match dump file count");
+
+ for (size_t i = 0; i < m_inst.outputs_memory_count(); i++) {
+ auto dump_file = files[0];
+ if (files.size() > 1 || m_inst.outputs_memory_count() != 1) {
+ std::string pattern = "_dst" + std::to_string(i) + "__";
+ dump_file = debug_config->get_matched_from_filelist(files, pattern);
+ }
+ OPENVINO_ASSERT((dump_file.length() > 0), "Could not find expected pattern '_dst[N]__' for binary dump");
+ GPU_DEBUG_COUT << " Load binary dump : " << dump_file << " for " << layer_name << std::endl;
+
+ std::vector<uint8_t> bin = ov::util::load_binary(dump_file);
+ OPENVINO_ASSERT(!bin.empty(), "Failure loading binary from OV_GPU_LoadDumpRawBinary : " + dump_file);
+
+ auto output_mem = m_inst.output_memory_ptr(i);
+ OPENVINO_ASSERT(output_mem->size() == bin.size(), "memory size mis-match for OV_GPU_LoadDumpRawBinary : " + layer_name
+ + "\n Expected size : " + to_string(output_mem->size()) + ", Binary : " + to_string(bin.size()));
+
+ output_mem->copy_from(m_stream, static_cast<void *>(&bin[0]), true);
+ }
+ } else {
+ auto check_dst = debug_config->get_matched_from_filelist(files, "_dst0__");
+ OPENVINO_ASSERT(check_dst.length() == 0, "Expected to load binaries for inputs of " + layer_name);
+
+ // Loading input tensors for any layer
+ auto dump_file = debug_config->get_matched_from_filelist(files, "_src0__");
+ OPENVINO_ASSERT(dump_file.length() != 0, "Could not find expected pattern '_src[N]__' for binary dump input : " + layer_name);
+
+ for (size_t i = 0; i < m_inst.dependencies().size(); i++) {
+ auto dump_file = files[0];
+ if (files.size() > 1 || m_inst.dependencies().size() != 1) {
+ std::string pattern = "_src" + std::to_string(i) + "__";
+ dump_file = debug_config->get_matched_from_filelist(files, pattern);
+ }
+ if (dump_file.length() == 0) {
+ GPU_DEBUG_COUT << " Skip loading for input(" << i << ") of " << layer_name << std::endl;
+ continue;
+ }
+ OPENVINO_ASSERT((dump_file.length() > 0), "Could not find expected pattern '_src[N]__' for binary dump input");
+ GPU_DEBUG_COUT << " Load binary dump : " << dump_file << " for input(" << i << ") of " << layer_name << std::endl;
+
+ std::vector<uint8_t> bin = ov::util::load_binary(dump_file);
+ OPENVINO_ASSERT(!bin.empty(), "Failure loading binary from OV_GPU_LoadDumpRawBinary : " + dump_file);
+
+ auto input_mem = m_inst.dep_memory_ptr(i);
+ if (input_mem->size() != bin.size()) {
+ std::cout << "WARNING: memory size mis-match for OV_GPU_LoadDumpRawBinary : " + layer_name
+ << " " << input_mem->size() << " / " << bin.size() << std::endl;
+ bin.resize(input_mem->size());
+ }
+
+ input_mem->copy_from(m_stream, static_cast<void *>(&bin[0]), true);
+ }
+ }
+ }
+ }
+
+ // Dump input buffers of 'inst'
+ if (debug_config->dump_layers_path.length() > 0) {
+ const std::string layer_name = inst.id();
+
+ if (debug_config->is_target_iteration(m_iter) &&
+ debug_config->dump_layers_dst_only == 0 && debug_config->is_layer_for_dumping(layer_name)) {
+ std::string debug_str_for_bin_load = " Command for loading : OV_GPU_LoadDumpRawBinary=\"" + layer_name + ":";
+ for (size_t i = 0; i < m_inst.dependencies().size(); i++) {
+ std::string name = get_file_prefix() + layer_name + "_src" + std::to_string(i);
+ auto input_mem = m_inst.dep_memory_ptr(i);
+ if (input_mem == nullptr) {
+ GPU_DEBUG_COUT << " input_mem_" << i << " is nullptr. Nothing to dump." << std::endl;
+ continue;
+ }
+
+ auto dep = m_inst.dependencies().at(i);
+ auto input_layout = dep.first->get_output_layout(dep.second);
+ GPU_DEBUG_IF(debug_config->dump_layers_binary) {
+ // Binary dump : raw
+ auto filename = get_file_path_for_binary_dump(input_layout, name);
+
+ mem_lock<char, mem_lock_type::read> lock(input_mem, m_stream);
+ ov::util::save_binary(filename, lock.data(), input_mem->size());
+ GPU_DEBUG_COUT << " Dump layer src : " << layer_name << " to " << filename << std::endl;
+ debug_str_for_bin_load += (filename + ",");
+ } else {
+ log_memory_to_file(input_mem,
+ input_layout,
+ m_stream,
+ name,
+ debug_config->dump_layers_raw);
+ }
+ }
+
+ if (debug_config->dump_layers_binary && !inst.is_input()) {
+ debug_str_for_bin_load[debug_str_for_bin_load.size()-1] = '\"';
+ GPU_DEBUG_COUT << debug_str_for_bin_load << std::endl;
+ }
+ }
+ }
+}
+
+
+NodeDebugHelper::~NodeDebugHelper() {
+ // Dump output buffers of 'inst'
+ if (debug_config->dump_layers_path.length() > 0) {
+ m_stream.finish();
+ const std::string layer_name = m_inst.id();
+
+ GPU_DEBUG_IF(debug_config->is_target_iteration(m_iter) &&
+ debug_config->is_layer_for_dumping(layer_name, m_inst.is_output(), m_inst.is_input())) {
+ std::string debug_str_for_bin_load = " Command for loading : OV_GPU_LoadDumpRawBinary=\""
+ + layer_name + ":";
+ for (size_t i = 0; i < m_inst.outputs_memory_count(); i++) {
+ std::string name = get_file_prefix() + "_dst" + std::to_string(i);
+ auto output_mem = m_inst.output_memory_ptr(i);
+ if (output_mem == nullptr) {
+ GPU_DEBUG_COUT << " output_mem is nullptr. Nothing to dump." << std::endl;
+ continue;
+ }
+
+ GPU_DEBUG_IF(debug_config->dump_layers_binary) {
+ // Binary dump : raw
+ auto output_layout = m_inst.get_output_layout(i);
+ auto filename = get_file_path_for_binary_dump(output_layout, name);
+
+ mem_lock<char, mem_lock_type::read> lock(output_mem, m_stream);
+ ov::util::save_binary(filename, lock.data(), output_mem->size());
+ GPU_DEBUG_COUT << " Dump layer dst : " << layer_name << " to " << filename << std::endl;
+ debug_str_for_bin_load += (filename + ",");
+ } else {
+ // Text dump
+ log_memory_to_file(output_mem, m_inst.get_output_layout(i), m_stream, name, debug_config->dump_layers_raw);
+ }
+ }
+
+ GPU_DEBUG_IF(debug_config->dump_layers_binary && m_inst.is_input()) {
+ debug_str_for_bin_load[debug_str_for_bin_load.size()-1] = '\"';
+ GPU_DEBUG_COUT << debug_str_for_bin_load << std::endl;;
+ }
+ }
+ }
+}
+
+NetworkDebugHelper::NetworkDebugHelper(const network& net)
+ : m_network(net)
+ , m_iter(net.iteration) {
+ auto net_id = m_network.get_id();
+ GPU_DEBUG_IF(debug_config->dump_memory_pool > 0) {
+ auto& iters = debug_config->dump_memory_pool_iters;
+ if (iters.empty() || iters.find(m_iter) != iters.end()) {
+ GPU_DEBUG_COUT << "============================================================================" << std::endl;
+ GPU_DEBUG_COUT << "Start network execution (net_id : " << net_id << ", iter :" << m_iter << ")" << std::endl;
+ if (m_iter == 0 && net_id > 0) {
+ dump_memory_pool(debug_config->dump_memory_pool_path, m_iter);
+ GPU_DEBUG_COUT << "============================================================================" << std::endl;
+ }
+ }
+ } else {
+ GPU_DEBUG_TRACE << "============================================================================" << std::endl;
+ GPU_DEBUG_TRACE << "Start network execution (net_id : " << net_id << ", iter :" << m_iter << ")" << std::endl;
+ }
+
+ if (debug_config->list_layers == 1) {
+ for (auto& inst : m_network._exec_order) {
+ GPU_DEBUG_COUT << inst->id() << std::endl;
+ if (inst->get_node().is_type<loop>()) {
+ auto& loop_node = inst->get_node().as<loop>();
+ for (auto& prim : loop_node.get_body_program()->get_processing_order()) {
+ GPU_DEBUG_COUT << "\t" << prim->id() << std::endl;
+ }
+ } else if (inst->get_node().is_type<condition>()) {
+ auto& cond_node = inst->get_node().as<condition>();
+ GPU_DEBUG_COUT << "* Branch_True" << std::endl;
+ for (auto& prim : cond_node.get_branch_true().inner_program->get_processing_order()) {
+ GPU_DEBUG_COUT << "\t" << prim->id() << std::endl;
+ }
+ GPU_DEBUG_COUT << "* Branch_False" << std::endl;
+ for (auto& prim : cond_node.get_branch_false().inner_program->get_processing_order()) {
+ GPU_DEBUG_COUT << "\t" << prim->id() << std::endl;
+ }
+ }
+ }
+
+ if (!m_network.is_internal())
+ exit(0);
+ }
+}
+
+NetworkDebugHelper::~NetworkDebugHelper() {
+ auto prog = m_network.get_program().get();
+ auto net_id = m_network.get_id();
+ // print '-data_shape' option for benchmark_app
+ if (debug_config->print_input_data_shapes == 1) {
+ std::stringstream data_shape_str;
+ auto add_string = [&data_shape_str](std::string str) {
+ data_shape_str << ((data_shape_str.rdbuf()->in_avail() == 0) ? " -data_shape " : ",") << str;
+ };
+
+ for (auto& inst : m_network._exec_order) {
+ auto name = inst->id();
+ auto pos = name.find(':');
+ auto type = name.substr(0, pos);
+ name.erase(0, pos + 1);
+ if (inst->is_input() && type == "parameter") {
+ add_string(name + inst->get_output_layout().get_partial_shape().to_string());
+ }
+ }
+
+ GPU_DEBUG_COUT << "[program:" << std::setw(2) << ((prog != nullptr) ? prog->get_id() : 0)
+ << "|network:" << std::setw(2) << net_id << "|iter:" << std::setw(4) << m_iter << "] benchmark_app cmd: "
+ << data_shape_str.str() << std::endl;
+ }
+
+ if (!debug_config->dump_graphs.empty() && debug_config->is_target_iteration(m_iter)) {
+ auto get_fixed_str = [](int value, int length = 2) -> std::string {
+ std::ostringstream ss;
+ ss << std::setw(length) << std::setfill('0') << std::to_string(value);
+ return ss.str();
+ };
+ std::string path = get_dir_path(m_network.get_config());
+ if (!path.empty()) {
+ std::ofstream ofs(path + "cldnn_program_exec_p" + get_fixed_str(prog->get_id()) + "_n" + get_fixed_str(net_id)
+ + "_" + get_fixed_str(m_iter, 5) + ".graph");
+ dump_graph_init(ofs, *prog, [this](const primitive_id& id) -> std::shared_ptr<const primitive_inst> {
+ return m_network.get_primitive(id);
+ });
+ }
+ }
+
+ if (debug_config->dump_memory_pool > 0) {
+ auto& iters = debug_config->dump_memory_pool_iters;
+ if (iters.empty() || iters.find(m_iter) != iters.end()) {
+ dump_memory_pool(debug_config->dump_memory_pool_path, m_iter);
+ GPU_DEBUG_COUT << "============================================================================" << std::endl;
+ }
+ }
+
+ m_network.iteration++;
+}
+
+void NetworkDebugHelper::dump_memory_pool(std::string dump_path, int64_t curr_iter) const {
+ m_network.get_memory_pool().dump(m_network.get_id(), curr_iter, dump_path);
+ auto get_constants_mem_size = [&](allocation_type type) -> size_t {
+ size_t mem_size = 0;
+ for (auto& prim : m_network._primitives) {
+ if (prim.second->get_node().is_constant()) {
+ for (size_t i = 0; i < prim.second->outputs_memory_count(); i++) {
+ if (prim.second->output_memory_ptr(i)->get_allocation_type() == type)
+ mem_size += prim.second->output_memory_ptr(i)->size();
+ }
+ }
+ }
+ return mem_size;
+ };
+ auto get_variables_mem_size = [&](allocation_type type) -> size_t {
+ size_t mem_size = 0;
+ for (auto& var : m_network.get_variables()) {
+ if (var.second->get_memory() && var.second->get_memory()->get_allocation_type() == type)
+ mem_size += var.second->get_actual_mem_size();
+ }
+ return mem_size;
+ };
+ auto get_mb_size = [&](int64_t size) -> std::string {
+ if (size == 0) return "0 MB";
+ return std::to_string(static_cast<float>(size) / (1024 * 1024)) + " MB";
+ };
+ int64_t usm_host_const_mem_size = get_constants_mem_size(allocation_type::usm_host);
+ int64_t usm_device_const_mem_size = get_constants_mem_size(allocation_type::usm_device);
+ int64_t usm_host_var_mem_size = get_variables_mem_size(allocation_type::usm_host);
+ int64_t usm_device_var_mem_size = get_variables_mem_size(allocation_type::usm_device);
+ int64_t host_mem_size = m_network.get_engine().get_used_device_memory(allocation_type::usm_host);
+ int64_t device_mem_size = m_network.get_engine().get_used_device_memory(allocation_type::usm_device);
+ int64_t usm_host_mem_pool_size = m_network.get_memory_pool().get_total_mem_pool_size(allocation_type::usm_host);
+ int64_t usm_host_etc_size = host_mem_size - usm_host_mem_pool_size
+ - usm_host_const_mem_size - usm_host_var_mem_size;
+ int64_t usm_device_mem_pool_size = m_network.get_memory_pool().get_total_mem_pool_size(allocation_type::usm_device);
+ int64_t usm_device_etc_size = device_mem_size - usm_device_mem_pool_size
+ - usm_device_const_mem_size - usm_device_var_mem_size;
+ GPU_DEBUG_COUT << "------------------------------------------------------------------------" << std::endl;
+ GPU_DEBUG_COUT << "Memory statistics for (net_id:" << m_network.get_id() << ", iter:" << curr_iter << ")" << std::endl;
+ GPU_DEBUG_COUT << " Total host mem size : " << get_mb_size(host_mem_size) << std::endl;
+ GPU_DEBUG_COUT << " * Memory pool : " << get_mb_size(usm_host_mem_pool_size) << std::endl;
+ GPU_DEBUG_COUT << " * Constant : " << get_mb_size(usm_host_const_mem_size) << std::endl;
+ GPU_DEBUG_COUT << " * Variable : " << get_mb_size(usm_host_var_mem_size) << std::endl;
+ GPU_DEBUG_COUT << " * ETC : " << get_mb_size(usm_host_etc_size) << std::endl;
+ GPU_DEBUG_COUT << " Total device mem size : " << get_mb_size(device_mem_size) << std::endl;
+ GPU_DEBUG_COUT << " * Memory pool : " << get_mb_size(usm_device_mem_pool_size) << std::endl;
+ GPU_DEBUG_COUT << " * Constant : " << get_mb_size(usm_device_const_mem_size) << std::endl;
+ GPU_DEBUG_COUT << " * Variable : " << get_mb_size(usm_device_var_mem_size) << std::endl;
+ GPU_DEBUG_COUT << " * ETC : " << get_mb_size(usm_device_etc_size) << std::endl;
+ GPU_DEBUG_COUT << "------------------------------------------------------------------------" << std::endl;
+}
+
+} // namespace cldnn
+
+#endif // GPU_DEBUG_CONFIG
diff --git a/src/plugins/intel_gpu/src/graph/debug_helper.hpp b/src/plugins/intel_gpu/src/graph/debug_helper.hpp
new file mode 100644
index 00000000000..c7c6bd006af
--- /dev/null
+++ b/src/plugins/intel_gpu/src/graph/debug_helper.hpp
@@ -0,0 +1,69 @@
+// Copyright (C) 2018-2024 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include "intel_gpu/graph/network.hpp"
+#include "intel_gpu/graph/program.hpp"
+#include "intel_gpu/runtime/stream.hpp"
+#include "intel_gpu/runtime/debug_configuration.hpp"
+#include "primitive_inst.h"
+
+namespace cldnn {
+
+#ifdef GPU_DEBUG_CONFIG
+
+class NodeDebugHelper {
+public:
+ NodeDebugHelper(const primitive_inst& inst);
+ ~NodeDebugHelper();
+
+private:
+ std::string get_iteration_prefix() {
+ if (m_iter < 0)
+ return std::string("");
+ return std::to_string(m_iter) + "_";
+ }
+
+ std::string get_file_prefix() {
+ auto prog_id = ((m_program != nullptr) ? m_program->get_id() : 0);
+ auto net_id = m_network.get_id();
+
+ return "program" + std::to_string(prog_id) + "_network" + std::to_string(net_id) + "_" + get_iteration_prefix() + m_inst.id();
+ }
+
+
+ const primitive_inst& m_inst;
+ stream& m_stream;
+ const network& m_network;
+ const program* m_program;
+ const size_t m_iter;
+
+ const debug_configuration* debug_config = cldnn ::debug_configuration ::get_instance();
+};
+
+class NetworkDebugHelper {
+public:
+ NetworkDebugHelper(const network& net);
+ ~NetworkDebugHelper();
+
+private:
+ void dump_memory_pool(std::string dump_path, int64_t curr_iter) const;
+ const network& m_network;
+ const size_t m_iter;
+
+ const debug_configuration* debug_config = cldnn ::debug_configuration ::get_instance();
+};
+
+#define NETWORK_DEBUG(net) NetworkDebugHelper __network_debug_helper(net)
+#define NODE_DEBUG(inst) NodeDebugHelper __node_debug_helper(inst)
+
+#else
+
+#define NETWORK_DEBUG(...)
+#define NODE_DEBUG(...)
+
+#endif // GPU_DEBUG_CONFIG
+
+} // namespace cldnn
diff --git a/src/plugins/intel_gpu/src/graph/include/program_dump_graph.h b/src/plugins/intel_gpu/src/graph/include/program_dump_graph.h
index 075422a4196..cf5111de6b2 100644
--- a/src/plugins/intel_gpu/src/graph/include/program_dump_graph.h
+++ b/src/plugins/intel_gpu/src/graph/include/program_dump_graph.h
@@ -14,6 +14,6 @@ std::string get_dir_path(const ExecutionConfig& config);
void dump_graph_optimized(std::ofstream&, const program&);
void dump_graph_processing_order(std::ofstream&, const program&);
void dump_graph_init(std::ofstream&, const program&,
- std::function<std::shared_ptr<primitive_inst>(const primitive_id&)> get_primitive_inst = nullptr);
+ std::function<std::shared_ptr<const primitive_inst>(const primitive_id&)> get_primitive_inst = nullptr);
void dump_graph_info(std::ofstream&, const program&);
} // namespace cldnn
diff --git a/src/plugins/intel_gpu/src/graph/network.cpp b/src/plugins/intel_gpu/src/graph/network.cpp
index 92d62782828..8f0e97dd51e 100644
--- a/src/plugins/intel_gpu/src/graph/network.cpp
+++ b/src/plugins/intel_gpu/src/graph/network.cpp
@@ -4,7 +4,6 @@
#include "intel_gpu/plugin/variable_state.hpp"
#include "intel_gpu/primitives/read_value.hpp"
-#include "openvino/util/file_util.hpp"
#include "intel_gpu/primitives/data.hpp"
#include "intel_gpu/primitives/mutable_data.hpp"
@@ -31,13 +30,10 @@
#include "deconvolution_inst.h"
#include "mutable_data_inst.h"
#include "condition_inst.h"
-#include "loop_inst.h"
-#include "assign_inst.h"
#include "read_value_inst.h"
#include "reshape_inst.h"
#include "kv_cache_inst.h"
#include "program_helpers.h"
-#include "to_string_utils.h"
#include "program_dump_graph.h"
#include <algorithm>
@@ -51,8 +47,8 @@
#include <functional>
#include <fstream>
+#include "debug_helper.hpp"
#ifdef GPU_DEBUG_CONFIG
-#include <iomanip>
#include <fstream>
#include <sys/stat.h>
#include <chrono>
@@ -60,7 +56,6 @@
#endif
namespace cldnn {
-
namespace {
#ifdef GPU_DEBUG_CONFIG
@@ -143,179 +138,6 @@ void dump_perf_data_raw(std::string dump_path, const std::list<std::shared_ptr<p
}
}
-float convert_element(int64_t i) { return static_cast<float>(i); }
-float convert_element(int32_t i) { return static_cast<float>(i); }
-
-float convert_element(float f) { return f; }
-
-float convert_element(ov::float16 h) { return static_cast<float>(h); }
-
-size_t get_x_pitch(const layout& layout) {
- try {
- auto tensor_x0 = tensor(batch(0), feature(0), spatial(0, 0, 0, 0));
- auto tensor_x1 = tensor(batch(0), feature(0), spatial(1, 0, 0, 0));
- auto x0 = layout.get_linear_offset(tensor_x0);
- auto x1 = layout.get_linear_offset(tensor_x1);
- return (x1 - x0);
- } catch (...) {
- // When spatial size of x=0, x_pitch is meaningless
- return 0;
- }
-}
-
-template <class T>
-void dump(memory::ptr mem, stream& stream, std::ofstream& file_stream, bool dump_raw) {
- auto&& size = mem->get_layout().get_tensor();
-
- GPU_DEBUG_GET_INSTANCE(debug_config);
- auto batch_size = std::max(std::min(debug_config->dump_layers_limit_batch, size.batch[0]), 1);
- tensor tmp_size(size);
- tmp_size.batch[0] = batch_size;
- if (tmp_size == size) {
- file_stream << "shape: " << size.to_string() << " ";
- file_stream << "(count: " << size.count()
- << ", original format: " << cldnn::fmt_to_str(mem->get_layout().format) << ")"
- << (dump_raw ? " raw data" : "") << std::endl;
- } else {
- file_stream << "shape: " << tmp_size.to_string() << " ";
- file_stream << "(count: " << tmp_size.count()
- << ", original format: " << cldnn::fmt_to_str(mem->get_layout().format)
- << ", original shape: " << size.to_string() << ")"
- << (dump_raw ? " raw data" : "") << std::endl;
- }
-
- if (size.count() == 0) {
- file_stream << "Empty buffer" << std::endl;
- return;
- }
-
- mem_lock<T, mem_lock_type::read> lock(mem, stream);
- auto mem_ptr = lock.data();
- auto x_pitch = get_x_pitch(mem->get_layout());
- std::stringstream buffer;
-
- if (!dump_raw) {
- for (cldnn::tensor::value_type g = 0; g < size.group[0]; ++g) {
- for (cldnn::tensor::value_type b = 0; b < batch_size; ++b) {
- for (cldnn::tensor::value_type f = 0; f < size.feature[0]; ++f) {
- for (cldnn::tensor::value_type w = 0; w < size.spatial[3]; ++w) {
- for (cldnn::tensor::value_type z = 0; z < size.spatial[2]; ++z) {
- for (cldnn::tensor::value_type y = 0; y < size.spatial[1]; ++y) {
- cldnn::tensor t(cldnn::group(g), cldnn::batch(b), cldnn::feature(f), cldnn::spatial(0, y, z, w));
- size_t input_it = mem->get_layout().get_linear_offset(t);
-
- for (cldnn::tensor::value_type x = 0; x < size.spatial[0]; ++x, input_it += x_pitch) {
- buffer << std::fixed << std::setprecision(6) << convert_element(mem_ptr[input_it]) << std::endl;
- }
- }
- }
- }
- }
- }
- }
- } else {
- for (size_t i = 0; i < lock.size(); ++i) {
- buffer << std::fixed << std::setprecision(6) << convert_element(mem_ptr[i]) << std::endl;
- }
- }
- file_stream << buffer.str();
-}
-
-void unpack(cldnn::data_types type, uint8_t input, int8_t &v0, int8_t &v1) {
- if (type == cldnn::data_types::i4) {
- char s_bit = (input & 0x08);
- char mask = s_bit > 0 ? 0xF0 : 0x00;
- v0 = (input & 0x0F) | mask;
-
- input >>= 4;
- s_bit = (input & 0x08);
- mask = s_bit > 0 ? 0xF0 : 0x00;
- v1 = (input & 0x0F) | mask;
- } else if (type == cldnn::data_types::u4) {
- v0 = input & 0x0F;
- v1 = input >> 4;
- } else {
- OPENVINO_ASSERT(false, "not supported unpacking");
- }
-}
-
-void dump_i4u4(cldnn::data_types type, memory::ptr mem, stream& stream, std::ofstream& file_stream, bool dump_raw) {
- auto&& size = mem->get_layout().get_tensor();
-
- GPU_DEBUG_GET_INSTANCE(debug_config);
- auto batch_size = std::max(std::min(debug_config->dump_layers_limit_batch, size.batch[0]), 1);
- tensor tmp_size(size);
- tmp_size.batch[0] = batch_size;
- if (tmp_size == size) {
- file_stream << "shape: " << size.to_string() << " ";
- file_stream << "(count: " << size.count()
- << ", original format: " << cldnn::fmt_to_str(mem->get_layout().format) << ")"
- << (dump_raw ? " raw data" : "") << std::endl;
- } else {
- file_stream << "shape: " << tmp_size.to_string() << " ";
- file_stream << "(count: " << tmp_size.count()
- << ", original format: " << cldnn::fmt_to_str(mem->get_layout().format)
- << ", original shape: " << size.to_string() << ")"
- << (dump_raw ? " raw data" : "") << std::endl;
- }
-
- if (size.count() == 0) {
- file_stream << "Empty buffer" << std::endl;
- return;
- }
-
- mem_lock<uint8_t, mem_lock_type::read> lock(mem, stream);
- auto mem_ptr = lock.data();
- std::stringstream buffer;
-
- if (dump_raw) {
- for (size_t i = 0; i < lock.size(); ++i) {
- int8_t v0, v1;
- unpack(type, mem_ptr[i], v0, v1);
- buffer << std::fixed << std::setprecision(6) << static_cast<int>(v0) << std::endl;
- buffer << std::fixed << std::setprecision(6) << static_cast<int>(v1) << std::endl;
- }
- } else {
- std::cout << __func__ << " supports raw dump only" << std::endl;
- }
- file_stream << buffer.str();
-}
-
-void log_memory_to_file(memory::ptr mem, layout data_layout, stream& stream, std::string layerName, bool dump_raw) {
- std::cout << "Dump " << (dump_raw ? "raw " : "") << layerName << std::endl;
- GPU_DEBUG_GET_INSTANCE(debug_config);
- std::string filename = debug_config->get_name_for_dump(layerName);
- filename = debug_config->dump_layers_path + filename + ".txt";
- std::ofstream file_stream(filename);
- if (!mem) {
- file_stream << "Empty" << std::endl;
- return;
- }
-
- // Reinterpret buffer to represent actual data layout
- auto actual_mem = mem->get_engine()->reinterpret_buffer(*mem, data_layout);
-
- auto mem_dt = actual_mem->get_layout().data_type;
- if (mem_dt == cldnn::data_types::f32)
- dump<float>(actual_mem, stream, file_stream, dump_raw);
- else if (mem_dt == cldnn::data_types::f16)
- dump<ov::float16>(actual_mem, stream, file_stream, dump_raw);
- else if (mem_dt == cldnn::data_types::i64)
- dump<int64_t>(actual_mem, stream, file_stream, dump_raw);
- else if (mem_dt == cldnn::data_types::i32)
- dump<int32_t>(actual_mem, stream, file_stream, dump_raw);
- else if (mem_dt == cldnn::data_types::i8)
- dump<int8_t>(actual_mem, stream, file_stream, dump_raw);
- else if (mem_dt == cldnn::data_types::u8)
- dump<uint8_t>(actual_mem, stream, file_stream, dump_raw);
- else if (mem_dt == cldnn::data_types::u8)
- dump<uint8_t>(actual_mem, stream, file_stream, dump_raw);
- else if (mem_dt == cldnn::data_types::i4 || mem_dt == cldnn::data_types::u4)
- dump_i4u4(mem_dt, actual_mem, stream, file_stream, dump_raw);
- else
- std::cout << "Dump for this data type is not supported: " << dt_to_str(mem_dt) << std::endl;
-}
-
void wait_for_the_turn() {
GPU_DEBUG_GET_INSTANCE(debug_config);
bool need_to_wait;
@@ -336,7 +158,6 @@ void wait_for_the_turn() {
#else
void dump_perf_data_raw(std::string, const std::list<std::shared_ptr<primitive_inst>>&) {}
-void log_memory_to_file(memory::ptr, layout, stream&, std::string, bool dump_raw) {}
void wait_for_the_turn() {}
#endif
} // namespace
@@ -346,25 +167,6 @@ static uint32_t get_unique_net_id() {
return ++id_gen;
}
-static std::string get_file_path_for_binary_dump(cldnn::layout layout, std::string name) {
- std::string filename;
- std::string data_type = ov::element::Type(layout.data_type).get_type_name();
- std::string format = layout.format.to_string();
- std::string tensor;
- auto dims = layout.get_dims();
- for (size_t r = 0 ; r < layout.get_rank() ; r++) {
- tensor += ("_" + to_string(dims[r]));
- }
-
-#ifdef GPU_DEBUG_CONFIG
- GPU_DEBUG_GET_INSTANCE(debug_config);
- std::string layer_name = debug_config->get_name_for_dump(name);
- filename = debug_config->dump_layers_path + layer_name
- + "__" + data_type + "_" + tensor + "__" + format + ".bin";
-#endif
- return filename;
-}
-
/*
Network will always have net_id = 0 when it will be cldnn internal micronetwork (created i.e by propagate_constants
opt pass).
@@ -939,28 +741,10 @@ std::map<primitive_id, network_output> network::execute(const std::vector<event:
void network::execute_impl(const std::vector<event::ptr>& events) {
OV_ITT_SCOPED_TASK(ov::intel_gpu::itt::domains::intel_gpu_plugin, "NetworkImpl::Execute");
- int64_t curr_iter = -1;
- GPU_DEBUG_GET_INSTANCE(debug_config);
-#ifdef GPU_DEBUG_CONFIG
- curr_iter = iteration;
-#endif
+ NETWORK_DEBUG(*this);
// Wait for previous execution completion
reset_execution(false);
- GPU_DEBUG_IF(debug_config->dump_memory_pool > 0) {
- auto& iters = debug_config->dump_memory_pool_iters;
- if (iters.empty() || iters.find(curr_iter) != iters.end()) {
- GPU_DEBUG_COUT << "============================================================================" << std::endl;
- GPU_DEBUG_COUT << "Start network execution (net_id : " << get_id() << ", iter :" << curr_iter << ")" << std::endl;
- if (curr_iter == 0 && get_id() > 0) {
- dump_memory_pool(debug_config->dump_memory_pool_path, curr_iter);
- GPU_DEBUG_COUT << "============================================================================" << std::endl;
- }
- }
- } else {
- GPU_DEBUG_TRACE << "============================================================================" << std::endl;
- GPU_DEBUG_TRACE << "Start network execution (net_id : " << get_id() << ", iter :" << curr_iter << ")" << std::endl;
- }
std::vector<memory::ptr> in_out_mem;
auto is_surface_lock_check_needed = [&](const shared_mem_type& shared_mem_type) {
@@ -996,33 +780,6 @@ void network::execute_impl(const std::vector<event::ptr>& events) {
auto surf_lock = surfaces_lock::create(get_engine().type(), in_out_mem, get_stream());
set_arguments();
- GPU_DEBUG_IF(debug_config->list_layers == 1) {
- for (auto& inst : _exec_order) {
- GPU_DEBUG_COUT << inst->id() << std::endl;
- if (inst->get_node().is_type<loop>()) {
- auto& loop_node = inst->get_node().as<loop>();
- for (auto& prim : loop_node.get_body_program()->get_processing_order()) {
- GPU_DEBUG_COUT << "\t" << prim->id() << std::endl;
- }
- } else if (inst->get_node().is_type<condition>()) {
- auto& cond_node = inst->get_node().as<condition>();
- GPU_DEBUG_COUT << "* Branch_True" << std::endl;
- for (auto& prim : cond_node.get_branch_true().inner_program->get_processing_order()) {
- GPU_DEBUG_COUT << "\t" << prim->id() << std::endl;
- }
- GPU_DEBUG_COUT << "* Branch_False" << std::endl;
- for (auto& prim : cond_node.get_branch_false().inner_program->get_processing_order()) {
- GPU_DEBUG_COUT << "\t" << prim->id() << std::endl;
- }
- }
- }
- if (!is_internal()) exit(0);
- }
- auto get_iteration_prefix = [](int64_t iter) {
- if (iter < 0)
- return std::string("");
- return std::to_string(iter) + "_";
- };
// This extra flush command is needed for dynamic models in both cases of out_of_order / in_order operating mode
// since it reduces `bubbles` number in pipeline and GPU's idle time by timely flushing new kernels to device.
@@ -1033,233 +790,43 @@ void network::execute_impl(const std::vector<event::ptr>& events) {
size_t executed_prims = 0;
for (auto& inst : _exec_order) {
- // Load binary dump for input layers
- GPU_DEBUG_IF(!debug_config->load_layers_raw_dump.empty()) {
- const std::string layer_name = inst->id();
- auto files = debug_config->get_filenames_for_matched_layer_loading_binaries(layer_name);
- if (!files.empty()) {
- if (inst->is_input()) {
- // Loading binary dumps for output tensors of input-layers : only one output exists or index(dstN) exists
- auto dump_file = debug_config->get_matched_from_filelist(files, "_dst0__");
- OPENVINO_ASSERT((files.size() == 1 || dump_file.length() != 0), "Unexpected binary dump for input layer");
-
- OPENVINO_ASSERT(files.size() == get_primitive(inst->id())->outputs_memory_count(), "Mis-match dump file count");
-
- for (size_t i = 0; i < get_primitive(inst->id())->outputs_memory_count(); i++) {
- auto dump_file = files[0];
- if (files.size() > 1 || get_primitive(inst->id())->outputs_memory_count() != 1) {
- std::string pattern = "_dst" + std::to_string(i) + "__";
- dump_file = debug_config->get_matched_from_filelist(files, pattern);
- }
- OPENVINO_ASSERT((dump_file.length() > 0), "Could not find expected pattern '_dst[N]__' for binary dump");
- GPU_DEBUG_COUT << " Load binary dump : " << dump_file << " for " << layer_name << std::endl;
-
- std::vector<uint8_t> bin = ov::util::load_binary(dump_file);
- OPENVINO_ASSERT(!bin.empty(), "Failure loading binary from OV_GPU_LoadDumpRawBinary : " + dump_file);
-
- auto output_mem = get_primitive(layer_name)->output_memory_ptr(i);
- OPENVINO_ASSERT(output_mem->size() == bin.size(), "memory size mis-match for OV_GPU_LoadDumpRawBinary : " + layer_name
- + "\n Expected size : " + to_string(output_mem->size()) + ", Binary : " + to_string(bin.size()));
-
- output_mem->copy_from(get_stream(), static_cast<void *>(&bin[0]), true);
- }
- } else {
- auto check_dst = debug_config->get_matched_from_filelist(files, "_dst0__");
- OPENVINO_ASSERT(check_dst.length() == 0, "Expected to load binaries for inputs of " + layer_name);
-
- // Loading input tensors for any layer
- auto dump_file = debug_config->get_matched_from_filelist(files, "_src0__");
- OPENVINO_ASSERT(dump_file.length() != 0, "Could not find expected pattern '_src[N]__' for binary dump input : " + layer_name);
-
- for (size_t i = 0; i < get_primitive(inst->id())->dependencies().size(); i++) {
- auto dump_file = files[0];
- if (files.size() > 1 || get_primitive(inst->id())->dependencies().size() != 1) {
- std::string pattern = "_src" + std::to_string(i) + "__";
- dump_file = debug_config->get_matched_from_filelist(files, pattern);
- }
- if (dump_file.length() == 0) {
- GPU_DEBUG_COUT << " Skip loading for input(" << i << ") of " << layer_name << std::endl;
- continue;
- }
- OPENVINO_ASSERT((dump_file.length() > 0), "Could not find expected pattern '_src[N]__' for binary dump input");
- GPU_DEBUG_COUT << " Load binary dump : " << dump_file << " for input(" << i << ") of " << layer_name << std::endl;
-
- std::vector<uint8_t> bin = ov::util::load_binary(dump_file);
- OPENVINO_ASSERT(!bin.empty(), "Failure loading binary from OV_GPU_LoadDumpRawBinary : " + dump_file);
-
- auto input_mem = get_primitive(inst->id())->dep_memory_ptr(i);
- if (input_mem->size() != bin.size()) {
- std::cout << "WARNING: memory size mis-match for OV_GPU_LoadDumpRawBinary : " + layer_name
- << " " << input_mem->size() << " / " << bin.size() << std::endl;
- bin.resize(input_mem->size());
- }
-
- input_mem->copy_from(get_stream(), static_cast<void *>(&bin[0]), true);
- }
- }
- }
- }
-
- // Dump input buffers of 'inst'
- GPU_DEBUG_IF(debug_config->dump_layers_path.length() > 0) {
- const std::string layer_name = inst->id();
-
- GPU_DEBUG_IF(debug_config->is_target_iteration(curr_iter) &&
- debug_config->dump_layers_dst_only == 0 && debug_config->is_layer_for_dumping(layer_name)) {
- std::string debug_str_for_bin_load = " Command for loading : OV_GPU_LoadDumpRawBinary=\"" + layer_name + ":";
- for (size_t i = 0; i < get_primitive(inst->id())->dependencies().size(); i++) {
- std::string name = "program" + std::to_string((get_program() != nullptr) ? get_program()->get_id() : 0) +
- "_network" + std::to_string(get_id()) +
- "_" + get_iteration_prefix(curr_iter) +
- layer_name + "_src" + std::to_string(i);
- auto input_mem = get_primitive(inst->id())->dep_memory_ptr(i);
- if (input_mem == nullptr) {
- GPU_DEBUG_COUT << " input_mem_" << i << " is nullptr. Nothing to dump." << std::endl;
- continue;
- }
-
- auto dep = inst->dependencies().at(i);
- auto input_layout = dep.first->get_output_layout(dep.second);
- GPU_DEBUG_IF(debug_config->dump_layers_binary) {
- // Binary dump : raw
- auto filename = get_file_path_for_binary_dump(input_layout, name);
-
- mem_lock<char, mem_lock_type::read> lock(input_mem, get_stream());
- ov::util::save_binary(filename, lock.data(), input_mem->size());
- GPU_DEBUG_COUT << " Dump layer src : " << layer_name << " to " << filename << std::endl;
- debug_str_for_bin_load += (filename + ",");
- } else {
- log_memory_to_file(input_mem,
- input_layout,
- get_stream(),
- name,
- debug_config->dump_layers_raw);
- }
- }
-
- GPU_DEBUG_IF(debug_config->dump_layers_binary && !inst->is_input()) {
- debug_str_for_bin_load[debug_str_for_bin_load.size()-1] = '\"';
- GPU_DEBUG_COUT << debug_str_for_bin_load << std::endl;;
- }
- }
- }
+ NODE_DEBUG(*inst);
execute_primitive(inst, events);
executed_prims++;
if (needs_flushing && executed_prims % flush_frequency == 0)
get_stream().flush();
-
- // Dump output buffers of 'inst'
- GPU_DEBUG_IF(debug_config->dump_layers_path.length() > 0) {
- get_stream().finish();
- const std::string layer_name = inst->id();
- auto prog_id = ((get_program() != nullptr) ? get_program()->get_id() : 0);
- auto net_id = get_id();
- GPU_DEBUG_IF(debug_config->is_target_iteration(curr_iter) &&
- debug_config->is_layer_for_dumping(layer_name, inst->is_output(), inst->is_input())) {
- std::string debug_str_for_bin_load = " Command for loading : OV_GPU_LoadDumpRawBinary=\""
- + layer_name + ":";
- for (size_t i = 0; i < get_primitive(layer_name)->outputs_memory_count(); i++) {
- std::string name = "program" + std::to_string(prog_id) +
- "_network" + std::to_string(net_id) +
- "_" + get_iteration_prefix(curr_iter) +
- layer_name + "_dst" + std::to_string(i);
- auto output_mem = get_primitive(layer_name)->output_memory_ptr(i);
- if (output_mem == nullptr) {
- GPU_DEBUG_COUT << " output_mem is nullptr. Nothing to dump." << std::endl;
- continue;
- }
-
- GPU_DEBUG_IF(debug_config->dump_layers_binary) {
- // Binary dump : raw
- auto output_layout = inst->get_output_layout(i);
- auto filename = get_file_path_for_binary_dump(output_layout, name);
-
- mem_lock<char, mem_lock_type::read> lock(output_mem, get_stream());
- ov::util::save_binary(filename, lock.data(), output_mem->size());
- GPU_DEBUG_COUT << " Dump layer dst : " << layer_name << " to " << filename << std::endl;
- debug_str_for_bin_load += (filename + ",");
- } else {
- // Text dump
- log_memory_to_file(output_mem, inst->get_output_layout(i), get_stream(), name, debug_config->dump_layers_raw);
- }
- }
-
- GPU_DEBUG_IF(debug_config->dump_layers_binary && inst->is_input()) {
- debug_str_for_bin_load[debug_str_for_bin_load.size()-1] = '\"';
- GPU_DEBUG_COUT << debug_str_for_bin_load << std::endl;;
- }
- }
- }
- }
-
- // print '-data_shape' option for benchmark_app
- GPU_DEBUG_IF(debug_config->print_input_data_shapes == 1) {
- std::stringstream data_shape_str;
- auto add_string = [&data_shape_str](std::string str) {
- data_shape_str << ((data_shape_str.rdbuf()->in_avail() == 0) ? " -data_shape " : ",") << str;
- };
-
- for (auto& inst : _exec_order) {
- auto name = inst->id();
- auto pos = name.find(':');
- auto type = name.substr(0, pos);
- name.erase(0, pos + 1);
- if (inst->is_input() && type == "parameter") {
- add_string(name + inst->get_output_layout().get_partial_shape().to_string());
- }
- }
-
- GPU_DEBUG_COUT << "[program:" << std::setw(2) << ((get_program() != nullptr) ? get_program()->get_id() : 0)
- << "|network:" << std::setw(2) << get_id() << "|iter:" << std::setw(4) << curr_iter << "] benchmark_app cmd: "
- << data_shape_str.str() << std::endl;
- }
-
- GPU_DEBUG_IF(!debug_config->dump_graphs.empty() && debug_config->is_target_iteration(curr_iter)) {
- auto get_fixed_str = [](int value, int length = 2) -> std::string {
- std::ostringstream ss;
- ss << std::setw(length) << std::setfill('0') << std::to_string(value);
- return ss.str();
- };
- std::string path = get_dir_path(get_config());
- if (!path.empty()) {
- std::ofstream ofs(path + "cldnn_program_exec_p" + get_fixed_str(get_program()->get_id()) + "_n" + get_fixed_str(get_id())
- + "_" + get_fixed_str(curr_iter, 5) + ".graph");
- dump_graph_init(ofs, *get_program(), [&](const primitive_id& id) -> std::shared_ptr<primitive_inst> {
- return get_primitive(id);
- });
- }
}
// Store events only in case of OOO queue or enabled Profiling
auto store_events = is_out_of_order_queue || _enable_profiling;
if (store_events) {
if (_program != nullptr) {
- for (auto& inst : _program->get_processing_order()) {
- // Special handling for mutable data. The event should be the same as the user or dependency with highest
- // processing_num as the mutable_data can be updated when is both user or dependency.
- if (inst->is_type<mutable_data>()) {
- decltype(_program->get_processing_order().get_processing_number(inst)) proc_num = 0;
- for (auto& user : inst->get_users()) {
- auto user_proc_num = _program->get_processing_order().get_processing_number(user);
- if (user_proc_num > proc_num) {
- _events[inst->id()] = _events[user->id()];
- proc_num = user_proc_num;
+ for (auto& inst : _program->get_processing_order()) {
+ // Special handling for mutable data. The event should be the same as the user or dependency with highest
+ // processing_num as the mutable_data can be updated when is both user or dependency.
+ if (inst->is_type<mutable_data>()) {
+ decltype(_program->get_processing_order().get_processing_number(inst)) proc_num = 0;
+ for (auto& user : inst->get_users()) {
+ auto user_proc_num = _program->get_processing_order().get_processing_number(user);
+ if (user_proc_num > proc_num) {
+ _events[inst->id()] = _events[user->id()];
+ proc_num = user_proc_num;
+ }
}
- }
- if (!inst->get_dependencies().empty()) {
- for (auto& dep : inst->get_dependencies()) {
- auto dep_proc_num = _program->get_processing_order().get_processing_number(dep.first);
- if (dep_proc_num > proc_num) {
- _events[inst->id()] = _events[dep.first->id()];
- proc_num = dep_proc_num;
+ if (!inst->get_dependencies().empty()) {
+ for (auto& dep : inst->get_dependencies()) {
+ auto dep_proc_num = _program->get_processing_order().get_processing_number(dep.first);
+ if (dep_proc_num > proc_num) {
+ _events[inst->id()] = _events[dep.first->id()];
+ proc_num = dep_proc_num;
+ }
}
}
}
}
}
- }
for (auto& dout : _data_outputs) { // data primitives are not executed so if they are marked as output we need to add
// them valid events manually
@@ -1278,73 +845,6 @@ void network::execute_impl(const std::vector<event::ptr>& events) {
// Deallocate events from the previos iteration
_old_events.clear();
-
- GPU_DEBUG_IF(debug_config->dump_memory_pool > 0) {
- auto& iters = debug_config->dump_memory_pool_iters;
- if (iters.empty() || iters.find(curr_iter) != iters.end()) {
- dump_memory_pool(debug_config->dump_memory_pool_path, curr_iter);
- GPU_DEBUG_COUT << "============================================================================" << std::endl;
- }
- }
-
-#ifdef GPU_DEBUG_CONFIG
- iteration++;
-#endif
-}
-
-void network::dump_memory_pool(std::string dump_path, int64_t curr_iter) {
-#ifdef GPU_DEBUG_CONFIG
- get_memory_pool().dump(get_id(), curr_iter, dump_path);
- auto get_constants_mem_size = [&](allocation_type type) -> size_t {
- size_t mem_size = 0;
- for (auto& prim : _primitives) {
- if (prim.second->get_node().is_constant()) {
- for (size_t i = 0; i < prim.second->outputs_memory_count(); i++) {
- if (prim.second->output_memory_ptr(i)->get_allocation_type() == type)
- mem_size += prim.second->output_memory_ptr(i)->size();
- }
- }
- }
- return mem_size;
- };
- auto get_variables_mem_size = [&](allocation_type type) -> size_t {
- size_t mem_size = 0;
- for (auto& var : get_variables()) {
- if (var.second->get_memory() && var.second->get_memory()->get_allocation_type() == type)
- mem_size += var.second->get_actual_mem_size();
- }
- return mem_size;
- };
- auto get_mb_size = [&](int64_t size) -> std::string {
- if (size == 0) return "0 MB";
- return std::to_string(static_cast<float>(size) / (1024 * 1024)) + " MB";
- };
- int64_t usm_host_const_mem_size = get_constants_mem_size(allocation_type::usm_host);
- int64_t usm_device_const_mem_size = get_constants_mem_size(allocation_type::usm_device);
- int64_t usm_host_var_mem_size = get_variables_mem_size(allocation_type::usm_host);
- int64_t usm_device_var_mem_size = get_variables_mem_size(allocation_type::usm_device);
- int64_t host_mem_size = get_engine().get_used_device_memory(allocation_type::usm_host);
- int64_t device_mem_size = get_engine().get_used_device_memory(allocation_type::usm_device);
- int64_t usm_host_mem_pool_size = get_memory_pool().get_total_mem_pool_size(allocation_type::usm_host);
- int64_t usm_host_etc_size = host_mem_size - usm_host_mem_pool_size
- - usm_host_const_mem_size - usm_host_var_mem_size;
- int64_t usm_device_mem_pool_size = get_memory_pool().get_total_mem_pool_size(allocation_type::usm_device);
- int64_t usm_device_etc_size = device_mem_size - usm_device_mem_pool_size
- - usm_device_const_mem_size - usm_device_var_mem_size;
- GPU_DEBUG_COUT << "------------------------------------------------------------------------" << std::endl;
- GPU_DEBUG_COUT << "Memory statistics for (net_id:" << get_id() << ", iter:" << curr_iter << ")" << std::endl;
- GPU_DEBUG_COUT << " Total host mem size : " << get_mb_size(host_mem_size) << std::endl;
- GPU_DEBUG_COUT << " * Memory pool : " << get_mb_size(usm_host_mem_pool_size) << std::endl;
- GPU_DEBUG_COUT << " * Constant : " << get_mb_size(usm_host_const_mem_size) << std::endl;
- GPU_DEBUG_COUT << " * Variable : " << get_mb_size(usm_host_var_mem_size) << std::endl;
- GPU_DEBUG_COUT << " * ETC : " << get_mb_size(usm_host_etc_size) << std::endl;
- GPU_DEBUG_COUT << " Total device mem size : " << get_mb_size(device_mem_size) << std::endl;
- GPU_DEBUG_COUT << " * Memory pool : " << get_mb_size(usm_device_mem_pool_size) << std::endl;
- GPU_DEBUG_COUT << " * Constant : " << get_mb_size(usm_device_const_mem_size) << std::endl;
- GPU_DEBUG_COUT << " * Variable : " << get_mb_size(usm_device_var_mem_size) << std::endl;
- GPU_DEBUG_COUT << " * ETC : " << get_mb_size(usm_device_etc_size) << std::endl;
- GPU_DEBUG_COUT << "------------------------------------------------------------------------" << std::endl;
-#endif
}
std::vector<primitive_id> network::get_input_ids() const {
diff --git a/src/plugins/intel_gpu/src/graph/program_dump_graph.cpp b/src/plugins/intel_gpu/src/graph/program_dump_graph.cpp
index bff45cd81f9..4a2f43b28d9 100644
--- a/src/plugins/intel_gpu/src/graph/program_dump_graph.cpp
+++ b/src/plugins/intel_gpu/src/graph/program_dump_graph.cpp
@@ -170,7 +170,7 @@ std::string get_dir_path(const ExecutionConfig& config) {
void dump_graph_init(std::ofstream& graph,
const program& program,
- std::function<std::shared_ptr<primitive_inst>(const primitive_id&)> get_primitive_inst) {
+ std::function<std::shared_ptr<const primitive_inst>(const primitive_id&)> get_primitive_inst) {
const std::string invalid_layout_msg = "(invalid layout)";
const auto dump_mem_info = [&invalid_layout_msg, &get_primitive_inst](const program_node* ptr) {