Skip to content

Commit 446d2e2

Browse files
authored
[GPU] dump verbose log to file (#26244)
### Details: - New debug config for dumping verbose log into file
1 parent 6fef4a0 commit 446d2e2

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/plugins/intel_gpu/include/intel_gpu/runtime/debug_configuration.hpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <vector>
99
#include <set>
1010
#include <string>
11+
#include <iostream>
1112

1213
namespace ov {
1314
namespace intel_gpu {
@@ -62,8 +63,9 @@ enum class LogLevel : int8_t {
6263
#define GPU_DEBUG_LOG_RAW_INT(min_verbose_level) if (cldnn::debug_configuration::get_instance()->verbose >= min_verbose_level) \
6364
((cldnn::debug_configuration::get_instance()->verbose_color == 0) ? GPU_DEBUG_LOG_PREFIX : GPU_DEBUG_LOG_COLOR_PREFIX)
6465
#define GPU_DEBUG_LOG_RAW(min_verbose_level) GPU_DEBUG_LOG_RAW_INT(static_cast<std::underlying_type<ov::intel_gpu::LogLevel>::type>(min_verbose_level))
65-
#define GPU_DEBUG_LOG_PREFIX std::cout << cldnn::debug_configuration::prefix << GPU_FILENAME << ":" <<__LINE__ << ":" << __func__ << ": "
66-
#define GPU_DEBUG_LOG_COLOR_PREFIX std::cout << DARK_GRAY << cldnn::debug_configuration::prefix << \
66+
#define GPU_DEBUG_LOG_PREFIX \
67+
*cldnn::debug_configuration::verbose_stream << cldnn::debug_configuration::prefix << GPU_FILENAME << ":" <<__LINE__ << ":" << __func__ << ": "
68+
#define GPU_DEBUG_LOG_COLOR_PREFIX *cldnn::debug_configuration::verbose_stream << DARK_GRAY << cldnn::debug_configuration::prefix << \
6769
BLUE << GPU_FILENAME << ":" << PURPLE << __LINE__ << ":" << CYAN << __func__ << ": " << RESET
6870
#define DARK_GRAY "\033[1;30m"
6971
#define BLUE "\033[1;34m"
@@ -77,7 +79,7 @@ enum class LogLevel : int8_t {
7779
#define GPU_DEBUG_PROFILED_STAGE(stage)
7880
#define GPU_DEBUG_PROFILED_STAGE_CACHE_HIT(val)
7981
#define GPU_DEBUG_PROFILED_STAGE_MEMALLOC_INFO(info)
80-
#define GPU_DEBUG_LOG_RAW(min_verbose_level) if (0) std::cout << cldnn::debug_configuration::prefix
82+
#define GPU_DEBUG_LOG_RAW(min_verbose_level) if (0) *cldnn::debug_configuration::verbose_stream << cldnn::debug_configuration::prefix
8183
#endif
8284

8385
// Macro below is inserted to avoid unused variable warning when GPU_DEBUG_CONFIG is OFF
@@ -100,6 +102,7 @@ class debug_configuration {
100102
int help; // Print help messages
101103
int verbose; // Verbose execution
102104
int verbose_color; // Print verbose color
105+
std::string verbose_file; // Verbose log to file
103106
int list_layers; // Print list layers
104107
int print_multi_kernel_perf; // Print execution time of each kernel in multi-kernel primitimive
105108
int print_input_data_shapes; // Print the input data_shape for benchmark_app.
@@ -170,6 +173,8 @@ class debug_configuration {
170173
int64_t start = 0;
171174
int64_t end = 0;
172175
} dump_prof_data_iter_params;
176+
177+
static std::ostream* verbose_stream;
173178
};
174179

175180
} // namespace cldnn

src/plugins/intel_gpu/src/runtime/debug_configuration.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
#include <regex>
1111
#include <sstream>
1212
#include <vector>
13+
#include <fstream>
1314

1415
namespace cldnn {
1516
const char *debug_configuration::prefix = "GPU_Debug: ";
17+
std::ostream* debug_configuration::verbose_stream;
1618

1719
// Default policy is that dump_configuration will override other configuration from IE.
1820

@@ -128,6 +130,7 @@ static void print_help_messages() {
128130
message_list.emplace_back("OV_GPU_Help", "Print help messages");
129131
message_list.emplace_back("OV_GPU_Verbose", "Verbose execution");
130132
message_list.emplace_back("OV_GPU_VerboseColor", "Print verbose color");
133+
message_list.emplace_back("OV_GPU_VerboseFile", "Filename to dump verbose log");
131134
message_list.emplace_back("OV_GPU_ListLayers", "Print layers names");
132135
message_list.emplace_back("OV_GPU_PrintMultiKernelPerf", "Print execution time of each kernel in multi-kernel primitimive");
133136
message_list.emplace_back("OV_GPU_PrintInputDataShapes", "Print data_shapes of input layers for benchmark_app.");
@@ -214,6 +217,7 @@ debug_configuration::debug_configuration()
214217
: help(0)
215218
, verbose(0)
216219
, verbose_color(0)
220+
, verbose_file()
217221
, list_layers(0)
218222
, print_multi_kernel_perf(0)
219223
, print_input_data_shapes(0)
@@ -255,6 +259,7 @@ debug_configuration::debug_configuration()
255259
get_gpu_debug_env_var("Help", help);
256260
get_common_debug_env_var("Verbose", verbose);
257261
get_gpu_debug_env_var("VerboseColor", verbose_color);
262+
get_gpu_debug_env_var("VerboseFile", verbose_file);
258263
get_gpu_debug_env_var("ListLayers", list_layers);
259264
get_gpu_debug_env_var("PrintMultiKernelPerf", print_multi_kernel_perf);
260265
get_gpu_debug_env_var("PrintInputDataShapes", print_input_data_shapes);
@@ -316,6 +321,14 @@ debug_configuration::debug_configuration()
316321
exit(0);
317322
}
318323

324+
if (verbose_file.length() > 0) {
325+
static std::ofstream fout;
326+
fout.open(verbose_file);
327+
verbose_stream = &fout;
328+
} else {
329+
verbose_stream = &std::cout;
330+
}
331+
319332
if (dump_prof_data_iter_str.length() > 0) {
320333
dump_prof_data_iter_str = " " + dump_prof_data_iter_str + " ";
321334
std::istringstream iss(dump_prof_data_iter_str);

0 commit comments

Comments
 (0)