Skip to content

Commit

Permalink
VITIS-11503 - Dump instruction bo created from Elf so verification ca…
Browse files Browse the repository at this point in the history
…n be done (#8043)

* VITIS-11503 - Dump instruction bo created from Elf so verification can be done

* VITIS-11503 -respond to review comments

* VITIS-11503 Add a function dump_bo for reuse

* VITIS-11503 - change function dump_bo under unnamed space

* VITIS-11503 - early return in function dump_bo if feature is not enabled

* VITIS-11503 A function unused in release builds must have XRT_CORE_UNUSED

---------

Co-authored-by: dezhliao <[email protected]>
  • Loading branch information
dezhiAmd and dezhliao authored Apr 5, 2024
1 parent cb8d4d0 commit 347acbd
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/runtime_src/core/common/api/xrt_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#define XCL_DRIVER_DLL_EXPORT // exporting xrt_module.h
#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 "experimental/xrt_module.h"
#include "experimental/xrt_elf.h"
#include "experimental/xrt_ext.h"
Expand Down Expand Up @@ -41,6 +42,9 @@ 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 std::string Debug_Bo_From_Elf_Feature = "Debug.dump_bo_from_elf";

struct buf
{
std::vector<uint8_t> m_data;
Expand Down Expand Up @@ -197,6 +201,19 @@ 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!");

auto buf = bo.map<char*>();
ofs.write(buf, bo.size());
}
} // namespace

namespace xrt
Expand Down Expand Up @@ -808,8 +825,16 @@ class module_sram : public module_impl
// copy instruction into bo
fill_instr_buf(m_instr_buf, data);

#ifdef _DEBUG
dump_bo(m_instr_buf, "instrBo.bin");
#endif

if (m_ctrlpkt_buf) {
patch_instr("control-packet", m_ctrlpkt_buf);

#ifdef _DEBUG
dump_bo(m_instr_buf, "instrBoPatchedByCtrlPacket.bin");
#endif
XRT_PRINTF("<- module_sram::create_instr_buf()\n");
}
}
Expand All @@ -831,6 +856,11 @@ class module_sram : public module_impl

// copy instruction into bo
fill_ctrlpkt_buf(m_ctrlpkt_buf, data);

#ifdef _DEBUG
dump_bo(m_ctrlpkt_buf, "ctrlpktBo.bin");
#endif

XRT_PRINTF("<- module_sram::create_ctrlpkt_buffer()\n");
}
}
Expand Down

0 comments on commit 347acbd

Please sign in to comment.