Skip to content

Commit

Permalink
Add capture and replay for extended classes of XRT (Xilinx#8580)
Browse files Browse the repository at this point in the history
Signed-off-by: Harsh Wardhan <hwardhan@amd.com>
  • Loading branch information
theharshwardhan authored Oct 29, 2024
1 parent 5952bcf commit 4cf22ce
Show file tree
Hide file tree
Showing 5 changed files with 316 additions and 7 deletions.
198 changes: 196 additions & 2 deletions src/runtime_src/core/tools/xbreplay/src/replay_xrt/replay_xrt_bo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@

namespace xrt_core::tools::xbreplay {

#ifdef _WIN32
using export_handle = uint64_t;
#else
using export_handle = int32_t;
#endif /* #ifdef _WIN32 */

/**
* Replay maintains a map where each member function of the XRT classes is associated
* with a corresponding lambda function. This API adds a lambda function entry for each
Expand Down Expand Up @@ -125,6 +131,51 @@ void replay_xrt::register_bo_class_func()
throw std::runtime_error("failed to get dev handle");
};

m_api_map["xrt::bo::bo(const xrt::device&, export_handle)"] =
[this] (std::shared_ptr<utils::message> msg)
{
const std::vector<std::pair<std::string, std::string>>& args = msg->m_args;

/* get dev handle */
auto dev_handle = std::stoull(args[0].second, nullptr, utils::base_hex);

/* From handle obtained from log get the corresponding device
* handle from map
*/
std::shared_ptr<xrt::device> dev = m_device_hndle_map[dev_handle];

if (dev)
{
auto ehdl = static_cast<export_handle>(std::stoull(args[1].second, nullptr, utils::base_hex));
m_bo_hndle_map[msg->m_handle] = std::make_shared<xrt::bo>(*dev, ehdl);
}
else
throw std::runtime_error("failed to get dev handle");
};

m_api_map["xrt::bo::bo(const xrt::device&, xrt::pid_type, export_handle)"] =
[this] (std::shared_ptr<utils::message> msg)
{
const std::vector<std::pair<std::string, std::string>>& args = msg->m_args;

/* get dev handle */
auto dev_handle = std::stoull(args[0].second, nullptr, utils::base_hex);

/* From handle obtained from log get the corresponding device
* handle from map
*/
std::shared_ptr<xrt::device> dev = m_device_hndle_map[dev_handle];

if (dev)
{
xrt::pid_type pid{std::stoi(args[1].second)};
auto ehdl = static_cast<export_handle>(std::stoull(args[2].second, nullptr, utils::base_hex));
m_bo_hndle_map[msg->m_handle] = std::make_shared<xrt::bo>(*dev, pid, ehdl);
}
else
throw std::runtime_error("failed to get dev handle");
};

m_api_map["xrt::bo::bo(const xrt::hw_context&, void*, size_t, xrt::memory_group)"] =
[this] (std::shared_ptr<utils::message>msg)
{
Expand Down Expand Up @@ -324,7 +375,127 @@ void replay_xrt::register_bo_class_func()
throw std::runtime_error("failed to get pbo handle");
};

m_api_map["ext::bo::bo(constxrt::hw_context&, size_t, xrt::ext::bo::access_mode)"] =
m_api_map["ext::bo::bo(const xrt::device&, void*, size_t, xrt::ext::bo::access_mode)"] =
[this] (std::shared_ptr<utils::message> msg)
{
const std::vector <std::pair<std::string, std::string>> &args = msg->m_args;

/* get device handle */
auto dev_handle = std::stoull(args[0].second, nullptr, utils::base_hex);

/* From handle obtained from log get the corresponding device
* handle from map
*/
std::shared_ptr<xrt::device> dev = m_device_hndle_map[dev_handle];

if (dev)
{
void* userptr = reinterpret_cast<void*>(std::stoull(args[1].second, nullptr, utils::base_hex));
size_t sz = std::stoull(args[2].second);
auto acc_mode = static_cast<xrt::ext::bo::access_mode>(std::stol(args[3].second));

m_bo_hndle_map[msg->m_handle] = std::make_shared<xrt::ext::bo>(*dev, userptr, sz, acc_mode);
}
else
throw std::runtime_error("failed to get device handle");
};

m_api_map["ext::bo::bo(const xrt::device&, void*, size_t)"] =
[this] (std::shared_ptr<utils::message> msg)
{
const std::vector <std::pair<std::string, std::string>> &args = msg->m_args;

/* get device handle */
auto dev_handle = std::stoull(args[0].second, nullptr, utils::base_hex);

/* From handle obtained from log get the corresponding device
* handle from map
*/
std::shared_ptr<xrt::device> dev = m_device_hndle_map[dev_handle];

if (dev)
{
void* userptr = reinterpret_cast<void*>(std::stoull(args[1].second, nullptr, utils::base_hex));
size_t sz = std::stoull(args[2].second);

m_bo_hndle_map[msg->m_handle] = std::make_shared<xrt::ext::bo>(*dev, userptr, sz);
}
else
throw std::runtime_error("failed to get device handle");
};

m_api_map["ext::bo::bo(const xrt::device&, size_t, xrt::ext::bo::access_mode)"] =
[this] (std::shared_ptr<utils::message> msg)
{
const std::vector <std::pair<std::string, std::string>> &args = msg->m_args;

/* get device handle */
auto dev_handle = std::stoull(args[0].second, nullptr, utils::base_hex);

/* From handle obtained from log get the corresponding device
* handle from map
*/
std::shared_ptr<xrt::device> dev = m_device_hndle_map[dev_handle];

if (dev)
{
size_t sz = std::stoull(args[1].second);
auto acc_mode = static_cast<xrt::ext::bo::access_mode>(std::stol(args[2].second));

m_bo_hndle_map[msg->m_handle] = std::make_shared<xrt::ext::bo>(*dev, sz, acc_mode);
}
else
throw std::runtime_error("failed to get device handle");
};

m_api_map["ext::bo::bo(const xrt::device&, size_t)"] =
[this] (std::shared_ptr<utils::message> msg)
{
const std::vector <std::pair<std::string, std::string>> &args = msg->m_args;

/* get device handle */
auto dev_handle = std::stoull(args[0].second, nullptr, utils::base_hex);

/* From handle obtained from log get the corresponding device
* handle from map
*/
std::shared_ptr<xrt::device> dev = m_device_hndle_map[dev_handle];

if (dev)
{
size_t sz = std::stoull(args[1].second);

m_bo_hndle_map[msg->m_handle] = std::make_shared<xrt::ext::bo>(*dev, sz);
}
else
throw std::runtime_error("failed to get device handle");
};

m_api_map["ext::bo::bo(const xrt::device&, xrt::pid_type, xrt::bo::export_handle)"] =
[this] (std::shared_ptr<utils::message> msg)
{
const std::vector <std::pair<std::string, std::string>> &args = msg->m_args;

/* get device handle */
auto dev_handle = std::stoull(args[0].second, nullptr, utils::base_hex);

/* From handle obtained from log get the corresponding device
* handle from map
*/
std::shared_ptr<xrt::device> dev = m_device_hndle_map[dev_handle];

if (dev)
{
xrt::pid_type pid{std::stoi(args[1].second)};
auto ehdl = static_cast<xrt::bo::export_handle>(std::stoull(args[2].second, nullptr, utils::base_hex));

m_bo_hndle_map[msg->m_handle] = std::make_shared<xrt::ext::bo>(*dev, pid, ehdl);
}
else
throw std::runtime_error("failed to get device handle");
};

m_api_map["ext::bo::bo(const xrt::hw_context&, size_t, xrt::ext::bo::access_mode)"] =
[this] (std::shared_ptr<utils::message>msg)
{
const std::vector <std::pair<std::string, std::string>> &args = msg->m_args;
Expand All @@ -340,14 +511,37 @@ void replay_xrt::register_bo_class_func()
if (hw_ctx)
{
size_t sz = std::stoi(args[1].second);
auto acc_mode = static_cast<xrt::ext::bo::access_mode>(stol(args[2].second));
auto acc_mode = static_cast<xrt::ext::bo::access_mode>(std::stol(args[2].second));

m_bo_hndle_map[msg->m_handle] = std::make_shared<xrt::ext::bo>(*hw_ctx, sz, acc_mode);
}
else
throw std::runtime_error("failed to get hw_ctx handle");
};

m_api_map["ext::bo::bo(const xrt::hw_context&, size_t)"] =
[this] (std::shared_ptr<utils::message>msg)
{
const std::vector <std::pair<std::string, std::string>> &args = msg->m_args;

/* get hwctx handle */
auto hwctx_hdl = std::stoull(args[0].second, nullptr, utils::base_hex);

/* From handle obtained from log get the corresponding hw_context
* handle from map
*/
auto hw_ctx = m_hwctx_hndle_map[hwctx_hdl];

if (hw_ctx)
{
size_t sz = std::stoull(args[1].second);

m_bo_hndle_map[msg->m_handle] = std::make_shared<xrt::ext::bo>(*hw_ctx, sz);
}
else
throw std::runtime_error("failed to get hw_ctx handle");
};

m_api_map["xrt::bo::~bo()"] =
[this] (std::shared_ptr<utils::message>msg)
{
Expand Down
9 changes: 9 additions & 0 deletions src/runtime_src/core/tools/xbtracer/src/lib/capture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ const static std::unordered_map < std::string, void **> fname2fptr_map = {
{"xrt::bo::bo(xrt::device const&, void*, unsigned long, unsigned int)", (void **) &dtbl.bo.ctor_dev_up_s_g},
{"xrt::bo::bo(xrt::device const&, unsigned long, xrt::bo::flags, unsigned int)", (void **) &dtbl.bo.ctor_dev_s_f_g},
{"xrt::bo::bo(xrt::device const&, unsigned long, unsigned int)", (void **) &dtbl.bo.ctor_dev_s_g},
{"xrt::bo::bo(xrt::device const&, export_handle)", (void **) &dtbl.bo.ctor_dev_ehdl},
{"xrt::bo::bo(xrt::device const&, xrt::pid_type, export_handle)", (void **) &dtbl.bo.ctor_dev_pid_ehdl},
{"xrt::bo::bo(xrt::hw_context const&, void*, unsigned long, xrt::bo::flags, unsigned int)", (void **) &dtbl.bo.ctor_cxt_up_s_f_g},
{"xrt::bo::bo(xrt::hw_context const&, void*, unsigned long, unsigned int)", (void **) &dtbl.bo.ctor_cxt_up_s_g},
{"xrt::bo::bo(xrt::hw_context const&, unsigned long, xrt::bo::flags, unsigned int)", (void **) &dtbl.bo.ctor_cxt_s_f_g},
Expand All @@ -85,7 +87,13 @@ const static std::unordered_map < std::string, void **> fname2fptr_map = {
{"xrt::bo::read(void*, unsigned long, unsigned long)", (void **) &dtbl.bo.read},
{"xrt::bo::copy(xrt::bo const&, unsigned long, unsigned long, unsigned long)", (void **) &dtbl.bo.copy},
{"xrt::bo::bo(void*)", (void **) &dtbl.bo.ctor_xcl_bh},
{"xrt::ext::bo::bo(xrt::device const&,void*, unsigned long, xrt::ext::bo::access_mode)", (void **) &dtbl.ext.bo_ctor_dev_up_s_a},
{"xrt::ext::bo::bo(xrt::device const&,void*, unsigned long)", (void **) &dtbl.ext.bo_ctor_dev_up_s},
{"xrt::ext::bo::bo(xrt::device const&, unsigned long, xrt::ext::bo::access_mode)", (void **) &dtbl.ext.bo_ctor_dev_s_a},
{"xrt::ext::bo::bo(xrt::device const&, unsigned long)", (void **) &dtbl.ext.bo_ctor_dev_s},
{"xrt::ext::bo(xrt::device const&, xrt::pid_type, xrt::bo::export_handle)", (void **) &dtbl.ext.bo_ctor_dev_pid_ehdl},
{"xrt::ext::bo::bo(xrt::hw_context const&, unsigned long, xrt::ext::bo::access_mode)", (void **) &dtbl.ext.bo_ctor_cxt_s_a},
{"xrt::ext::bo::bo(xrt::hw_context const&, unsigned long)", (void **) &dtbl.ext.bo_ctor_cxt_s},

/* run class maps */
{"xrt::run::run(xrt::kernel const&)", (void **) &dtbl.run.ctor},
Expand Down Expand Up @@ -449,6 +457,7 @@ namespace xrt::tools::xbtracer {

std::string demangled_and_conditioned_str =
find_and_replace_all(demangled_str, replacements);

return demangled_and_conditioned_str;
}
else
Expand Down
87 changes: 85 additions & 2 deletions src/runtime_src/core/tools/xbtracer/src/lib/xrt_bo_inst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,24 @@ bo::bo(const xrt::device& device, size_t sz, xrt::memory_group grp)
XRT_TOOLS_XBT_FUNC_EXIT(func);
}

bo::bo(const xrt::device& device, export_handle ehdl)
{
auto func = "xrt::bo::bo(const xrt::device&, export_handle)";
XRT_TOOLS_XBT_CALL_CTOR(dtbl.bo.ctor_dev_ehdl, this, device, ehdl);
/* As pimpl will be updated only after ctor call */
XRT_TOOLS_XBT_FUNC_ENTRY(func, device.get_handle().get(), ehdl);
XRT_TOOLS_XBT_FUNC_EXIT(func);
}

bo::bo(const xrt::device& device, pid_type pid, export_handle ehdl)
{
auto func = "xrt::bo::bo(const xrt::device&, pid_type, export_handle)";
XRT_TOOLS_XBT_CALL_CTOR(dtbl.bo.ctor_dev_pid_ehdl, this, device, pid, ehdl);
/* As pimpl will be updated only after ctor call */
XRT_TOOLS_XBT_FUNC_ENTRY(func, device.get_handle().get(), pid.pid, ehdl);
XRT_TOOLS_XBT_FUNC_EXIT(func);
}

bo::bo(const xrt::hw_context& hwctx, void* userptr, size_t sz, bo::flags flags,
memory_group grp)
{
Expand Down Expand Up @@ -284,14 +302,79 @@ bo::bo(xrtBufferHandle hbuf)
// xrt_ext::bo C++ API implmentations (xrt_ext.h)
////////////////////////////////////////////////////////////////
namespace xrt::ext {
bo::
bo(const xrt::device& device, void* userptr, size_t sz, access_mode access)
{
auto func = "ext::bo::bo(const xrt::device&, void*, size_t, xrt::ext::bo::access_mode)";
XRT_TOOLS_XBT_CALL_EXT_CTOR(dtbl.ext.bo_ctor_dev_up_s_a, this, device, userptr, sz, access);
/* As pimpl will be updated only after ctor call*/
XRT_TOOLS_XBT_FUNC_ENTRY(func,
device.get_handle().get(), userptr, sz, (int)access);
XRT_TOOLS_XBT_FUNC_EXIT(func);
}

bo::
bo(const xrt::device& device, void* userptr, size_t sz)
{
auto func = "ext::bo::bo(const xrt::device&, void*, size_t)";
XRT_TOOLS_XBT_CALL_EXT_CTOR(dtbl.ext.bo_ctor_dev_up_s, this, device, userptr, sz);
/* As pimpl will be updated only after ctor call*/
XRT_TOOLS_XBT_FUNC_ENTRY(func,
device.get_handle().get(), userptr, sz);
XRT_TOOLS_XBT_FUNC_EXIT(func);
}

bo::
bo(const xrt::device& device, size_t sz, access_mode access)
{
auto func = "ext::bo::bo(const xrt::device&, size_t, xrt::ext::bo::access_mode)";
XRT_TOOLS_XBT_CALL_EXT_CTOR(dtbl.ext.bo_ctor_dev_s_a, this, device, sz, access);
/* As pimpl will be updated only after ctor call*/
XRT_TOOLS_XBT_FUNC_ENTRY(func, device.get_handle().get(),
sz, (int)access);
XRT_TOOLS_XBT_FUNC_EXIT(func);
}

bo::
bo(const xrt::device& device, size_t sz)
{
auto func = "ext::bo::bo(const xrt::device&, size_t)";
XRT_TOOLS_XBT_CALL_EXT_CTOR(dtbl.ext.bo_ctor_dev_s, this, device, sz);
/* As pimpl will be updated only after ctor call*/
XRT_TOOLS_XBT_FUNC_ENTRY(func, device.get_handle().get(),
sz);
XRT_TOOLS_XBT_FUNC_EXIT(func);
}

bo::
bo(const xrt::device& device, pid_type pid, xrt::bo::export_handle ehdl)
{
auto func = "ext::bo::bo(const xrt::device&, pid_type, xrt::bo::export_handle)";
XRT_TOOLS_XBT_CALL_EXT_CTOR(dtbl.ext.bo_ctor_dev_pid_ehdl, this, device, pid, ehdl);
/* As pimpl will be updated only after ctor call */
XRT_TOOLS_XBT_FUNC_ENTRY(func, device.get_handle().get(), pid.pid, ehdl);
XRT_TOOLS_XBT_FUNC_EXIT(func);
}

bo::
bo(const xrt::hw_context& hwctx, size_t sz, access_mode access)
{
auto func = "ext::bo::bo(constxrt::hw_context&, size_t, xrt::ext::bo::access_mode)";
auto func = "ext::bo::bo(const xrt::hw_context&, size_t, xrt::ext::bo::access_mode)";
XRT_TOOLS_XBT_CALL_EXT_CTOR(dtbl.ext.bo_ctor_cxt_s_a, this, hwctx, sz, access);
/* As pimpl will be updated only after ctor call*/
/* As pimpl will be updated only after ctor call */
XRT_TOOLS_XBT_FUNC_ENTRY(func, hwctx.get_handle().get(),
sz, (int)access);
XRT_TOOLS_XBT_FUNC_EXIT(func);
}

bo::
bo(const xrt::hw_context& hwctx, size_t sz)
{
auto func = "ext::bo::bo(const xrt::hw_context&, size_t)";
XRT_TOOLS_XBT_CALL_EXT_CTOR(dtbl.ext.bo_ctor_cxt_s, this, hwctx, sz);
/* As pimpl will be updated only after ctor call */
XRT_TOOLS_XBT_FUNC_ENTRY(func, hwctx.get_handle().get(), sz);
XRT_TOOLS_XBT_FUNC_EXIT(func);
}

} // namespace xrt::ext
6 changes: 6 additions & 0 deletions src/runtime_src/core/tools/xbtracer/src/lib/xrt_bo_inst.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ using xrt_bo_ctor_dev_s_f_g = xrt::bo* (*)(void*, const xrt::device&, size_t,\
xrt::bo::flags, xrt::memory_group);
using xrt_bo_ctor_dev_s_g = xrt::bo* (*)(void*, const xrt::device&, size_t,\
xrt::memory_group);
using xrt_bo_ctor_dev_ehdl = xrt::bo* (*)(void*, const xrt::device&,\
export_handle);
using xrt_bo_ctor_dev_pid_ehdl = xrt::bo* (*)(void*, const xrt::device&,\
xrt::pid_type, export_handle);
using xrt_bo_ctor_cxt_up_s_f_g = xrt::bo* (*)(void*, const xrt::hw_context&,\
void*, size_t, xrt::bo::flags, xrt::memory_group);
using xrt_bo_ctor_cxt_up_s_g = xrt::bo* (*)(void*, const xrt::hw_context&,\
Expand Down Expand Up @@ -69,6 +73,8 @@ struct xrt_bo_ftbl
xrt_bo_ctor_dev_up_s_g ctor_dev_up_s_g;
xrt_bo_ctor_dev_s_f_g ctor_dev_s_f_g;
xrt_bo_ctor_dev_s_g ctor_dev_s_g;
xrt_bo_ctor_dev_ehdl ctor_dev_ehdl;
xrt_bo_ctor_dev_pid_ehdl ctor_dev_pid_ehdl;
xrt_bo_ctor_cxt_up_s_f_g ctor_cxt_up_s_f_g;
xrt_bo_ctor_cxt_up_s_g ctor_cxt_up_s_g;
xrt_bo_ctor_cxt_s_f_g ctor_cxt_s_f_g;
Expand Down
Loading

0 comments on commit 4cf22ce

Please sign in to comment.