-
Notifications
You must be signed in to change notification settings - Fork 25
Add loglevels to aiebu #178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main-ge
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,73 @@ | ||||||
| // SPDX-License-Identifier: MIT | ||||||
| // Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved. | ||||||
|
|
||||||
| #ifndef AIEBU_COMMON_LOGGER_H | ||||||
| #define AIEBU_COMMON_LOGGER_H | ||||||
|
|
||||||
| #include <iostream> | ||||||
| #include <sstream> | ||||||
|
|
||||||
| namespace aiebu { | ||||||
|
|
||||||
| // Log Levels | ||||||
| enum class log_level { | ||||||
| error = 0, // Always shown | ||||||
| warn = 1, // Warnings | ||||||
| info = 2, // Informational messages (shown with verbose) | ||||||
| debug = 3 // Debug messages (shown with verbose) | ||||||
| }; | ||||||
|
|
||||||
| // Global log level (default: errors and warnings) | ||||||
| inline log_level g_log_level = log_level::warn; | ||||||
|
|
||||||
| // Set log level | ||||||
| inline void set_log_level(log_level level) { | ||||||
| g_log_level = level; | ||||||
| } | ||||||
|
|
||||||
| // Get log level | ||||||
| inline log_level get_log_level() { | ||||||
| return g_log_level; | ||||||
| } | ||||||
|
|
||||||
| // Enable verbose mode (shows info and debug messages) | ||||||
| inline void enable_verbose_logging() { | ||||||
| g_log_level = log_level::debug; | ||||||
| } | ||||||
|
|
||||||
| // Disable verbose mode (back to default: errors and warnings) | ||||||
| inline void disable_verbose_logging() { | ||||||
| g_log_level = log_level::warn; | ||||||
| } | ||||||
|
|
||||||
| } // namespace aiebu | ||||||
|
|
||||||
| // Logging macros | ||||||
| #define LOG_ERROR(msg) \ | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: function-like macro 'LOG_ERROR' used; consider a 'constexpr' template function [cppcoreguidelines-macro-usage] #define LOG_ERROR(msg) \
^ |
||||||
| do { \ | ||||||
| std::cerr << "[ERROR] " << msg << std::endl; \ | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: macro argument should be enclosed in parentheses [bugprone-macro-parentheses]
Suggested change
|
||||||
| } while (0) | ||||||
|
|
||||||
| #define LOG_WARN(msg) \ | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: function-like macro 'LOG_WARN' used; consider a 'constexpr' template function [cppcoreguidelines-macro-usage] #define LOG_WARN(msg) \
^ |
||||||
| do { \ | ||||||
| if (aiebu::g_log_level >= aiebu::log_level::warn) { \ | ||||||
| std::cout << "[WARN] " << msg << std::endl; \ | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: macro argument should be enclosed in parentheses [bugprone-macro-parentheses]
Suggested change
|
||||||
| } \ | ||||||
| } while (0) | ||||||
|
|
||||||
| #define LOG_INFO(msg) \ | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: function-like macro 'LOG_INFO' used; consider a 'constexpr' template function [cppcoreguidelines-macro-usage] #define LOG_INFO(msg) \
^ |
||||||
| do { \ | ||||||
| if (aiebu::g_log_level >= aiebu::log_level::info) { \ | ||||||
| std::cout << msg << std::endl; \ | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: macro argument should be enclosed in parentheses [bugprone-macro-parentheses]
Suggested change
|
||||||
| } \ | ||||||
| } while (0) | ||||||
|
|
||||||
| #define LOG_DEBUG(msg) \ | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: function-like macro 'LOG_DEBUG' used; consider a 'constexpr' template function [cppcoreguidelines-macro-usage] #define LOG_DEBUG(msg) \
^ |
||||||
| do { \ | ||||||
| if (aiebu::g_log_level >= aiebu::log_level::debug) { \ | ||||||
| std::cout << "[DEBUG] " << msg << std::endl; \ | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: macro argument should be enclosed in parentheses [bugprone-macro-parentheses]
Suggested change
|
||||||
| } \ | ||||||
| } while (0) | ||||||
|
|
||||||
| #endif // AIEBU_COMMON_LOGGER_H | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| // Copyright (C) 2024-2025, Advanced Micro Devices, Inc. All rights reserved. | ||
|
|
||
| #include "elfwriter.h" | ||
| #include "logger.h" | ||
|
|
||
| namespace aiebu { | ||
|
|
||
|
|
@@ -118,7 +119,7 @@ elf_writer:: | |
| finalize() | ||
| { | ||
| add_note(NT_XRT_UID, ".note.xrt.UID", m_uid.calculate()); | ||
| std::cout << "UID:" << m_uid.str() << "\n"; | ||
| LOG_INFO("UID:" << m_uid.str()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: avoid do-while loops [cppcoreguidelines-avoid-do-while] LOG_INFO("UID:" << m_uid.str());
^Additional contextsrc/cpp/common/logger.h:58: expanded from macro 'LOG_INFO' do { \
^ |
||
| std::stringstream stream; | ||
| stream << std::noskipws; | ||
| //m_elfio.save( "hello_32" ); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |||||
| #include "utils.h" | ||||||
| #include "file_utils.h" | ||||||
| #include "preprocessor_input.h" | ||||||
| #include "asm/asm_parser.h" | ||||||
| #include <boost/format.hpp> | ||||||
| #include <boost/property_tree/json_parser.hpp> | ||||||
|
|
||||||
|
|
@@ -105,6 +106,8 @@ class aie2_blob_preprocessor_input : public preprocessor_input | |||||
| { | ||||||
| if (lib == legacydpuxclbin) | ||||||
| arg_offset = 1; | ||||||
| else if (lib == "verbose") | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how you are passing this flag from aiebu-asm, that code is missing |
||||||
| enable_verbose_logging(); | ||||||
| else | ||||||
| std::cout << "Invalid flag: " << lib << ", ignored !!!" << std::endl; | ||||||
|
||||||
| std::cout << "Invalid flag: " << lib << ", ignored !!!" << std::endl; | |
| LOG_WARN("Invalid flag: %s, ignored !!!", lib.c_str()); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ class aie2ps_preprocessor: public preprocessor | |
| { | ||
| const std::string disable_dump_map = "disabledump"; | ||
| const std::string full_dump_map = "fulldump"; | ||
| const std::string verbose_asm = "verbose"; | ||
| std::shared_ptr<std::map<std::string, std::shared_ptr<isa_op>>> m_isa; | ||
| public: | ||
| aie2ps_preprocessor() {} | ||
|
|
@@ -45,25 +46,32 @@ class aie2ps_preprocessor: public preprocessor | |
| { | ||
| //auto keys = tinput->get_keys(); | ||
| const std::string prefix = "opt_level_"; | ||
| std::shared_ptr<asm_parser> parser(new asm_parser(tinput->get_ctrlcode_data(), tinput->get_include_paths())); | ||
| parser->parse_lines(); | ||
| auto collist = parser->get_col_list(); | ||
| isa i; | ||
| uint32_t optimize = 0; | ||
| m_isa = i.get_isamap(); | ||
| auto toutput = std::make_shared<aie2ps_preprocessed_output>(parser->get_partition_info()); | ||
|
|
||
| // Process flags before parsing to set global verbose flag | ||
| auto flags = tinput->get_flags(); | ||
| uint32_t optimize = 0; | ||
| asm_dump_flag debug_flag = asm_dump_flag::text; | ||
| for (const auto& flag: flags) | ||
| { | ||
| if (flag == disable_dump_map) | ||
| toutput->set_debug(asm_dump_flag::disable); | ||
| debug_flag = asm_dump_flag::disable; | ||
| else if (flag == full_dump_map) | ||
| toutput->set_debug(asm_dump_flag::full); | ||
| debug_flag = asm_dump_flag::full; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we dont need verbose. |
||
| else if (flag == verbose_asm) | ||
| enable_verbose_logging(); | ||
| else if (flag.find(prefix) == 0) | ||
| optimize = std::stoi(flag.substr(prefix.size())); | ||
| else | ||
| std::cout << "Invalid flag: " << flag << ", ignored !!!" << std::endl; | ||
| } | ||
|
Comment on lines
51
to
66
|
||
|
|
||
| std::shared_ptr<asm_parser> parser(new asm_parser(tinput->get_ctrlcode_data(), tinput->get_include_paths())); | ||
| parser->parse_lines(); | ||
| auto collist = parser->get_col_list(); | ||
| isa i; | ||
| m_isa = i.get_isamap(); | ||
| auto toutput = std::make_shared<aie2ps_preprocessed_output>(parser->get_partition_info()); | ||
| toutput->set_debug(debug_flag); | ||
| auto& controlpkts = tinput->get_controlpkt(); | ||
| auto& ctrlpkt_id_map = tinput->get_ctrlpkt_id_map(); | ||
| toutput->set_optmization(optimize); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -219,7 +219,7 @@ operate(std::shared_ptr<asm_parser> parserptr, const smatch& sm) | |
| else if (is_annotation_section(args[0])) | ||
| m_parserptr->set_annotation_state(); | ||
| else | ||
| std::cout << "section directive with unknown section found:" << args[0] << std::endl; | ||
| LOG_WARN("section directive with unknown section found:" << args[0]); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: avoid do-while loops [cppcoreguidelines-avoid-do-while] LOG_WARN("section directive with unknown section found:" << args[0]);
^Additional contextsrc/cpp/common/logger.h:51: expanded from macro 'LOG_WARN' do { \
^ |
||
| } | ||
|
|
||
| void | ||
|
|
@@ -229,18 +229,17 @@ operate(std::shared_ptr<asm_parser> parserptr, const smatch& sm) | |
| m_parserptr = parserptr; | ||
| static const regex pattern(R"(\.partition\s+(\d+)(column|core:(\d+)mem))"); | ||
| smatch match; | ||
| // LOG_INFO("PARTITION:" << sm[0].str()); | ||
| std::cout << "PARTITION:" << sm[0].str() << std::endl; | ||
| LOG_INFO("PARTITION:" << sm[0].str()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: avoid do-while loops [cppcoreguidelines-avoid-do-while] LOG_INFO("PARTITION:" << sm[0].str());
^Additional contextsrc/cpp/common/logger.h:58: expanded from macro 'LOG_INFO' do { \
^ |
||
| std::string line = sm[0].str(); | ||
| if (regex_match(line, match, pattern)) { | ||
| if (match[2] == "column") { | ||
| std::cout << "Column count: " << match[1] << std::endl; | ||
| LOG_INFO("Column count: " << match[1]); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: avoid do-while loops [cppcoreguidelines-avoid-do-while] LOG_INFO("Column count: " << match[1]);
^Additional contextsrc/cpp/common/logger.h:58: expanded from macro 'LOG_INFO' do { \
^ |
||
| m_parserptr->set_numcolumn(to_uinteger<uint32_t>(match[1])); | ||
| } else { | ||
| m_parserptr->set_numcore(to_uinteger<uint32_t>(match[1])); | ||
| m_parserptr->set_nummem(to_uinteger<uint32_t>(match[3])); | ||
| std::cout << "Core count: " << match[1] << std::endl; | ||
| std::cout << "Memory size: " << match[3] << std::endl; | ||
| LOG_INFO("Core count: " << match[1]); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: avoid do-while loops [cppcoreguidelines-avoid-do-while] LOG_INFO("Core count: " << match[1]);
^Additional contextsrc/cpp/common/logger.h:58: expanded from macro 'LOG_INFO' do { \
^ |
||
| LOG_INFO("Memory size: " << match[3]); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: avoid do-while loops [cppcoreguidelines-avoid-do-while] LOG_INFO("Memory size: " << match[3]);
^Additional contextsrc/cpp/common/logger.h:58: expanded from macro 'LOG_INFO' do { \
^ |
||
| } | ||
| } else | ||
| throw error(error::error_code::invalid_asm, "Invalid format!! " + line + "\n"); | ||
|
|
@@ -254,7 +253,7 @@ read_include_file(std::string filename) | |
| if (!file.is_open()) { | ||
| return false; | ||
| } | ||
| // std::cout << "Reading file:" << filename << std::endl; | ||
| LOG_INFO("Reading file:" << filename); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: avoid do-while loops [cppcoreguidelines-avoid-do-while] LOG_INFO("Reading file:" << filename);
^Additional contextsrc/cpp/common/logger.h:58: expanded from macro 'LOG_INFO' do { \
^ |
||
| std::string line; | ||
| m_parserptr->set_data_state(false); | ||
|
|
||
|
|
@@ -369,7 +368,7 @@ read_pad_file(std::string& name, std::string& filename) | |
| return false; | ||
| } | ||
|
|
||
| // std::cout << "Reading file:" << filename << std::endl; | ||
| LOG_INFO("Reading file:" << filename); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: avoid do-while loops [cppcoreguidelines-avoid-do-while] LOG_INFO("Reading file:" << filename);
^Additional contextsrc/cpp/common/logger.h:58: expanded from macro 'LOG_INFO' do { \
^ |
||
| std::string line; | ||
| m_parserptr->set_data_state(false); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
| #include "target.h" | ||
| #include "utils.h" | ||
| #include "file_utils.h" | ||
| #include "logger.h" | ||
|
|
||
| std::map<uint32_t, std::vector<char> > | ||
| aiebu::utilities:: | ||
|
|
@@ -338,13 +339,15 @@ target_aie4::assemble(const sub_cmd_options &_options) | |
|
|
||
| cxxopts::Options all_options("Target aie4 Options", m_description); | ||
|
|
||
| std::string log_level_str; | ||
| try { | ||
| all_options.add_options() | ||
| ("outputelf,o", "ELF output file name", cxxopts::value<decltype(output_elffile)>()) | ||
| ("asm,c", "ASM File", cxxopts::value<decltype(input_file)>()) | ||
| ("j,json", "control packet Patching json file", cxxopts::value<decltype(external_buffers_file)>()) | ||
| ("L,libpath", "libs path", cxxopts::value<decltype(libpaths)>()) | ||
| ("f,flag", "flags", cxxopts::value<decltype(flags)>()) | ||
| ("f,flag", "flags (e.g., 'verbose' for detailed output, 'disabledump', 'fulldump')", cxxopts::value<decltype(flags)>()) | ||
| ("log-level", "log level: error, warn, info, debug (default: warn)", cxxopts::value<decltype(log_level_str)>()) | ||
| ("help,h", "show help message and exit", cxxopts::value<bool>()->default_value("false")) | ||
| ; | ||
|
|
||
|
|
@@ -379,6 +382,22 @@ target_aie4::assemble(const sub_cmd_options &_options) | |
| if (result.count("json")) | ||
| external_buffers_file = result["json"].as<decltype(external_buffers_file)>(); | ||
|
|
||
| if (result.count("log-level")) { | ||
| log_level_str = result["log-level"].as<decltype(log_level_str)>(); | ||
| if (log_level_str == "error") | ||
| aiebu::set_log_level(aiebu::log_level::error); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how you will set log_level when user is calling lib apis? |
||
| else if (log_level_str == "warn") | ||
| aiebu::set_log_level(aiebu::log_level::warn); | ||
| else if (log_level_str == "info") | ||
| aiebu::set_log_level(aiebu::log_level::info); | ||
| else if (log_level_str == "debug") | ||
| aiebu::set_log_level(aiebu::log_level::debug); | ||
| else { | ||
| auto errMsg = boost::format("Invalid log level: %s. Valid options: error, warn, info, debug\n") % log_level_str; | ||
| throw std::runtime_error(errMsg.str()); | ||
| } | ||
| } | ||
|
Comment on lines
+385
to
+399
|
||
|
|
||
| } | ||
| catch (const cxxopts::exceptions::exception& e) { | ||
| std::cout << all_options.help({"", "Target aie4 Options"}); | ||
|
|
@@ -408,15 +427,17 @@ aiebu::utilities:: | |
| asm_config_parser::parser(const sub_cmd_options &options) | ||
| { | ||
| std::string json_file; | ||
| std::string log_level_str; | ||
| cxxopts::Options all_options("Target config Options", m_description); | ||
| uint32_t optimization_level =0; | ||
|
|
||
| try { | ||
| all_options.add_options() | ||
| ("o,outputelf", "ELF output file name", cxxopts::value<decltype(output_elffile)>()) | ||
| ("j,json", "control packet Patching json file", cxxopts::value<decltype(json_file)>()) | ||
| ("f,flag", "flags", cxxopts::value<decltype(flags)>()) | ||
| ("f,flag", "flags (e.g., 'verbose' for detailed output, 'disabledump', 'fulldump')", cxxopts::value<decltype(flags)>()) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we dont need verbose here, we can merge verbose functionality with fulldump for aie2ps/aie4/aie2ps_config/aie4_config |
||
| ("O,optimization", "optimization level (1-4)", cxxopts::value<int>()->default_value("0")) | ||
| ("log-level", "log level: error, warn, info, debug (default: warn)", cxxopts::value<decltype(log_level_str)>()) | ||
| ("h,help", "show help message and exit", cxxopts::value<bool>()->default_value("false")) | ||
| ; | ||
|
|
||
|
|
@@ -451,6 +472,22 @@ asm_config_parser::parser(const sub_cmd_options &options) | |
| flags.insert(flags.end(), extra_flags.begin(), extra_flags.end()); | ||
| } | ||
|
|
||
| if (result.count("log-level")) { | ||
| log_level_str = result["log-level"].as<decltype(log_level_str)>(); | ||
| if (log_level_str == "error") | ||
| aiebu::set_log_level(aiebu::log_level::error); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
| else if (log_level_str == "warn") | ||
| aiebu::set_log_level(aiebu::log_level::warn); | ||
| else if (log_level_str == "info") | ||
| aiebu::set_log_level(aiebu::log_level::info); | ||
| else if (log_level_str == "debug") | ||
| aiebu::set_log_level(aiebu::log_level::debug); | ||
| else { | ||
| auto errMsg = boost::format("Invalid log level: %s. Valid options: error, warn, info, debug\n") % log_level_str; | ||
| throw std::runtime_error(errMsg.str()); | ||
| } | ||
| } | ||
|
|
||
| } | ||
| catch (const cxxopts::exceptions::exception& e) { | ||
| std::cout << all_options.help({"", "Target config Options"}); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
|
|
||
| #include "aiebu/aiebu_assembler.h" | ||
| #include "aiebu/aiebu_error.h" | ||
| #include "logger.h" | ||
|
|
||
| #include <filesystem> | ||
| #include <fstream> | ||
|
|
@@ -41,7 +42,7 @@ class target | |
| inline void write_elf(const aiebu::aiebu_assembler& as, const std::string& outfile) | ||
| { | ||
| auto e = as.get_elf(); | ||
| std::cout << "elf size:" << e.size() << "\n"; | ||
| LOG_INFO("elf size:" << e.size()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. warning: avoid do-while loops [cppcoreguidelines-avoid-do-while] LOG_INFO("elf size:" << e.size());
^Additional contextsrc/cpp/common/logger.h:58: expanded from macro 'LOG_INFO' do { \
^ |
||
| std::ofstream output_file(outfile, std::ios_base::binary); | ||
| output_file.write(e.data(), e.size()); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: variable 'g_log_level' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
inline log_level g_log_level = log_level::warn; ^