From 0c99509e52b4dc39ba4bea84461c1734d98174c6 Mon Sep 17 00:00:00 2001 From: dezhliao Date: Tue, 6 Aug 2024 16:31:23 -0700 Subject: [PATCH 1/8] Dump control-codes, control-packet and preemption-codes --- .../core/common/api/xrt_device.cpp | 19 +++++++ .../core/common/api/xrt_kernel.cpp | 29 ++++++---- .../core/common/api/xrt_module.cpp | 53 ++++++++++--------- src/runtime_src/core/common/device.cpp | 4 ++ src/runtime_src/core/common/device.h | 30 +++++++++++ 5 files changed, 102 insertions(+), 33 deletions(-) diff --git a/src/runtime_src/core/common/api/xrt_device.cpp b/src/runtime_src/core/common/api/xrt_device.cpp index 0ddefebc4b9..d78091a52d1 100644 --- a/src/runtime_src/core/common/api/xrt_device.cpp +++ b/src/runtime_src/core/common/api/xrt_device.cpp @@ -10,6 +10,7 @@ #include "core/include/xrt/xrt_device.h" #include "core/include/xrt/xrt_aie.h" +#include "core/common/config_reader.h" #include "core/common/device.h" #include "core/common/info_aie.h" #include "core/common/info_memory.h" @@ -329,6 +330,24 @@ get_xclbin_section(axlf_section_kind section, const uuid& uuid) const }); } +bool +device:: +is_dump_control_codes() const { + return handle->is_dump_control_codes(); +} + +bool +device:: +is_dump_control_packet() const { + return handle->is_dump_control_packet(); +} + +bool +device:: +is_dump_preemption_codes() const { + return handle->is_dump_preemption_codes(); +} + // Deprecated but referenced in binaries using xrt-2.11.x and earlier boost::any device:: diff --git a/src/runtime_src/core/common/api/xrt_kernel.cpp b/src/runtime_src/core/common/api/xrt_kernel.cpp index c289d73ebef..e13a67adec0 100644 --- a/src/runtime_src/core/common/api/xrt_kernel.cpp +++ b/src/runtime_src/core/common/api/xrt_kernel.cpp @@ -1957,12 +1957,12 @@ class run_impl switch (kernel->get_kernel_type()) { case kernel_type::pl : if (kernel->get_ip_control_protocol() == control_type::fa) - return std::make_unique(data); - return std::make_unique(data); + return std::make_unique(m_data); + return std::make_unique(m_data); case kernel_type::ps : - return std::make_unique(data); + return std::make_unique(m_data); case kernel_type::dpu : - return std::make_unique(data); + return std::make_unique(m_data); case kernel_type::none : throw std::runtime_error("Internal error: unknown kernel type"); } @@ -2037,7 +2037,7 @@ class run_impl pkt->header = rhs_pkt->header; pkt->state = ERT_CMD_STATE_NEW; std::copy_n(rhs_pkt->data, rhs_pkt->count, pkt->data); - return pkt->data + (rhs->data - rhs_pkt->data); + return pkt->data + (rhs->m_data - rhs_pkt->data); } // For DPU kernels, initialize the instruction buffer(s) in the @@ -2080,7 +2080,7 @@ class run_impl std::bitset cumask; // cumask for command execution xrt_core::device* core_device; // convenience, in scope of kernel std::shared_ptr cmd; // underlying command object - uint32_t* data; // command argument data payload @0x0 + uint32_t* m_data; // command argument data payload @0x0 uint32_t m_header; // cached intialized command header uint32_t uid; // internal unique id for debug std::unique_ptr asetter; // helper to populate payload data @@ -2131,7 +2131,7 @@ class run_impl , cumask(kernel->get_cumask()) , core_device(kernel->get_core_device()) , cmd(std::make_shared(kernel->get_device(), m_hwqueue, kernel->get_hw_context())) - , data(initialize_command(cmd.get())) + , m_data(initialize_command(cmd.get())) , m_header(0) , uid(create_uid()) { @@ -2149,7 +2149,7 @@ class run_impl , cumask(rhs->cumask) , core_device(rhs->core_device) , cmd(std::make_shared(kernel->get_device(), m_hwqueue, kernel->get_hw_context())) - , data(clone_command_data(rhs)) + , m_data(clone_command_data(rhs)) , m_header(rhs->m_header) , uid(create_uid()) , encode_cumasks(rhs->encode_cumasks) @@ -2385,6 +2385,10 @@ class run_impl // constructing args in place // sending state as ERT_CMD_STATE_NEW for kernel start m_usage_logger->log_kernel_run_info(kernel.get(), this, ERT_CMD_STATE_NEW); + + if (core_device->no_exec_cmd_buf()) + return; + cmd->run(); } @@ -2465,6 +2469,9 @@ class run_impl [[nodiscard]] ert_cmd_state wait(const std::chrono::milliseconds& timeout_ms) const { + if (core_device->no_exec_cmd_buf()) + return ERT_CMD_STATE_COMPLETED; + ert_cmd_state state {ERT_CMD_STATE_NEW}; // initial value doesn't matter if (timeout_ms.count()) { auto [ert_state, cv_status] = cmd->wait(timeout_ms); @@ -2490,6 +2497,9 @@ class run_impl [[nodiscard]] std::cv_status wait_throw_on_error(const std::chrono::milliseconds& timeout_ms) const { + if (core_device->no_exec_cmd_buf()) + return std::cv_status::no_timeout; + ert_cmd_state state {ERT_CMD_STATE_NEW}; // initial value doesn't matter if (timeout_ms.count()) { auto [ert_state, cv_status] = cmd->wait(timeout_ms); @@ -2764,7 +2774,7 @@ class mailbox_impl : public run_impl if (kernel->get_ip_control_protocol() == control_type::fa) throw xrt_core::error("Mailbox not supported with FAST_ADAPTER"); - return std::make_unique(data, this); // data is run_impl::data + return std::make_unique(m_data, this); // data is run_impl::data } throw xrt_core::error("Mailbox not supported for non pl kernel types"); @@ -3706,6 +3716,7 @@ run:: wait2(const std::chrono::milliseconds& timeout_ms) const { XRT_TRACE_POINT_SCOPE(xrt_run_wait2); + // if (core_device return xdp::native::profiling_wrapper("xrt::run::wait", [this, &timeout_ms] { return handle->wait_throw_on_error(timeout_ms); diff --git a/src/runtime_src/core/common/api/xrt_module.cpp b/src/runtime_src/core/common/api/xrt_module.cpp index e43a50b0c44..765ac789525 100644 --- a/src/runtime_src/core/common/api/xrt_module.cpp +++ b/src/runtime_src/core/common/api/xrt_module.cpp @@ -243,9 +243,6 @@ struct patcher XRT_CORE_UNUSED void dump_bo(xrt::bo& bo, const std::string& filename) { - if (!xrt_core::config::get_feature_toggle(Debug_Bo_From_Elf_Feature)) - return; - std::ofstream ofs(filename, std::ios::out | std::ios::binary); if (!ofs.is_open()) throw std::runtime_error("Failure opening file " + filename + " for writing!"); @@ -1019,22 +1016,26 @@ class module_sram : public module_impl // copy instruction into bo fill_bo_with_data(m_instr_bo, data); -#ifdef _DEBUG - dump_bo(m_instr_bo, "instrBo.bin"); -#endif + if (m_hwctx.get_device().is_dump_control_codes()) + dump_bo(m_instr_bo, "ctl_codes_pre_patch.bin"); const auto& preempt_save_data = parent->get_preempt_save(); auto preempt_save_data_size = preempt_save_data.size(); - if (preempt_save_data_size > 0) { - m_preempt_save_bo = xrt::bo{ m_hwctx, preempt_save_data_size, xrt::bo::flags::cacheable, 1 /* fix me */ }; - fill_bo_with_data(m_preempt_save_bo, preempt_save_data); - } const auto& preempt_restore_data = parent->get_preempt_restore(); auto preempt_restore_data_size = preempt_restore_data.size(); - if (preempt_restore_data_size > 0) { + + if ((preempt_save_data_size > 0) && (preempt_restore_data_size > 0)) { + m_preempt_save_bo = xrt::bo{ m_hwctx, preempt_save_data_size, xrt::bo::flags::cacheable, 1 /* fix me */ }; + fill_bo_with_data(m_preempt_save_bo, preempt_save_data); + m_preempt_restore_bo = xrt::bo{ m_hwctx, preempt_restore_data_size, xrt::bo::flags::cacheable, 1 /* fix me */ }; fill_bo_with_data(m_preempt_restore_bo, preempt_restore_data); + + if (m_hwctx.get_device().is_dump_preemption_codes()) { + dump_bo(m_preempt_save_bo, "preemption_save_pre_patch.bin"); + dump_bo(m_preempt_restore_bo, "preemption_restore_pre_patch.bin"); + } } if ((preempt_save_data_size > 0) && (preempt_restore_data_size > 0)) { @@ -1068,9 +1069,8 @@ class module_sram : public module_impl // copy instruction into bo fill_ctrlpkt_buf(m_ctrlpkt_bo, data); -#ifdef _DEBUG - dump_bo(m_ctrlpkt_bo, "ctrlpktBo.bin"); -#endif + if (m_hwctx.get_device().is_dump_control_packet()) + dump_bo(m_ctrlpkt_bo, "ctrl_packet_pre_patch.bin"); XRT_DEBUGF("<- module_sram::create_ctrlpkt_buffer()\n"); } @@ -1175,21 +1175,26 @@ class module_sram : public module_impl } else if (os_abi == Elf_Amd_Aie2p) { m_instr_bo.sync(XCL_BO_SYNC_BO_TO_DEVICE); -#ifdef _DEBUG - dump_bo(m_instr_bo, "instrBoPatched.bin"); -#endif + + if (m_hwctx.get_device().is_dump_control_codes()) + dump_bo(m_instr_bo, "ctrl_codes_post_patch.bin"); + if (m_ctrlpkt_bo) { m_ctrlpkt_bo.sync(XCL_BO_SYNC_BO_TO_DEVICE); -#ifdef _DEBUG - dump_bo(m_ctrlpkt_bo, "ctrlpktBoPatched.bin"); -#endif - } - if (m_preempt_save_bo) - m_preempt_save_bo.sync(XCL_BO_SYNC_BO_TO_DEVICE); + if (m_hwctx.get_device().is_dump_control_packet()) + dump_bo(m_ctrlpkt_bo, "ctrl_packet_post_patch.bin"); + } - if (m_preempt_restore_bo) + if (m_preempt_save_bo && m_preempt_restore_bo) { + m_preempt_save_bo.sync(XCL_BO_SYNC_BO_TO_DEVICE); m_preempt_restore_bo.sync(XCL_BO_SYNC_BO_TO_DEVICE); + + if (m_hwctx.get_device().is_dump_preemption_codes()) { + dump_bo(m_preempt_save_bo, "preemption_save_post_patch.bin"); + dump_bo(m_preempt_restore_bo, "preemption_restore_post_patch.bin"); + } + } } m_dirty = false; diff --git a/src/runtime_src/core/common/device.cpp b/src/runtime_src/core/common/device.cpp index c6e82d51282..b5a1f883ef3 100644 --- a/src/runtime_src/core/common/device.cpp +++ b/src/runtime_src/core/common/device.cpp @@ -40,6 +40,10 @@ device(id_type device_id) : m_device_id(device_id) { XRT_DEBUGF("xrt_core::device::device(0x%x) idx(%d)\n", this, device_id); + m_debug_mode.all = 0; + m_debug_mode.debug_flags.dump_control_codes = xrt_core::config::get_feature_toggle("Debug.dump_control_codes"); + m_debug_mode.debug_flags.dump_control_packet = xrt_core::config::get_feature_toggle("Debug.dump_control_packet"); + m_debug_mode.debug_flags.dump_preemption_codes = xrt_core::config::get_feature_toggle("Debug.dump_preemption_codes"); } device:: diff --git a/src/runtime_src/core/common/device.h b/src/runtime_src/core/common/device.h index 9f45ee7bfbb..76e1dad18fd 100644 --- a/src/runtime_src/core/common/device.h +++ b/src/runtime_src/core/common/device.h @@ -201,6 +201,27 @@ class device : public ishim lookup_query(query::key_type query_key) const = 0; public: + + bool + inline no_exec_cmd_buf() const { + return m_debug_mode.all != 0; + } + + bool + inline is_dump_control_codes() const { + return m_debug_mode.debug_flags.dump_control_codes != 0; + } + + bool + inline is_dump_control_packet() const { + return m_debug_mode.debug_flags.dump_control_packet != 0; + } + + bool + inline is_dump_preemption_codes() { + return m_debug_mode.debug_flags.dump_preemption_codes != 0; + } + /** * query() - Query the device for specific property * @@ -485,6 +506,15 @@ class device : public ishim xclbin_map m_xclbins; // currently loaded xclbins (multi-slot) mutable std::mutex m_mutex; std::shared_ptr m_usage_logger = usage_metrics::get_usage_metrics_logger(); + union debug_flag_union { + struct debug_mode_struct { + uint32_t dump_control_codes : 1; + uint32_t dump_control_packet : 1; + uint32_t dump_preemption_codes : 1; + uint32_t reserved : 29; + } debug_flags; + uint32_t all; + }m_debug_mode; }; /** From a48dd9271ae72b64b65e3feb6d8cb19b863a788a Mon Sep 17 00:00:00 2001 From: dezhliao Date: Wed, 7 Aug 2024 11:17:01 -0700 Subject: [PATCH 2/8] Attempt to fix compiling errors on linux --- src/runtime_src/core/include/xrt/xrt_device.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/runtime_src/core/include/xrt/xrt_device.h b/src/runtime_src/core/include/xrt/xrt_device.h index 7a9836c7717..8680154b62b 100644 --- a/src/runtime_src/core/include/xrt/xrt_device.h +++ b/src/runtime_src/core/include/xrt/xrt_device.h @@ -384,6 +384,18 @@ class device return handle; } + XCL_DRIVER_DLLESPEC + bool + is_dump_control_codes() const; + + XCL_DRIVER_DLLESPEC + bool + is_dump_control_packet() const; + + XCL_DRIVER_DLLESPEC + bool + is_dump_preemption_codes() const; + XCL_DRIVER_DLLESPEC void reset(); From 9d415386735443d77e91edec2bfeb7555dca4450 Mon Sep 17 00:00:00 2001 From: dezhliao Date: Wed, 7 Aug 2024 12:10:09 -0700 Subject: [PATCH 3/8] Remove no_exec_cmd_buf --- src/runtime_src/core/common/api/xrt_kernel.cpp | 9 --------- src/runtime_src/core/common/api/xrt_module.cpp | 2 -- src/runtime_src/core/common/device.h | 5 ----- 3 files changed, 16 deletions(-) diff --git a/src/runtime_src/core/common/api/xrt_kernel.cpp b/src/runtime_src/core/common/api/xrt_kernel.cpp index e13a67adec0..60097a31e1e 100644 --- a/src/runtime_src/core/common/api/xrt_kernel.cpp +++ b/src/runtime_src/core/common/api/xrt_kernel.cpp @@ -2386,9 +2386,6 @@ class run_impl // sending state as ERT_CMD_STATE_NEW for kernel start m_usage_logger->log_kernel_run_info(kernel.get(), this, ERT_CMD_STATE_NEW); - if (core_device->no_exec_cmd_buf()) - return; - cmd->run(); } @@ -2469,9 +2466,6 @@ class run_impl [[nodiscard]] ert_cmd_state wait(const std::chrono::milliseconds& timeout_ms) const { - if (core_device->no_exec_cmd_buf()) - return ERT_CMD_STATE_COMPLETED; - ert_cmd_state state {ERT_CMD_STATE_NEW}; // initial value doesn't matter if (timeout_ms.count()) { auto [ert_state, cv_status] = cmd->wait(timeout_ms); @@ -2497,9 +2491,6 @@ class run_impl [[nodiscard]] std::cv_status wait_throw_on_error(const std::chrono::milliseconds& timeout_ms) const { - if (core_device->no_exec_cmd_buf()) - return std::cv_status::no_timeout; - ert_cmd_state state {ERT_CMD_STATE_NEW}; // initial value doesn't matter if (timeout_ms.count()) { auto [ert_state, cv_status] = cmd->wait(timeout_ms); diff --git a/src/runtime_src/core/common/api/xrt_module.cpp b/src/runtime_src/core/common/api/xrt_module.cpp index 765ac789525..d70be27bcdb 100644 --- a/src/runtime_src/core/common/api/xrt_module.cpp +++ b/src/runtime_src/core/common/api/xrt_module.cpp @@ -43,8 +43,6 @@ static constexpr size_t column_page_size = AIE_COLUMN_PAGE_SIZE; static constexpr uint8_t Elf_Amd_Aie2p = 69; static constexpr uint8_t Elf_Amd_Aie2ps = 64; -// When Debug.dump_bo_from_elf is true in xrt.ini, instruction bo(s) from elf will be dumped -static const char* Debug_Bo_From_Elf_Feature = "Debug.dump_bo_from_elf"; static const char* Scratch_Pad_Mem_Symbol = "scratch-pad-mem"; static const char* Control_Packet_Symbol = "control-packet"; diff --git a/src/runtime_src/core/common/device.h b/src/runtime_src/core/common/device.h index 76e1dad18fd..8c679f9fcab 100644 --- a/src/runtime_src/core/common/device.h +++ b/src/runtime_src/core/common/device.h @@ -202,11 +202,6 @@ class device : public ishim public: - bool - inline no_exec_cmd_buf() const { - return m_debug_mode.all != 0; - } - bool inline is_dump_control_codes() const { return m_debug_mode.debug_flags.dump_control_codes != 0; From 98f47e4599309751f0e397fd1a8f99bfaa6926a0 Mon Sep 17 00:00:00 2001 From: dezhliao Date: Wed, 7 Aug 2024 12:23:24 -0700 Subject: [PATCH 4/8] Remove all change to xrt_kernel.cpp --- .../core/common/api/xrt_kernel.cpp | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/runtime_src/core/common/api/xrt_kernel.cpp b/src/runtime_src/core/common/api/xrt_kernel.cpp index 60097a31e1e..c289d73ebef 100644 --- a/src/runtime_src/core/common/api/xrt_kernel.cpp +++ b/src/runtime_src/core/common/api/xrt_kernel.cpp @@ -1957,12 +1957,12 @@ class run_impl switch (kernel->get_kernel_type()) { case kernel_type::pl : if (kernel->get_ip_control_protocol() == control_type::fa) - return std::make_unique(m_data); - return std::make_unique(m_data); + return std::make_unique(data); + return std::make_unique(data); case kernel_type::ps : - return std::make_unique(m_data); + return std::make_unique(data); case kernel_type::dpu : - return std::make_unique(m_data); + return std::make_unique(data); case kernel_type::none : throw std::runtime_error("Internal error: unknown kernel type"); } @@ -2037,7 +2037,7 @@ class run_impl pkt->header = rhs_pkt->header; pkt->state = ERT_CMD_STATE_NEW; std::copy_n(rhs_pkt->data, rhs_pkt->count, pkt->data); - return pkt->data + (rhs->m_data - rhs_pkt->data); + return pkt->data + (rhs->data - rhs_pkt->data); } // For DPU kernels, initialize the instruction buffer(s) in the @@ -2080,7 +2080,7 @@ class run_impl std::bitset cumask; // cumask for command execution xrt_core::device* core_device; // convenience, in scope of kernel std::shared_ptr cmd; // underlying command object - uint32_t* m_data; // command argument data payload @0x0 + uint32_t* data; // command argument data payload @0x0 uint32_t m_header; // cached intialized command header uint32_t uid; // internal unique id for debug std::unique_ptr asetter; // helper to populate payload data @@ -2131,7 +2131,7 @@ class run_impl , cumask(kernel->get_cumask()) , core_device(kernel->get_core_device()) , cmd(std::make_shared(kernel->get_device(), m_hwqueue, kernel->get_hw_context())) - , m_data(initialize_command(cmd.get())) + , data(initialize_command(cmd.get())) , m_header(0) , uid(create_uid()) { @@ -2149,7 +2149,7 @@ class run_impl , cumask(rhs->cumask) , core_device(rhs->core_device) , cmd(std::make_shared(kernel->get_device(), m_hwqueue, kernel->get_hw_context())) - , m_data(clone_command_data(rhs)) + , data(clone_command_data(rhs)) , m_header(rhs->m_header) , uid(create_uid()) , encode_cumasks(rhs->encode_cumasks) @@ -2385,7 +2385,6 @@ class run_impl // constructing args in place // sending state as ERT_CMD_STATE_NEW for kernel start m_usage_logger->log_kernel_run_info(kernel.get(), this, ERT_CMD_STATE_NEW); - cmd->run(); } @@ -2765,7 +2764,7 @@ class mailbox_impl : public run_impl if (kernel->get_ip_control_protocol() == control_type::fa) throw xrt_core::error("Mailbox not supported with FAST_ADAPTER"); - return std::make_unique(m_data, this); // data is run_impl::data + return std::make_unique(data, this); // data is run_impl::data } throw xrt_core::error("Mailbox not supported for non pl kernel types"); @@ -3707,7 +3706,6 @@ run:: wait2(const std::chrono::milliseconds& timeout_ms) const { XRT_TRACE_POINT_SCOPE(xrt_run_wait2); - // if (core_device return xdp::native::profiling_wrapper("xrt::run::wait", [this, &timeout_ms] { return handle->wait_throw_on_error(timeout_ms); From 263d0e3964f072ca16f988c1434e6b57e7bf6afa Mon Sep 17 00:00:00 2001 From: dezhliao Date: Thu, 8 Aug 2024 10:05:41 -0700 Subject: [PATCH 5/8] Put all change in xrt_module.cpp. Not ideal... --- .../core/common/api/xrt_device.cpp | 19 ----- .../core/common/api/xrt_module.cpp | 77 +++++++++++++++---- src/runtime_src/core/common/device.cpp | 4 - src/runtime_src/core/common/device.h | 25 ------ src/runtime_src/core/include/xrt/xrt_device.h | 12 --- 5 files changed, 62 insertions(+), 75 deletions(-) diff --git a/src/runtime_src/core/common/api/xrt_device.cpp b/src/runtime_src/core/common/api/xrt_device.cpp index d78091a52d1..0ddefebc4b9 100644 --- a/src/runtime_src/core/common/api/xrt_device.cpp +++ b/src/runtime_src/core/common/api/xrt_device.cpp @@ -10,7 +10,6 @@ #include "core/include/xrt/xrt_device.h" #include "core/include/xrt/xrt_aie.h" -#include "core/common/config_reader.h" #include "core/common/device.h" #include "core/common/info_aie.h" #include "core/common/info_memory.h" @@ -330,24 +329,6 @@ get_xclbin_section(axlf_section_kind section, const uuid& uuid) const }); } -bool -device:: -is_dump_control_codes() const { - return handle->is_dump_control_codes(); -} - -bool -device:: -is_dump_control_packet() const { - return handle->is_dump_control_packet(); -} - -bool -device:: -is_dump_preemption_codes() const { - return handle->is_dump_preemption_codes(); -} - // Deprecated but referenced in binaries using xrt-2.11.x and earlier boost::any device:: diff --git a/src/runtime_src/core/common/api/xrt_module.cpp b/src/runtime_src/core/common/api/xrt_module.cpp index d70be27bcdb..6090a6339f9 100644 --- a/src/runtime_src/core/common/api/xrt_module.cpp +++ b/src/runtime_src/core/common/api/xrt_module.cpp @@ -265,7 +265,6 @@ namespace xrt class module_impl { xrt::uuid m_cfg_uuid; // matching hw configuration id - public: explicit module_impl(xrt::uuid cfg_uuid) : m_cfg_uuid(std::move(cfg_uuid)) @@ -950,6 +949,36 @@ class module_sram : public module_impl // buffer sync to device. bool m_dirty{ false }; + union debug_flag_union { + struct debug_mode_struct { + uint32_t dump_control_codes : 1; + uint32_t dump_control_packet : 1; + uint32_t dump_preemption_codes : 1; + uint32_t reserved : 29; + } debug_flags; + uint32_t all; + }m_debug_mode = {}; + static uint32_t s_id; //TODO: it needs come from the elf file + + bool + inline is_dump_control_codes() const { + return m_debug_mode.debug_flags.dump_control_codes != 0; + } + + bool + inline is_dump_control_packet() const { + return m_debug_mode.debug_flags.dump_control_packet != 0; + } + + bool + inline is_dump_preemption_codes() { + return m_debug_mode.debug_flags.dump_preemption_codes != 0; + } + + uint32_t get_id() const { + return s_id; + } + // For separated multi-column control code, compute the ctrlcode // buffer object address of each column (used in ert_dpu_data). void @@ -1014,8 +1043,10 @@ class module_sram : public module_impl // copy instruction into bo fill_bo_with_data(m_instr_bo, data); - if (m_hwctx.get_device().is_dump_control_codes()) - dump_bo(m_instr_bo, "ctl_codes_pre_patch.bin"); + if (is_dump_control_codes()) { + std::string dump_file_name = "ctr_codes_pre_patch" + std::to_string(get_id()) + ".bin"; + dump_bo(m_instr_bo, dump_file_name); + } const auto& preempt_save_data = parent->get_preempt_save(); auto preempt_save_data_size = preempt_save_data.size(); @@ -1030,9 +1061,11 @@ class module_sram : public module_impl m_preempt_restore_bo = xrt::bo{ m_hwctx, preempt_restore_data_size, xrt::bo::flags::cacheable, 1 /* fix me */ }; fill_bo_with_data(m_preempt_restore_bo, preempt_restore_data); - if (m_hwctx.get_device().is_dump_preemption_codes()) { - dump_bo(m_preempt_save_bo, "preemption_save_pre_patch.bin"); - dump_bo(m_preempt_restore_bo, "preemption_restore_pre_patch.bin"); + if (is_dump_preemption_codes()) { + std::string dump_file_name = "preemption_save_pre_patch" + std::to_string(get_id()) + ".bin"; + dump_bo(m_preempt_save_bo, dump_file_name); + dump_file_name = "preemption_restore_pre_patch" + std::to_string(get_id()) + ".bin"; + dump_bo(m_preempt_restore_bo, dump_file_name); } } @@ -1067,8 +1100,10 @@ class module_sram : public module_impl // copy instruction into bo fill_ctrlpkt_buf(m_ctrlpkt_bo, data); - if (m_hwctx.get_device().is_dump_control_packet()) - dump_bo(m_ctrlpkt_bo, "ctrl_packet_pre_patch.bin"); + if (is_dump_control_packet()) { + std::string dump_file_name = "ctr_packet_pre_patch" + std::to_string(get_id()) + ".bin"; + dump_bo(m_ctrlpkt_bo, dump_file_name); + } XRT_DEBUGF("<- module_sram::create_ctrlpkt_buffer()\n"); } @@ -1174,23 +1209,29 @@ class module_sram : public module_impl else if (os_abi == Elf_Amd_Aie2p) { m_instr_bo.sync(XCL_BO_SYNC_BO_TO_DEVICE); - if (m_hwctx.get_device().is_dump_control_codes()) - dump_bo(m_instr_bo, "ctrl_codes_post_patch.bin"); + if (is_dump_control_codes()) { + std::string dump_file_name = "ctr_codes_post_patch" + std::to_string(get_id()) + ".bin"; + dump_bo(m_instr_bo, dump_file_name); + } if (m_ctrlpkt_bo) { m_ctrlpkt_bo.sync(XCL_BO_SYNC_BO_TO_DEVICE); - if (m_hwctx.get_device().is_dump_control_packet()) - dump_bo(m_ctrlpkt_bo, "ctrl_packet_post_patch.bin"); + if (is_dump_control_packet()) { + std::string dump_file_name = "ctr_packet_post_patch" + std::to_string(get_id()) + ".bin"; + dump_bo(m_ctrlpkt_bo, dump_file_name); + } } if (m_preempt_save_bo && m_preempt_restore_bo) { m_preempt_save_bo.sync(XCL_BO_SYNC_BO_TO_DEVICE); m_preempt_restore_bo.sync(XCL_BO_SYNC_BO_TO_DEVICE); - if (m_hwctx.get_device().is_dump_preemption_codes()) { - dump_bo(m_preempt_save_bo, "preemption_save_post_patch.bin"); - dump_bo(m_preempt_restore_bo, "preemption_restore_post_patch.bin"); + if (is_dump_preemption_codes()) { + std::string dump_file_name = "preemption_save_post_patch" + std::to_string(get_id()) + ".bin"; + dump_bo(m_preempt_save_bo, dump_file_name); + dump_file_name = "preemption_restore_post_patch" + std::to_string(get_id()) + ".bin"; + dump_bo(m_preempt_restore_bo, dump_file_name); } } } @@ -1251,6 +1292,11 @@ class module_sram : public module_impl , m_parent{ std::move(parent) } , m_hwctx{ std::move(hwctx) } { + m_debug_mode.debug_flags.dump_control_codes = xrt_core::config::get_feature_toggle("Debug.dump_control_codes"); + m_debug_mode.debug_flags.dump_control_packet = xrt_core::config::get_feature_toggle("Debug.dump_control_packet"); + m_debug_mode.debug_flags.dump_preemption_codes = xrt_core::config::get_feature_toggle("Debug.dump_preemption_codes"); + s_id++; + auto os_abi = m_parent.get()->get_os_abi(); if (os_abi == Elf_Amd_Aie2p) { @@ -1283,6 +1329,7 @@ class module_sram : public module_impl return m_scratch_pad_mem; } }; +uint32_t module_sram::s_id = 0; } // namespace xrt diff --git a/src/runtime_src/core/common/device.cpp b/src/runtime_src/core/common/device.cpp index b5a1f883ef3..c6e82d51282 100644 --- a/src/runtime_src/core/common/device.cpp +++ b/src/runtime_src/core/common/device.cpp @@ -40,10 +40,6 @@ device(id_type device_id) : m_device_id(device_id) { XRT_DEBUGF("xrt_core::device::device(0x%x) idx(%d)\n", this, device_id); - m_debug_mode.all = 0; - m_debug_mode.debug_flags.dump_control_codes = xrt_core::config::get_feature_toggle("Debug.dump_control_codes"); - m_debug_mode.debug_flags.dump_control_packet = xrt_core::config::get_feature_toggle("Debug.dump_control_packet"); - m_debug_mode.debug_flags.dump_preemption_codes = xrt_core::config::get_feature_toggle("Debug.dump_preemption_codes"); } device:: diff --git a/src/runtime_src/core/common/device.h b/src/runtime_src/core/common/device.h index 8c679f9fcab..9f45ee7bfbb 100644 --- a/src/runtime_src/core/common/device.h +++ b/src/runtime_src/core/common/device.h @@ -201,22 +201,6 @@ class device : public ishim lookup_query(query::key_type query_key) const = 0; public: - - bool - inline is_dump_control_codes() const { - return m_debug_mode.debug_flags.dump_control_codes != 0; - } - - bool - inline is_dump_control_packet() const { - return m_debug_mode.debug_flags.dump_control_packet != 0; - } - - bool - inline is_dump_preemption_codes() { - return m_debug_mode.debug_flags.dump_preemption_codes != 0; - } - /** * query() - Query the device for specific property * @@ -501,15 +485,6 @@ class device : public ishim xclbin_map m_xclbins; // currently loaded xclbins (multi-slot) mutable std::mutex m_mutex; std::shared_ptr m_usage_logger = usage_metrics::get_usage_metrics_logger(); - union debug_flag_union { - struct debug_mode_struct { - uint32_t dump_control_codes : 1; - uint32_t dump_control_packet : 1; - uint32_t dump_preemption_codes : 1; - uint32_t reserved : 29; - } debug_flags; - uint32_t all; - }m_debug_mode; }; /** diff --git a/src/runtime_src/core/include/xrt/xrt_device.h b/src/runtime_src/core/include/xrt/xrt_device.h index 8680154b62b..7a9836c7717 100644 --- a/src/runtime_src/core/include/xrt/xrt_device.h +++ b/src/runtime_src/core/include/xrt/xrt_device.h @@ -384,18 +384,6 @@ class device return handle; } - XCL_DRIVER_DLLESPEC - bool - is_dump_control_codes() const; - - XCL_DRIVER_DLLESPEC - bool - is_dump_control_packet() const; - - XCL_DRIVER_DLLESPEC - bool - is_dump_preemption_codes() const; - XCL_DRIVER_DLLESPEC void reset(); From 7fd677a67ac137dc97ce0e38c342a4d9f32d4055 Mon Sep 17 00:00:00 2001 From: dezhliao Date: Mon, 12 Aug 2024 15:12:29 -0700 Subject: [PATCH 6/8] Add log file --- .../core/common/api/xrt_module.cpp | 91 ++++++++++++++----- 1 file changed, 68 insertions(+), 23 deletions(-) diff --git a/src/runtime_src/core/common/api/xrt_module.cpp b/src/runtime_src/core/common/api/xrt_module.cpp index 6090a6339f9..1d0f01b8979 100644 --- a/src/runtime_src/core/common/api/xrt_module.cpp +++ b/src/runtime_src/core/common/api/xrt_module.cpp @@ -4,6 +4,7 @@ #define XRT_API_SOURCE // exporting xrt_module.h #define XRT_CORE_COMMON_SOURCE // in same dll as core_common #include "core/common/config_reader.h" +#include "core/common/message.h" #include "experimental/xrt_module.h" #include "experimental/xrt_elf.h" #include "experimental/xrt_ext.h" @@ -28,6 +29,7 @@ #include #include #include +#include #ifndef AIE_COLUMN_PAGE_SIZE # define AIE_COLUMN_PAGE_SIZE 8192 // NOLINT @@ -778,6 +780,18 @@ class module_elf : public module_impl } it->second.patch(base, patch); + if (xrt_core::config::get_xrt_debug()) { + if (not_found_use_argument_name) { + std::stringstream ss; + ss << "Patched " << patcher::section_name_to_string(type) << " use argument index " << index << " with value " << std::hex << patch; + xrt_core::message::send( xrt_core::message::severity_level::debug, "xrt_module", ss.str()); + } + else { + std::stringstream ss; + ss << "Patched " << patcher::section_name_to_string(type) << "use argument name " << argnm << " with value " << std::hex << patch; + xrt_core::message::send( xrt_core::message::severity_level::debug, "xrt_module", ss.str()); + } + } return true; } @@ -1046,6 +1060,10 @@ class module_sram : public module_impl if (is_dump_control_codes()) { std::string dump_file_name = "ctr_codes_pre_patch" + std::to_string(get_id()) + ".bin"; dump_bo(m_instr_bo, dump_file_name); + + std::stringstream ss; + ss << "dumped file " << dump_file_name << " ctr_codes size: " << std::to_string(sz); + xrt_core::message::send(xrt_core::message::severity_level::debug, "xrt_module", ss.str()); } const auto& preempt_save_data = parent->get_preempt_save(); @@ -1064,16 +1082,30 @@ class module_sram : public module_impl if (is_dump_preemption_codes()) { std::string dump_file_name = "preemption_save_pre_patch" + std::to_string(get_id()) + ".bin"; dump_bo(m_preempt_save_bo, dump_file_name); + + std::stringstream ss; + ss << "dumped file " << dump_file_name; + xrt_core::message::send(xrt_core::message::severity_level::debug, "xrt_module", ss.str()); + dump_file_name = "preemption_restore_pre_patch" + std::to_string(get_id()) + ".bin"; dump_bo(m_preempt_restore_bo, dump_file_name); + + ss.clear(); + ss << "dumped file " << dump_file_name; + xrt_core::message::send(xrt_core::message::severity_level::debug, "xrt_module", ss.str()); } } if ((preempt_save_data_size > 0) && (preempt_restore_data_size > 0)) { - XRT_DEBUGF("module_sram::create_instr_buf create scratch_pad_mem of size %d for preemption\n", m_parent->get_scratch_pad_mem_size()); m_scratch_pad_mem = xrt::ext::bo{ m_hwctx, m_parent->get_scratch_pad_mem_size() }; patch_instr(m_preempt_save_bo, Scratch_Pad_Mem_Symbol, 0, m_scratch_pad_mem, patcher::buf_type::preempt_save); patch_instr(m_preempt_restore_bo, Scratch_Pad_Mem_Symbol, 0, m_scratch_pad_mem, patcher::buf_type::preempt_restore); + + if (is_dump_preemption_codes()) { + std::stringstream ss; + ss << "patched preemption-codes using scratch_pad_mem at address " << std::hex << m_scratch_pad_mem.address() << " size " << std::hex << m_parent->get_scratch_pad_mem_size(); + xrt_core::message::send(xrt_core::message::severity_level::debug, "xrt_module", ss.str()); + } } if (m_ctrlpkt_bo) { @@ -1085,27 +1117,25 @@ class module_sram : public module_impl void create_ctrlpkt_buf(const module_impl* parent) { - XRT_DEBUGF("-> module_sram::create_ctrlpkt_buf()\n"); const auto& data = parent->get_ctrlpkt(); size_t sz = data.size(); if (sz == 0) { - XRT_DEBUGF("ctrlpkt buf is empty\n"); + XRT_DEBUGF("ctrpkt buf is empty\n"); + return; } - else { - // create bo combined size of all ctrlcodes - // m_ctrlpkt_buf = xrt::bo{m_hwctx, sz, xrt::bo::flags::host_only, 0}; - m_ctrlpkt_bo = xrt::ext::bo{ m_hwctx, sz }; - // copy instruction into bo - fill_ctrlpkt_buf(m_ctrlpkt_bo, data); + m_ctrlpkt_bo = xrt::ext::bo{ m_hwctx, sz }; - if (is_dump_control_packet()) { - std::string dump_file_name = "ctr_packet_pre_patch" + std::to_string(get_id()) + ".bin"; - dump_bo(m_ctrlpkt_bo, dump_file_name); - } + fill_ctrlpkt_buf(m_ctrlpkt_bo, data); + + if (is_dump_control_packet()) { + std::string dump_file_name = "ctr_packet_pre_patch" + std::to_string(get_id()) + ".bin"; + dump_bo(m_ctrlpkt_bo, dump_file_name); - XRT_DEBUGF("<- module_sram::create_ctrlpkt_buffer()\n"); + std::stringstream ss; + ss << "dumped file " << dump_file_name; + xrt_core::message::send(xrt_core::message::severity_level::debug, "xrt_module", ss.str()); } } @@ -1114,7 +1144,6 @@ class module_sram : public module_impl void create_instruction_buffer(const module_impl* parent) { - XRT_DEBUGF("-> module_sram::create_instruction_buffer()\n"); const auto& data = parent->get_data(); // create bo combined size of all ctrlcodes @@ -1122,16 +1151,13 @@ class module_sram : public module_impl return acc + ctrlcode.size(); }); if (sz == 0) { - std::cout << "instruction buf is empty" << std::endl; + XRT_DEBUGF("ctrcode buf is empty\n"); return; } m_buffer = xrt::bo{ m_hwctx, sz, xrt::bo::flags::cacheable, 1 /* fix me */ }; - // copy ctrlcodes into bo fill_instruction_buffer(m_buffer, data); - - XRT_DEBUGF("<- module_sram::create_instruction_buffer()\n"); } virtual void @@ -1212,6 +1238,10 @@ class module_sram : public module_impl if (is_dump_control_codes()) { std::string dump_file_name = "ctr_codes_post_patch" + std::to_string(get_id()) + ".bin"; dump_bo(m_instr_bo, dump_file_name); + + std::stringstream ss; + ss << "dumped file " << dump_file_name; + xrt_core::message::send(xrt_core::message::severity_level::debug, "xrt_module", ss.str()); } if (m_ctrlpkt_bo) { @@ -1220,6 +1250,10 @@ class module_sram : public module_impl if (is_dump_control_packet()) { std::string dump_file_name = "ctr_packet_post_patch" + std::to_string(get_id()) + ".bin"; dump_bo(m_ctrlpkt_bo, dump_file_name); + + std::stringstream ss; + ss << "dumped file " << dump_file_name; + xrt_core::message::send(xrt_core::message::severity_level::debug, "xrt_module", ss.str()); } } @@ -1230,8 +1264,17 @@ class module_sram : public module_impl if (is_dump_preemption_codes()) { std::string dump_file_name = "preemption_save_post_patch" + std::to_string(get_id()) + ".bin"; dump_bo(m_preempt_save_bo, dump_file_name); + + std::stringstream ss; + ss << "dumped file " << dump_file_name; + xrt_core::message::send(xrt_core::message::severity_level::debug, "xrt_module", ss.str()); + dump_file_name = "preemption_restore_post_patch" + std::to_string(get_id()) + ".bin"; dump_bo(m_preempt_restore_bo, dump_file_name); + + ss.clear(); + ss << "dumped file " << dump_file_name; + xrt_core::message::send(xrt_core::message::severity_level::debug, "xrt_module", ss.str()); } } } @@ -1292,10 +1335,12 @@ class module_sram : public module_impl , m_parent{ std::move(parent) } , m_hwctx{ std::move(hwctx) } { - m_debug_mode.debug_flags.dump_control_codes = xrt_core::config::get_feature_toggle("Debug.dump_control_codes"); - m_debug_mode.debug_flags.dump_control_packet = xrt_core::config::get_feature_toggle("Debug.dump_control_packet"); - m_debug_mode.debug_flags.dump_preemption_codes = xrt_core::config::get_feature_toggle("Debug.dump_preemption_codes"); - s_id++; + if (xrt_core::config::get_xrt_debug()) { + m_debug_mode.debug_flags.dump_control_codes = xrt_core::config::get_feature_toggle("Debug.dump_control_codes"); + m_debug_mode.debug_flags.dump_control_packet = xrt_core::config::get_feature_toggle("Debug.dump_control_packet"); + m_debug_mode.debug_flags.dump_preemption_codes = xrt_core::config::get_feature_toggle("Debug.dump_preemption_codes"); + s_id++; + } auto os_abi = m_parent.get()->get_os_abi(); From 8f2769daee6dde1d6867d4b10ad15d003c944924 Mon Sep 17 00:00:00 2001 From: dezhliao Date: Mon, 19 Aug 2024 10:03:15 -0700 Subject: [PATCH 7/8] Trigger debugging elf-flow only if xrt_core::config::get_xrt_debug is true --- src/runtime_src/core/common/api/xrt_elf.cpp | 7 +++++++ src/runtime_src/core/common/api/xrt_module.cpp | 12 ++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/runtime_src/core/common/api/xrt_elf.cpp b/src/runtime_src/core/common/api/xrt_elf.cpp index 6c4965ecf33..bb522c32e74 100644 --- a/src/runtime_src/core/common/api/xrt_elf.cpp +++ b/src/runtime_src/core/common/api/xrt_elf.cpp @@ -7,7 +7,9 @@ #include "xrt/xrt_uuid.h" #include "elf_int.h" +#include "core/common/config_reader.h" #include "core/common/error.h" +#include "core/common/message.h" #include #include @@ -26,6 +28,11 @@ class elf_impl { if (!m_elf.load(fnm)) throw std::runtime_error(fnm + " is not found or is not a valid ELF file"); + + if (xrt_core::config::get_xrt_debug()) { + std::string message = "Loaded elf file " + fnm; + xrt_core::message::send( xrt_core::message::severity_level::debug, "xrt_elf", message); + } } explicit elf_impl(std::istream& stream) diff --git a/src/runtime_src/core/common/api/xrt_module.cpp b/src/runtime_src/core/common/api/xrt_module.cpp index 1d0f01b8979..ebaa6445cd4 100644 --- a/src/runtime_src/core/common/api/xrt_module.cpp +++ b/src/runtime_src/core/common/api/xrt_module.cpp @@ -783,12 +783,12 @@ class module_elf : public module_impl if (xrt_core::config::get_xrt_debug()) { if (not_found_use_argument_name) { std::stringstream ss; - ss << "Patched " << patcher::section_name_to_string(type) << " use argument index " << index << " with value " << std::hex << patch; + ss << "Patched " << patcher::section_name_to_string(type) << " using argument index " << index << " with value " << std::hex << patch; xrt_core::message::send( xrt_core::message::severity_level::debug, "xrt_module", ss.str()); } else { std::stringstream ss; - ss << "Patched " << patcher::section_name_to_string(type) << "use argument name " << argnm << " with value " << std::hex << patch; + ss << "Patched " << patcher::section_name_to_string(type) << " using argument name " << argnm << " with value " << std::hex << patch; xrt_core::message::send( xrt_core::message::severity_level::debug, "xrt_module", ss.str()); } } @@ -972,7 +972,7 @@ class module_sram : public module_impl } debug_flags; uint32_t all; }m_debug_mode = {}; - static uint32_t s_id; //TODO: it needs come from the elf file + uint32_t m_id {0}; //TODO: it needs come from the elf file bool inline is_dump_control_codes() const { @@ -990,7 +990,7 @@ class module_sram : public module_impl } uint32_t get_id() const { - return s_id; + return m_id; } // For separated multi-column control code, compute the ctrlcode @@ -1339,7 +1339,8 @@ class module_sram : public module_impl m_debug_mode.debug_flags.dump_control_codes = xrt_core::config::get_feature_toggle("Debug.dump_control_codes"); m_debug_mode.debug_flags.dump_control_packet = xrt_core::config::get_feature_toggle("Debug.dump_control_packet"); m_debug_mode.debug_flags.dump_preemption_codes = xrt_core::config::get_feature_toggle("Debug.dump_preemption_codes"); - s_id++; + static std::atomic s_id {0}; + m_id = s_id++; } auto os_abi = m_parent.get()->get_os_abi(); @@ -1374,7 +1375,6 @@ class module_sram : public module_impl return m_scratch_pad_mem; } }; -uint32_t module_sram::s_id = 0; } // namespace xrt From 0b01267fb0ce02cc7cf5ee7435b3a77c9b9280d2 Mon Sep 17 00:00:00 2001 From: dezhliao Date: Mon, 19 Aug 2024 10:45:56 -0700 Subject: [PATCH 8/8] Attempt to fix compile error on centos78 --- src/runtime_src/core/common/api/xrt_module.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/runtime_src/core/common/api/xrt_module.cpp b/src/runtime_src/core/common/api/xrt_module.cpp index ebaa6445cd4..2250cfda2b4 100644 --- a/src/runtime_src/core/common/api/xrt_module.cpp +++ b/src/runtime_src/core/common/api/xrt_module.cpp @@ -23,6 +23,7 @@ #include #include +#include #include #include #include