Skip to content

Commit

Permalink
Fix failure
Browse files Browse the repository at this point in the history
Signed-off-by: rbramand <[email protected]>
  • Loading branch information
rbramand committed Nov 4, 2024
1 parent 5db3f1b commit ca47bb5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 38 deletions.
61 changes: 28 additions & 33 deletions src/runtime_src/core/common/api/xrt_kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1505,39 +1505,18 @@ class kernel_impl : public std::enable_shared_from_this<kernel_impl>
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 - <kernel_name>:<index>
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
Expand Down Expand Up @@ -1616,15 +1595,31 @@ class kernel_impl : public std::enable_shared_from_this<kernel_impl>
}

kernel_impl(std::shared_ptr<device_type> 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());
Expand Down Expand Up @@ -3489,7 +3484,7 @@ alloc_kernel(const std::shared_ptr<device_type>& dev,
xrt::kernel::cu_access_mode mode)
{
auto amode = hwctx_access_mode(mode); // legacy access mode to hwctx qos
return std::make_shared<xrt::kernel_impl>(dev, xrt::hw_context{dev->get_xrt_device(), xclbin_id, amode}, name);
return std::make_shared<xrt::kernel_impl>(dev, xrt::hw_context{dev->get_xrt_device(), xclbin_id, amode}, xrt::module{}, name);
}

static std::shared_ptr<xrt::kernel_impl>
Expand Down
12 changes: 7 additions & 5 deletions src/runtime_src/core/common/api/xrt_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1377,8 +1377,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");
Expand Down Expand Up @@ -1461,8 +1462,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) {
Expand Down Expand Up @@ -1788,7 +1790,7 @@ patch(const xrt::module& module, uint8_t* ibuf, size_t* sz, const std::vector<st
auto os_abi = hdl->get_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);
}
Expand Down

0 comments on commit ca47bb5

Please sign in to comment.