From 6e61f5fb89828fc5ee5c45fb56e7738529fe2a66 Mon Sep 17 00:00:00 2001 From: rbramand Date: Fri, 1 Nov 2024 21:42:35 +0530 Subject: [PATCH] Fix failure Signed-off-by: rbramand --- .../core/common/api/xrt_kernel.cpp | 66 +++++++++---------- .../core/common/api/xrt_module.cpp | 18 +++-- .../core/include/experimental/xrt_module.h | 3 + 3 files changed, 48 insertions(+), 39 deletions(-) diff --git a/src/runtime_src/core/common/api/xrt_kernel.cpp b/src/runtime_src/core/common/api/xrt_kernel.cpp index 1705a6d47a..af61dd988a 100644 --- a/src/runtime_src/core/common/api/xrt_kernel.cpp +++ b/src/runtime_src/core/common/api/xrt_kernel.cpp @@ -1505,39 +1505,18 @@ class kernel_impl : public std::enable_shared_from_this return data; // no skipping } - xrt::module + static xrt::module get_module(const xrt::hw_context& ctx, const std::string& kname) { - // ELF use case, identify module from ctx that has given kernel name and - // get kernel signature from the module to construct kernel args etc + // ELF use case, identify module from ctx that has given kernel name // kernel name will be of format - : auto i = kname.find(":"); if (i == std::string::npos) { - // default case - ctrl code 0 will be used - name = kname.substr(0, kname.size()); - m_ctrl_code_index = 0; + // default case + return xrt_core::hw_context_int::get_module(ctx, kname.substr(0, kname.size())); } - else { - name = kname.substr(0, i); - m_ctrl_code_index = std::stoul(kname.substr(i+1, kname.size()-i-1)); - } - - return xrt_core::hw_context_int::get_module(ctx, name); - } - - const property_type& - get_elf_kernel_properties() - { - // Get kernel info from module - const auto& kernel_info = xrt_core::module_int::get_kernel_info(m_module); - if (name != kernel_info.props.name) - throw std::runtime_error("Kernel name mismatch, incorrect module picked\n"); - - // set kernel args - for (auto& arg : kernel_info.args) - args.emplace_back(arg); - - return kernel_info.props; + else + return xrt_core::hw_context_int::get_module(ctx, kname.substr(0, i)); } static uint32_t @@ -1616,15 +1595,31 @@ class kernel_impl : public std::enable_shared_from_this } kernel_impl(std::shared_ptr dev, xrt::hw_context ctx, const std::string& nm) - : device(std::move(dev)) // share ownership - , hwctx(std::move(ctx)) // hw context - , hwqueue(hwctx) // hw queue - , m_module(get_module(hwctx, nm)) // module object with matching kernel name - , properties(get_elf_kernel_properties()) // kernel info present in Elf + : device(std::move(dev)) // share ownership + , hwctx(std::move(ctx)) // hw context + , hwqueue(hwctx) // hw queue + , m_module(get_module(hwctx, nm)) // module object with matching kernel name + , properties(xrt_core::module_int::get_kernel_info(m_module).props) // kernel info present in Elf , uid(create_uid()) { XRT_DEBUGF("kernel_impl::kernel_impl(%d)\n", uid); + // initialize kernel name and ctrl code index + auto i = nm.find(":"); + if (i == std::string::npos) { + // default case - ctrl code 0 will be used + name = nm.substr(0, nm.size()); + m_ctrl_code_index = 0; + } + else { + name = nm.substr(0, i); + m_ctrl_code_index = std::stoul(nm.substr(i+1, nm.size()-i-1)); + } + + // initialize kernel args + for (auto& arg : xrt_core::module_int::get_kernel_info(m_module).args) + args.emplace_back(arg); + // amend args with computed data based on kernel protocol amend_args(); m_usage_logger->log_kernel_info(device->core_device.get(), hwctx, name, args.size()); @@ -1992,8 +1987,11 @@ class run_impl return count++; } - // This function copies the module into a hw_context. The module + // This function copies the module into a hw_context. The module // will be associated with hwctx specific memory. + // If module has multiple control codes, index is used to identify + // the control code that needs to be run. + // By default control code at zeroth index is picked static xrt::module copy_module(const xrt::module& module, const xrt::hw_context& hwctx, uint32_t ctrl_code_idx) { @@ -3489,7 +3487,7 @@ alloc_kernel(const std::shared_ptr& dev, xrt::kernel::cu_access_mode mode) { auto amode = hwctx_access_mode(mode); // legacy access mode to hwctx qos - return std::make_shared(dev, xrt::hw_context{dev->get_xrt_device(), xclbin_id, amode}, name); + return std::make_shared(dev, xrt::hw_context{dev->get_xrt_device(), xclbin_id, amode}, xrt::module{}, name); } static std::shared_ptr diff --git a/src/runtime_src/core/common/api/xrt_module.cpp b/src/runtime_src/core/common/api/xrt_module.cpp index 979da54fe2..c5221876e8 100644 --- a/src/runtime_src/core/common/api/xrt_module.cpp +++ b/src/runtime_src/core/common/api/xrt_module.cpp @@ -1055,6 +1055,12 @@ class module_elf_aie2p : public module_elf return std::make_pair(UINT32_MAX, control_packet::get_empty_buf()); } + [[nodiscard]] virtual size_t + get_scratch_pad_mem_size() const override + { + return m_scratch_pad_mem_size; + } + [[nodiscard]] std::pair get_preempt_save() const override { @@ -1377,8 +1383,9 @@ class module_sram : public module_impl create_instr_buf(const module_impl* parent) { XRT_DEBUGF("-> module_sram::create_instr_buf()\n"); - instr_buf data; - std::tie(m_instr_sec_idx, data) = parent->get_instr(m_index); + auto instr_buf_info = parent->get_instr(m_index); + m_instr_sec_idx = instr_buf_info.first; + const instr_buf& data = instr_buf_info.second; size_t sz = data.size(); if (sz == 0) throw std::runtime_error("Invalid instruction buffer size"); @@ -1461,8 +1468,9 @@ class module_sram : public module_impl void create_ctrlpkt_buf(const module_impl* parent) { - control_packet data; - std::tie(m_ctrlpkt_sec_idx, data) = parent->get_ctrlpkt(m_index); + auto ctrl_pkt_info = parent->get_ctrlpkt(m_index); + m_ctrlpkt_sec_idx = ctrl_pkt_info.first; + const control_packet& data = ctrl_pkt_info.second; size_t sz = data.size(); if (sz == 0) { @@ -1788,7 +1796,7 @@ patch(const xrt::module& module, uint8_t* ibuf, size_t* sz, const std::vectorget_os_abi(); if (os_abi == Elf_Amd_Aie2p || os_abi == Elf_Amd_Aie2p_config) { - const auto& buf_info = hdl->get_instr(idx); + auto buf_info = hdl->get_instr(idx); patch_index = buf_info.first; inst = &(buf_info.second); } diff --git a/src/runtime_src/core/include/experimental/xrt_module.h b/src/runtime_src/core/include/experimental/xrt_module.h index 4e22a36de6..369eda853e 100644 --- a/src/runtime_src/core/include/experimental/xrt_module.h +++ b/src/runtime_src/core/include/experimental/xrt_module.h @@ -90,6 +90,9 @@ class module : public detail::pimpl * * Copy content of existing module into an allocation associated * with the specified hardware context. + * If module has multiple control codes, index is used to identify + * the control code that needs to be run. + * By default control code at zeroth index is picked * * Throws if module is not compatible with hardware context */