Skip to content

Commit

Permalink
[GPU] dump verbose log to file (#26244)
Browse files Browse the repository at this point in the history
### Details:
- New debug config for dumping verbose log into file
  • Loading branch information
isanghao authored Aug 30, 2024
1 parent 6fef4a0 commit 446d2e2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <vector>
#include <set>
#include <string>
#include <iostream>

namespace ov {
namespace intel_gpu {
Expand Down Expand Up @@ -62,8 +63,9 @@ enum class LogLevel : int8_t {
#define GPU_DEBUG_LOG_RAW_INT(min_verbose_level) if (cldnn::debug_configuration::get_instance()->verbose >= min_verbose_level) \
((cldnn::debug_configuration::get_instance()->verbose_color == 0) ? GPU_DEBUG_LOG_PREFIX : GPU_DEBUG_LOG_COLOR_PREFIX)
#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))
#define GPU_DEBUG_LOG_PREFIX std::cout << cldnn::debug_configuration::prefix << GPU_FILENAME << ":" <<__LINE__ << ":" << __func__ << ": "
#define GPU_DEBUG_LOG_COLOR_PREFIX std::cout << DARK_GRAY << cldnn::debug_configuration::prefix << \
#define GPU_DEBUG_LOG_PREFIX \
*cldnn::debug_configuration::verbose_stream << cldnn::debug_configuration::prefix << GPU_FILENAME << ":" <<__LINE__ << ":" << __func__ << ": "
#define GPU_DEBUG_LOG_COLOR_PREFIX *cldnn::debug_configuration::verbose_stream << DARK_GRAY << cldnn::debug_configuration::prefix << \
BLUE << GPU_FILENAME << ":" << PURPLE << __LINE__ << ":" << CYAN << __func__ << ": " << RESET
#define DARK_GRAY "\033[1;30m"
#define BLUE "\033[1;34m"
Expand All @@ -77,7 +79,7 @@ enum class LogLevel : int8_t {
#define GPU_DEBUG_PROFILED_STAGE(stage)
#define GPU_DEBUG_PROFILED_STAGE_CACHE_HIT(val)
#define GPU_DEBUG_PROFILED_STAGE_MEMALLOC_INFO(info)
#define GPU_DEBUG_LOG_RAW(min_verbose_level) if (0) std::cout << cldnn::debug_configuration::prefix
#define GPU_DEBUG_LOG_RAW(min_verbose_level) if (0) *cldnn::debug_configuration::verbose_stream << cldnn::debug_configuration::prefix
#endif

// Macro below is inserted to avoid unused variable warning when GPU_DEBUG_CONFIG is OFF
Expand All @@ -100,6 +102,7 @@ class debug_configuration {
int help; // Print help messages
int verbose; // Verbose execution
int verbose_color; // Print verbose color
std::string verbose_file; // Verbose log to file
int list_layers; // Print list layers
int print_multi_kernel_perf; // Print execution time of each kernel in multi-kernel primitimive
int print_input_data_shapes; // Print the input data_shape for benchmark_app.
Expand Down Expand Up @@ -170,6 +173,8 @@ class debug_configuration {
int64_t start = 0;
int64_t end = 0;
} dump_prof_data_iter_params;

static std::ostream* verbose_stream;
};

} // namespace cldnn
13 changes: 13 additions & 0 deletions src/plugins/intel_gpu/src/runtime/debug_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
#include <regex>
#include <sstream>
#include <vector>
#include <fstream>

namespace cldnn {
const char *debug_configuration::prefix = "GPU_Debug: ";
std::ostream* debug_configuration::verbose_stream;

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

Expand Down Expand Up @@ -128,6 +130,7 @@ static void print_help_messages() {
message_list.emplace_back("OV_GPU_Help", "Print help messages");
message_list.emplace_back("OV_GPU_Verbose", "Verbose execution");
message_list.emplace_back("OV_GPU_VerboseColor", "Print verbose color");
message_list.emplace_back("OV_GPU_VerboseFile", "Filename to dump verbose log");
message_list.emplace_back("OV_GPU_ListLayers", "Print layers names");
message_list.emplace_back("OV_GPU_PrintMultiKernelPerf", "Print execution time of each kernel in multi-kernel primitimive");
message_list.emplace_back("OV_GPU_PrintInputDataShapes", "Print data_shapes of input layers for benchmark_app.");
Expand Down Expand Up @@ -214,6 +217,7 @@ debug_configuration::debug_configuration()
: help(0)
, verbose(0)
, verbose_color(0)
, verbose_file()
, list_layers(0)
, print_multi_kernel_perf(0)
, print_input_data_shapes(0)
Expand Down Expand Up @@ -255,6 +259,7 @@ debug_configuration::debug_configuration()
get_gpu_debug_env_var("Help", help);
get_common_debug_env_var("Verbose", verbose);
get_gpu_debug_env_var("VerboseColor", verbose_color);
get_gpu_debug_env_var("VerboseFile", verbose_file);
get_gpu_debug_env_var("ListLayers", list_layers);
get_gpu_debug_env_var("PrintMultiKernelPerf", print_multi_kernel_perf);
get_gpu_debug_env_var("PrintInputDataShapes", print_input_data_shapes);
Expand Down Expand Up @@ -316,6 +321,14 @@ debug_configuration::debug_configuration()
exit(0);
}

if (verbose_file.length() > 0) {
static std::ofstream fout;
fout.open(verbose_file);
verbose_stream = &fout;
} else {
verbose_stream = &std::cout;
}

if (dump_prof_data_iter_str.length() > 0) {
dump_prof_data_iter_str = " " + dump_prof_data_iter_str + " ";
std::istringstream iss(dump_prof_data_iter_str);
Expand Down

0 comments on commit 446d2e2

Please sign in to comment.