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][debug] New dump feature for sin/cos (#39113)
Mingyu Kim42daf28db1e8
diff --git a/src/plugins/intel_gpu/docs/gpu_debug_utils.md b/src/plugins/intel_gpu/docs/gpu_debug_utils.mdindex ce4f6560ffe..14579f5a16b 100644--- a/src/plugins/intel_gpu/docs/gpu_debug_utils.md+++ b/src/plugins/intel_gpu/docs/gpu_debug_utils.md@@ -77,6 +77,7 @@ These options enable inspection of intermediate tensor data and are primarily us| Env variable name | When/how to use ||---|---|| `OV_GPU_DUMP_TENSORS_PATH` | Saves intermediate input/output tensors for each primitive to the specified directory. This is the main switch for tensor dump mode. See the tensor dump section below for details. |+| `OV_GPU_DUMP_SINCOS_PATH` | Saves raw binary input/output of every Sin/Cos activation to the specified directory (must end with `/`). Files are named `SINCOS__<seq>__p<program>_n<network>_i<iteration>__<sin\|cos>__<src0\|dst0>__<dtype>__<AxBxC>__<layer>.bin`. Synchronizes the stream on every Sin/Cos node. Useful for troubleshooting position-embedding accuracy. || `OV_GPU_DUMP_TENSORS` | Tensor types to dump. Supported values: `all`, `in`, `out`. || `OV_GPU_DUMP_ITERATIONS` | Space-separated list of iterations when the other dump options should be enabled. || `OV_GPU_DUMP_LAYER_NAMES` | Enables dumping only for the specified layer names. |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 302ce178e35..a769221b8f7 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@@ -190,6 +190,7 @@ static constexpr Property<bool, ov::PropertyMutability::RW> dump_profiling_data_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> dump_sincos_path{"GPU_DUMP_SINCOS_PATH"};static constexpr Property<std::string, ov::PropertyMutability::RW> dry_run_path{"GPU_DRY_RUN_PATH"};static constexpr Property<DumpTensors, ov::PropertyMutability::RW> dump_tensors{"GPU_DUMP_TENSORS"};static constexpr Property<std::vector<std::string>, ov::PropertyMutability::RW> dump_layer_names{"GPU_DUMP_LAYER_NAMES"};diff --git a/src/plugins/intel_gpu/include/intel_gpu/runtime/options.inl b/src/plugins/intel_gpu/include/intel_gpu/runtime/options.inlindex 0e2e8357925..6cef7bec518 100644--- a/src/plugins/intel_gpu/include/intel_gpu/runtime/options.inl+++ b/src/plugins/intel_gpu/include/intel_gpu/runtime/options.inl@@ -117,6 +117,7 @@ OV_CONFIG_DEBUG_OPTION(ov::intel_gpu, dump_layer_names, std::vector<std::string>OV_CONFIG_DEBUG_OPTION(ov::intel_gpu, dump_memory_pool_path, "", "Save csv file with memory pool info to specified folder")OV_CONFIG_DEBUG_OPTION(ov::intel_gpu, dump_memory_pool, 0, "Enable verbose output for memory pool. 0 - Disabled, 1 - Dump summary, 2 - Dump detailed entries")OV_CONFIG_DEBUG_OPTION(ov::intel_gpu, dump_iterations, std::set<int64_t>{}, "Space separated list of iterations where other dump options should be enabled")+OV_CONFIG_DEBUG_OPTION(ov::intel_gpu, dump_sincos_path, "", "Save input/output of every Sin/Cos activation execution to specified folder as raw binary (SINCOS__<seq>__...bin).")OV_CONFIG_DEBUG_OPTION(ov::intel_gpu, dump_src_after_exec, false, "Enable source data dump after layer execution. Useful for capturing updated states in stateful models.")OV_CONFIG_DEBUG_OPTION(ov::intel_gpu, host_time_profiling, 0, "Measure and print host time spent from the beginning of the infer until all host work is done and plugin is ready to block thread on the final clFinish() call")OV_CONFIG_DEBUG_OPTION(ov::intel_gpu, disable_async_compilation, false, "Disable feature that allows to asynchronously prepare static-shaped implementations for the primitives with shape-agnostic kernels selected during compilation")diff --git a/src/plugins/intel_gpu/src/graph/debug_helper.cpp b/src/plugins/intel_gpu/src/graph/debug_helper.cppindex fd9fd9b19a7..bb90bc82fdf 100644--- a/src/plugins/intel_gpu/src/graph/debug_helper.cpp+++ b/src/plugins/intel_gpu/src/graph/debug_helper.cpp@@ -14,6 +14,7 @@# include <sys/stat.h>+# include <atomic># include <fstream># include <iomanip>@@ -336,6 +337,55 @@ std::string get_file_path_for_binary_dump(cldnn::layout layout, const std::strinreturn filename;}+void dump_sincos_tensor(memory::ptr mem, const layout& data_layout, stream& stream, const std::string& head, const std::string& tail) {+ if (mem == nullptr) {+ GPU_DEBUG_COUT << " Sin/Cos dump: memory is nullptr for " << head << std::endl;+ return;+ }+ if (data_layout.data_padding) {+ GPU_DEBUG_COUT << " Sin/Cos dump: padded layout is not supported for " << head << std::endl;+ return;+ }+ std::string shape;+ for (const auto dim : data_layout.get_shape()) {+ shape += (shape.empty() ? "" : "x") + std::to_string(dim);+ }+ const std::string data_type = ov::element::Type(data_layout.data_type).get_type_name();+ const std::string filename = head + data_type + "__" + shape + tail;+ const size_t bytes = std::min(mem->size(), data_layout.bytes_count());+ mem_lock<char, mem_lock_type::read> lock(mem, stream);+ std::ofstream file(filename, std::ios::binary);+ if (!file) {+ GPU_DEBUG_COUT << "Sin/Cos dump: failed to open " << filename << std::endl;+ return;+ }+ file.write(lock.data(), static_cast<std::streamsize>(bytes));+}++// Saves input/output of each Sin/Cos activation execution as+// SINCOS__<seq>__p<program>_n<network>_i<iteration>__<sin|cos>__<src0|dst0>__<dtype>__<AxBxC>__<layer>.bin+void dump_sincos(const primitive_inst& inst, stream& stream, const std::string& dump_path, uint32_t prog_id, uint32_t net_id, int64_t iter) {+ if (inst.desc()->type != activation::type_id()) {+ return;+ }+ const auto func = std::static_pointer_cast<const activation>(inst.desc())->activation_function;+ if (func != activation_func::sin && func != activation_func::cos) {+ return;+ }++ static std::atomic<uint64_t> sincos_seq{0};+ std::ostringstream seq;+ seq << std::setw(8) << std::setfill('0') << sincos_seq++;+ const std::string prefix = dump_path + "SINCOS__" + seq.str() + "__p" + std::to_string(prog_id) + "_n" + std::to_string(net_id) + "_i" + std::to_string(iter) + "__" ++ (func == activation_func::sin ? "sin" : "cos") + "__";+ const std::string suffix = "__" + get_name_for_dump(inst.id()) + ".bin";++ stream.finish(); // Wait for stream completion before reading Sin/Cos buffers+ auto dep = inst.dependencies().at(0);+ dump_sincos_tensor(inst.dep_memory_ptr(0), dep.first->get_output_layout(dep.second), stream, prefix + "src0__", suffix);+ dump_sincos_tensor(inst.output_memory_ptr(0), inst.get_output_layout(0), stream, prefix + "dst0__", suffix);+}+bool is_target_iteration(int64_t iteration, const std::set<int64_t> dump_iteration) {if (iteration < 0) {return true;@@ -545,6 +595,11 @@ NodeDebugHelper::NodeDebugHelper(const primitive_inst& inst)NodeDebugHelper::~NodeDebugHelper() {const auto& config = m_network.get_config();+ // Dump before output validation, which may throw on detection+ if (!config.get_dump_sincos_path().empty()) {+ dump_sincos(m_inst, m_stream, config.get_dump_sincos_path(), (m_program != nullptr) ? m_program->get_id() : 0, m_network.get_id(), m_iter);+ }+if (config.get_validate_output_buffer() && !m_network.is_internal()) {const bool throw_for_error = config.get_validate_output_buffer() >= 2;m_stream.finish(); // Wait for stream completion before checking output buffers