diff --git a/src/runtime_src/core/tools/xbreplay/CMakeLists.txt b/src/runtime_src/core/tools/xbreplay/CMakeLists.txt index a793c71625..483f61aa1c 100755 --- a/src/runtime_src/core/tools/xbreplay/CMakeLists.txt +++ b/src/runtime_src/core/tools/xbreplay/CMakeLists.txt @@ -22,6 +22,7 @@ add_library(xbreplay_objects OBJECT src/replay_xrt/replay_xrt_kernel.cpp src/replay_xrt/replay_xrt_run.cpp src/replay_xrt/replay_xrt_xclbin.cpp + src/replay_xrt/replay_xrt_runlist.cpp ) target_include_directories(xbreplay_objects PRIVATE diff --git a/src/runtime_src/core/tools/xbreplay/src/replay_xrt/replay_xrt.hpp b/src/runtime_src/core/tools/xbreplay/src/replay_xrt/replay_xrt.hpp index a488eb7d11..6b376e23dc 100755 --- a/src/runtime_src/core/tools/xbreplay/src/replay_xrt/replay_xrt.hpp +++ b/src/runtime_src/core/tools/xbreplay/src/replay_xrt/replay_xrt.hpp @@ -6,6 +6,7 @@ #include "experimental/xrt_device.h" #include "experimental/xrt_xclbin.h" #include "experimental/xrt_ext.h" +#include "experimental/xrt_kernel.h" #include "xrt/xrt_kernel.h" #include "xrt.h" #include "xclbin.h" @@ -61,6 +62,9 @@ class replay_xrt /*Map between handle from log and bo */ std::unordered_map> m_xclbin_hndle_map; + /*Map between handle from log and runlist */ + std::unordered_map> m_runlist_hndle_map; + /*Map between group id */ std::unordered_map m_kernel_grp_id; @@ -87,6 +91,9 @@ class replay_xrt /*Register hw_ctx class API's*/ void register_hwctxt_class_func(); + /* Registers runlist class API's */ + void register_runlist_class_func(); + /* Validate's file path */ bool is_file_exist(const std::string& fileName) { @@ -124,6 +131,9 @@ class replay_xrt /* Register HW CTX Class APIs*/ register_hwctxt_class_func(); + + /*Register Runlist class API's */ + register_runlist_class_func(); } /* @@ -159,6 +169,7 @@ class replay_xrt m_xclbin_hndle_map.clear(); m_hwctx_hndle_map.clear(); m_device_hndle_map.clear(); + m_runlist_hndle_map.clear(); } /* diff --git a/src/runtime_src/core/tools/xbreplay/src/replay_xrt/replay_xrt_runlist.cpp b/src/runtime_src/core/tools/xbreplay/src/replay_xrt/replay_xrt_runlist.cpp new file mode 100644 index 0000000000..0079bfb3ba --- /dev/null +++ b/src/runtime_src/core/tools/xbreplay/src/replay_xrt/replay_xrt_runlist.cpp @@ -0,0 +1,87 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved. + +#include "replay_xrt.hpp" + +namespace xrt_core::tools::xbreplay { + +/** + * 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 + * corresponding member of the xrt::runlist class. + */ +void replay_xrt::register_runlist_class_func() +{ + m_api_map["xrt::runlist::runlist(const xrt::hw_context&)"] = + [this] (std::shared_ptr msg) + { + const std::vector>& args = msg->m_args; + auto hwctx_handle = std::stoull(args[0].second, nullptr, utils::base_hex); + auto phwctx = m_hwctx_hndle_map[hwctx_handle]; + + if (phwctx) + { + const xrt::hw_context& hwctx = *phwctx; + auto runlist_ptr = std::make_shared(hwctx); + m_runlist_hndle_map[msg->m_ret_val] = runlist_ptr; + } + else + throw std::runtime_error("Failed to get hardware context handle"); + }; + + m_api_map["xrt::runlist::add(const xrt::run&)"] = + [this] (std::shared_ptr msg) + { + const std::vector>& args = msg->m_args; + auto runlist_handle = std::stoull(args[0].second, nullptr, utils::base_hex); + auto run_handle = std::stoull(args[1].second, nullptr, utils::base_hex); + + auto runlist_ptr = m_runlist_hndle_map[runlist_handle]; + auto run_ptr = m_run_hndle_map[run_handle]; + + if (runlist_ptr && run_ptr) + { + const xrt::run& run = *run_ptr; + runlist_ptr->add(run); + } + else + throw std::runtime_error("Failed to get runlist or run handle"); + }; + + m_api_map["xrt::runlist::execute()"] = + [this] (std::shared_ptr msg) + { + auto runlist_ptr = m_runlist_hndle_map[msg->m_handle]; + + if (runlist_ptr) + runlist_ptr->execute(); + else + throw std::runtime_error("Failed to get runlist handle"); + }; + + m_api_map["xrt::runlist::wait(const std::chrono::milliseconds&)"] = + [this] (std::shared_ptr msg) + { + const std::vector>& args = msg->m_args; + auto runlist_ptr = m_runlist_hndle_map[msg->m_handle]; + auto time = std::stoll(args[0].second); + const std::chrono::milliseconds timeout(time); + + if (runlist_ptr) + runlist_ptr->wait(timeout); + else + throw std::runtime_error("Failed to get runlist handle"); + }; + + m_api_map["xrt::runlist::reset()"] = + [this] (std::shared_ptr msg) + { + auto runlist_ptr = m_runlist_hndle_map[msg->m_handle]; + + if (runlist_ptr) + runlist_ptr->reset(); + else + throw std::runtime_error("Failed to get runlist handle"); + }; +} +} diff --git a/src/runtime_src/core/tools/xbtracer/src/lib/capture.cpp b/src/runtime_src/core/tools/xbtracer/src/lib/capture.cpp index afcff90825..67b7f6dc39 100644 --- a/src/runtime_src/core/tools/xbtracer/src/lib/capture.cpp +++ b/src/runtime_src/core/tools/xbtracer/src/lib/capture.cpp @@ -105,6 +105,13 @@ const static std::unordered_map < std::string, void **> fname2fptr_map = { {"xrt::run::set_arg_at_index(int, xrt::bo const&)", (void **) &dtbl.run.set_arg2}, {"xrt::run::update_arg_at_index(int, void const*, unsigned long)", (void **) &dtbl.run.update_arg3}, {"xrt::run::update_arg_at_index(int, xrt::bo const&)", (void **) &dtbl.run.update_arg2}, + + /* runlist class maps */ + {"xrt::runlist::runlist(xrt::hw_context const&)", (void **) &dtbl.runlist.ctor}, + {"xrt::runlist::add(xrt::run const&)", (void **) &dtbl.runlist.add}, + {"xrt::runlist::execute()", (void **) &dtbl.runlist.execute}, + {"xrt::runlist::wait(std::chrono::duration > const&) const", (void **) &dtbl.runlist.wait}, + {"xrt::runlist::reset()", (void **) &dtbl.runlist.reset}, /* kernel class maps */ {"xrt::kernel::kernel(xrt::device const&, xrt::uuid const&, std::string const&, xrt::kernel::cu_access_mode)", (void **) &dtbl.kernel.ctor}, diff --git a/src/runtime_src/core/tools/xbtracer/src/lib/capture.h b/src/runtime_src/core/tools/xbtracer/src/lib/capture.h index 8534d577e6..be1f393c5c 100644 --- a/src/runtime_src/core/tools/xbtracer/src/lib/capture.h +++ b/src/runtime_src/core/tools/xbtracer/src/lib/capture.h @@ -19,6 +19,7 @@ class xrt_ftbl xrt_bo_ftbl bo; xrt_kernel_ftbl kernel; xrt_run_ftbl run; + xrt_runlist_ftbl runlist; xrt_xclbin_ftbl xclbin; xrt_hw_context_ftbl hw_context; xrt_ext_ftbl ext; diff --git a/src/runtime_src/core/tools/xbtracer/src/lib/logger.cpp b/src/runtime_src/core/tools/xbtracer/src/lib/logger.cpp index b14ff53af3..7f0bd7fe02 100644 --- a/src/runtime_src/core/tools/xbtracer/src/lib/logger.cpp +++ b/src/runtime_src/core/tools/xbtracer/src/lib/logger.cpp @@ -174,6 +174,7 @@ void logger::synth_dtor_trace_fn() run |= check_ref_count(m_krnl_ref_tracker); run |= check_ref_count(m_bo_ref_tracker); run |= check_ref_count(m_hw_cnxt_ref_tracker); + run |= check_ref_count(m_runlist_ref_tracker); if (m_is_destructing == false) run = true; diff --git a/src/runtime_src/core/tools/xbtracer/src/lib/logger.h b/src/runtime_src/core/tools/xbtracer/src/lib/logger.h index bf68bea68a..fe01e19da3 100644 --- a/src/runtime_src/core/tools/xbtracer/src/lib/logger.h +++ b/src/runtime_src/core/tools/xbtracer/src/lib/logger.h @@ -19,6 +19,7 @@ #include "xrt/xrt_bo.h" #include "xrt/xrt_device.h" #include "xrt/xrt_kernel.h" +#include "experimental/xrt_kernel.h" #ifdef _WIN32 # include @@ -103,6 +104,8 @@ class logger std::string>> m_krnl_ref_tracker; std::vector, std::thread::id, std::string>> m_run_ref_tracker; + std::vector, std::thread::id, + std::string>> m_runlist_ref_tracker; std::vector, std::thread::id, std::string>> m_bo_ref_tracker; std::vector, std::thread::id, @@ -178,6 +181,12 @@ class logger std::this_thread::get_id(), "xrt::run::~run()")); } + void set_pimpl(std::shared_ptr hpimpl) + { + m_runlist_ref_tracker.emplace_back(std::make_tuple(hpimpl, + std::this_thread::get_id(), "xrt::runlist::~runlist()")); + } + void set_pimpl(std::shared_ptr hpimpl) { m_hw_cnxt_ref_tracker.emplace_back(std::make_tuple(hpimpl, diff --git a/src/runtime_src/core/tools/xbtracer/src/lib/xrt_kernel_inst.cpp b/src/runtime_src/core/tools/xbtracer/src/lib/xrt_kernel_inst.cpp index 31b0ccd5ac..339371eeb6 100755 --- a/src/runtime_src/core/tools/xbtracer/src/lib/xrt_kernel_inst.cpp +++ b/src/runtime_src/core/tools/xbtracer/src/lib/xrt_kernel_inst.cpp @@ -4,6 +4,7 @@ #include #define XCL_DRIVER_DLL_EXPORT +#define XRT_API_SOURCE #include "capture.h" #include "logger.h" @@ -13,7 +14,7 @@ namespace xtx = xrt::tools::xbtracer; const xtx::xrt_ftbl& dtbl = xtx::xrt_ftbl::get_instance(); /* - * kernel/run class instrumented methods + * kernel/run/runlist class instrumented methods * */ namespace xrt { XCL_DRIVER_DLLESPEC @@ -254,4 +255,52 @@ xrt::xclbin kernel::get_xclbin() const return xclbin; } +XRT_API_EXPORT +runlist::runlist(const xrt::hw_context& hwctx) +{ + auto func = "xrt::runlist::runlist(const xrt::hw_context&)"; + XRT_TOOLS_XBT_CALL_CTOR(dtbl.runlist.ctor, this, hwctx); + /* As pimpl will be updated only after ctor call */ + XRT_TOOLS_XBT_FUNC_ENTRY(func, hwctx.get_handle().get()); + XRT_TOOLS_XBT_FUNC_EXIT(func); +} + +XRT_API_EXPORT +void runlist::add(const xrt::run& run) +{ + auto func = "xrt::runlist::add(const xrt::run&)"; + XRT_TOOLS_XBT_FUNC_ENTRY(func, run.get_handle().get()); + XRT_TOOLS_XBT_CALL_METD(dtbl.runlist.add, run); + XRT_TOOLS_XBT_FUNC_EXIT(func); +} + +XRT_API_EXPORT +void runlist::execute() +{ + auto func = "xrt::runlist::execute()"; + XRT_TOOLS_XBT_FUNC_ENTRY(func, this); + XRT_TOOLS_XBT_CALL_METD(dtbl.runlist.execute); + XRT_TOOLS_XBT_FUNC_EXIT(func); +} + +XRT_API_EXPORT +std::cv_status runlist::wait(const std::chrono::milliseconds& timeout) const +{ + auto func = "xrt::runlist::wait(const std::chrono::milliseconds&)"; + XRT_TOOLS_XBT_FUNC_ENTRY(func, timeout.count()); + std::cv_status status = std::cv_status::no_timeout; + XRT_TOOLS_XBT_CALL_METD_RET(dtbl.runlist.wait, status, timeout); + XRT_TOOLS_XBT_FUNC_EXIT_RET(func, (int)status); + return status; +} + +XRT_API_EXPORT +void runlist::reset() +{ + auto func = "xrt::runlist::reset()"; + XRT_TOOLS_XBT_FUNC_ENTRY(func, this); + XRT_TOOLS_XBT_CALL_METD(dtbl.runlist.reset); + XRT_TOOLS_XBT_FUNC_EXIT(func); +} + } // namespace xrt diff --git a/src/runtime_src/core/tools/xbtracer/src/lib/xrt_kernel_inst.h b/src/runtime_src/core/tools/xbtracer/src/lib/xrt_kernel_inst.h index 7018c6407c..2f95f0e1a4 100755 --- a/src/runtime_src/core/tools/xbtracer/src/lib/xrt_kernel_inst.h +++ b/src/runtime_src/core/tools/xbtracer/src/lib/xrt_kernel_inst.h @@ -4,6 +4,7 @@ #pragma once #include "xrt/xrt_kernel.h" +#include "experimental/xrt_kernel.h" /* * Run class method aliases. @@ -63,7 +64,7 @@ using xrt_kernel_ctor = xrt::kernel* (*)(void*, const xrt::device&,\ const xrt::uuid&, const std::string&, xrt::kernel::cu_access_mode); using xrt_kernel_ctor2 = xrt::kernel* (*)(void*, const xrt::hw_context&,\ const std::string&); -/*TODO: Marked obselete - should be keep this ?*/ +/*TODO: Marked obselete - should we keep this ?*/ using xrt_kernel_ctor_obs = xrt::kernel* (*)(void* cxt, xclDeviceHandle,\ const xrt::uuid&, const std::string&, xrt::kernel::cu_access_mode); using xrt_kernel_group_id = int (xrt::kernel::*)(int) const; @@ -90,3 +91,25 @@ struct xrt_kernel_ftbl xrt_kernel_get_xclbin get_xclbin; xrt_kernel_dtor dtor; }; + +/* + * Runlist class method aliases. + */ +using xrt_runlist_ctor = xrt::runlist (*)(void*, const xrt::hw_context&); +using xrt_runlist_add = void (xrt::runlist::*)(const xrt::run&); +using xrt_runlist_execute = void (xrt::runlist::*)(void); +using xrt_runlist_wait = std::cv_status (xrt::runlist::*)\ + (const std::chrono::milliseconds&) const; +using xrt_runlist_reset = void (xrt::runlist::*)(void); + +/* + * struct xrt_runlist_ftbl definition. + */ +struct xrt_runlist_ftbl +{ + xrt_runlist_ctor ctor; + xrt_runlist_add add; + xrt_runlist_execute execute; + xrt_runlist_wait wait; + xrt_runlist_reset reset; +};