|
| 1 | +// SPDX-License-Identifier: Apache-2.0 |
| 2 | +// Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved. |
| 3 | + |
| 4 | +#include "replay_xrt.hpp" |
| 5 | + |
| 6 | +namespace xrt_core::tools::xbreplay { |
| 7 | + |
| 8 | +/** |
| 9 | + * Replay maintains a map where each member function of the XRT classes is associated |
| 10 | + * with a corresponding lambda function. This API adds a lambda function entry for each |
| 11 | + * corresponding member of the xrt::runlist class. |
| 12 | + */ |
| 13 | +void replay_xrt::register_runlist_class_func() |
| 14 | +{ |
| 15 | + m_api_map["xrt::runlist::runlist(const xrt::hw_context&)"] = |
| 16 | + [this] (std::shared_ptr<utils::message> msg) |
| 17 | + { |
| 18 | + const std::vector<std::pair<std::string, std::string>>& args = msg->m_args; |
| 19 | + auto hwctx_handle = std::stoull(args[0].second, nullptr, utils::base_hex); |
| 20 | + auto phwctx = m_hwctx_hndle_map[hwctx_handle]; |
| 21 | + |
| 22 | + if (phwctx) |
| 23 | + { |
| 24 | + const xrt::hw_context& hwctx = *phwctx; |
| 25 | + auto runlist_ptr = std::make_shared<xrt::runlist>(hwctx); |
| 26 | + m_runlist_hndle_map[msg->m_ret_val] = runlist_ptr; |
| 27 | + } |
| 28 | + else |
| 29 | + throw std::runtime_error("Failed to get hardware context handle"); |
| 30 | + }; |
| 31 | + |
| 32 | + m_api_map["xrt::runlist::add(const xrt::run&)"] = |
| 33 | + [this] (std::shared_ptr<utils::message> msg) |
| 34 | + { |
| 35 | + const std::vector<std::pair<std::string, std::string>>& args = msg->m_args; |
| 36 | + auto runlist_handle = std::stoull(args[0].second, nullptr, utils::base_hex); |
| 37 | + auto run_handle = std::stoull(args[1].second, nullptr, utils::base_hex); |
| 38 | + |
| 39 | + auto runlist_ptr = m_runlist_hndle_map[runlist_handle]; |
| 40 | + auto run_ptr = m_run_hndle_map[run_handle]; |
| 41 | + |
| 42 | + if (runlist_ptr && run_ptr) |
| 43 | + { |
| 44 | + const xrt::run& run = *run_ptr; |
| 45 | + runlist_ptr->add(run); |
| 46 | + } |
| 47 | + else |
| 48 | + throw std::runtime_error("Failed to get runlist or run handle"); |
| 49 | + }; |
| 50 | + |
| 51 | + m_api_map["xrt::runlist::execute()"] = |
| 52 | + [this] (std::shared_ptr<utils::message> msg) |
| 53 | + { |
| 54 | + auto runlist_ptr = m_runlist_hndle_map[msg->m_handle]; |
| 55 | + |
| 56 | + if (runlist_ptr) |
| 57 | + runlist_ptr->execute(); |
| 58 | + else |
| 59 | + throw std::runtime_error("Failed to get runlist handle"); |
| 60 | + }; |
| 61 | + |
| 62 | + m_api_map["xrt::runlist::wait(const std::chrono::milliseconds&)"] = |
| 63 | + [this] (std::shared_ptr<utils::message> msg) |
| 64 | + { |
| 65 | + const std::vector<std::pair<std::string, std::string>>& args = msg->m_args; |
| 66 | + auto runlist_ptr = m_runlist_hndle_map[msg->m_handle]; |
| 67 | + auto time = std::stoll(args[0].second); |
| 68 | + const std::chrono::milliseconds timeout(time); |
| 69 | + |
| 70 | + if (runlist_ptr) |
| 71 | + runlist_ptr->wait(timeout); |
| 72 | + else |
| 73 | + throw std::runtime_error("Failed to get runlist handle"); |
| 74 | + }; |
| 75 | + |
| 76 | + m_api_map["xrt::runlist::reset()"] = |
| 77 | + [this] (std::shared_ptr<utils::message> msg) |
| 78 | + { |
| 79 | + auto runlist_ptr = m_runlist_hndle_map[msg->m_handle]; |
| 80 | + |
| 81 | + if (runlist_ptr) |
| 82 | + runlist_ptr->reset(); |
| 83 | + else |
| 84 | + throw std::runtime_error("Failed to get runlist handle"); |
| 85 | + }; |
| 86 | +} |
| 87 | +} |
0 commit comments