Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/shim/buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ uint8_t
use_to_fw_debug_type(uint8_t use)
{
switch (use) {
case XRT_BO_USE_DEBUG:
case XRT_BO_USE_DEBUG: // USE_DEBUG and USE_UC_DEBUG should return same type, 2 different cases for different devices
case XRT_BO_USE_UC_DEBUG:
return AMDXDNA_FW_BUF_DEBUG;
case XRT_BO_USE_DTRACE:
return AMDXDNA_FW_BUF_TRACE;
Expand Down
19 changes: 17 additions & 2 deletions src/shim/hwq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,23 @@ hwq::
poll_command(xrt_core::buffer_handle *cmd) const
{
auto boh = static_cast<cmd_buffer*>(cmd);
auto cmdpkt = reinterpret_cast<ert_packet *>(boh->vaddr());

auto& subcmds = boh->get_subcmd_list();
// For chain commands in user mode
if (subcmds.size()) {
auto last_cmd_bo = subcmds.back();
auto last_cmdpkt = reinterpret_cast<ert_packet *>(last_cmd_bo->vaddr());
if (last_cmdpkt->state >= ERT_CMD_STATE_COMPLETED) {
// Update chain BO state to match
auto cmdpkt = reinterpret_cast<ert_packet *>(boh->vaddr());
cmdpkt->state = last_cmdpkt->state;
XRT_TRACE_POINT_LOG(poll_command_done);
return 1;
}
return 0;
}

Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blank line with only whitespace. Remove trailing whitespace for consistency with coding standards.

Suggested change

Copilot uses AI. Check for mistakes.
// Single command
auto cmdpkt = reinterpret_cast<volatile ert_packet *>(boh->vaddr());
if (cmdpkt->state >= ERT_CMD_STATE_COMPLETED) {
XRT_TRACE_POINT_LOG(poll_command_done);
return 1;
Expand Down
74 changes: 15 additions & 59 deletions test/shim_test/dev_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,88 +67,44 @@ xclbin_info xclbin_infos[] = {
.device = npu3_device_id,
.revision_id = npu_any_revision_id,
.ip_name2idx = {
{ "DPU:vadd", {0xffffffff} },
{ "DPU:dpu", {0xffffffff} },
},
.workspace = "npu3_workspace",
.workspace = "local_shim_test_data/elf_vadd_npu3",
.data = "",
.type = KERNEL_TYPE_TXN_FULL_ELF_PREEMPT,
},
{
.name = "vadd.elf",
.device = npu3_device_id1,
.revision_id = npu_any_revision_id,
.ip_name2idx = {
{ "DPU:vadd", {0xffffffff} },
},
.workspace = "npu3_workspace",
.data = "",
.type = KERNEL_TYPE_TXN_FULL_ELF_PREEMPT,
},
{
.name = "move_memtiles.elf",
.device = npu3_device_id,
.revision_id = npu_any_revision_id,
.ip_name2idx = {
{ "DPU:move_memtiles", {0xffffffff} },
},
.workspace = "npu3_workspace",
.data = "",
.type = KERNEL_TYPE_TXN_FULL_ELF_PREEMPT,
},
{
.name = "move_memtiles.elf",
.device = npu3_device_id1,
.revision_id = npu_any_revision_id,
.ip_name2idx = {
{ "DPU:move_memtiles", {0xffffffff} },
},
.workspace = "npu3_workspace",
.data = "",
.type = KERNEL_TYPE_TXN_FULL_ELF_PREEMPT,
.type = KERNEL_TYPE_TXN_FULL_ELF,
},
{
.name = "ddr_memtile.elf",
.name = "nop.elf",
.device = npu3_device_id,
.revision_id = npu_any_revision_id,
.ip_name2idx = {
{ "DPU:move_ddr_memtile", {0xffffffff} },
{ "DPU:dpu", {0xffffffff} },
},
.workspace = "npu3_workspace",
.workspace = "local_shim_test_data/elf_no_op_npu3",
.data = "",
.type = KERNEL_TYPE_TXN_FULL_ELF_PREEMPT,
.type = KERNEL_TYPE_TXN_FULL_ELF,
},
{
.name = "ddr_memtile.elf",
.name = "vadd.elf",
.device = npu3_device_id1,
.revision_id = npu_any_revision_id,
.ip_name2idx = {
{ "DPU:move_ddr_memtile", {0xffffffff} },
{ "DPU:dpu", {0xffffffff} },
},
.workspace = "npu3_workspace",
.workspace = "local_shim_test_data/elf_vadd_npu3",
.data = "",
.type = KERNEL_TYPE_TXN_FULL_ELF_PREEMPT,
.type = KERNEL_TYPE_TXN_FULL_ELF,
},
{
.name = "remote_barrier.elf",
.device = npu3_device_id,
.revision_id = npu_any_revision_id,
.ip_name2idx = {
{ "DPU:remote_barrier", {0xffffffff} },
},
.workspace = "npu3_workspace",
.data = "",
.type = KERNEL_TYPE_TXN_FULL_ELF_PREEMPT,
},
{
.name = "remote_barrier.elf",
.name = "nop.elf",
.device = npu3_device_id1,
.revision_id = npu_any_revision_id,
.ip_name2idx = {
{ "DPU:remote_barrier", {0xffffffff} },
{ "DPU:dpu", {0xffffffff} },
},
.workspace = "npu3_workspace",
.workspace = "local_shim_test_data/elf_no_op_npu3",
.data = "",
.type = KERNEL_TYPE_TXN_FULL_ELF_PREEMPT,
.type = KERNEL_TYPE_TXN_FULL_ELF,
},
{
.name = "1x4.xclbin",
Expand Down
1 change: 1 addition & 0 deletions test/shim_test/dev_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ enum kernel_type {
KERNEL_TYPE_DPU_SEQ = 0,
KERNEL_TYPE_TXN,
KERNEL_TYPE_TXN_PREEMPT,
KERNEL_TYPE_TXN_FULL_ELF,
KERNEL_TYPE_TXN_FULL_ELF_PREEMPT,
};

Expand Down
4 changes: 3 additions & 1 deletion test/shim_test/hwctx.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ class hw_ctx {
{
xrt::xclbin xclbin;
xrt::elf elf;
auto is_full_elf = (get_kernel_type(dev, xclbin_name) == KERNEL_TYPE_TXN_FULL_ELF_PREEMPT);
auto kernel_type = get_kernel_type(dev, xclbin_name);
auto is_full_elf = (kernel_type == KERNEL_TYPE_TXN_FULL_ELF_PREEMPT ||
kernel_type == KERNEL_TYPE_TXN_FULL_ELF);
auto path = get_xclbin_path(dev, xclbin_name);

try {
Expand Down
85 changes: 85 additions & 0 deletions test/shim_test/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,21 @@ elf_init_no_arg_cmd(xrt::elf& elf, cuidx_type idx, bool dump, bo& cmd, bo& inst)

} // namespace

void
io_test_bo_set_base::
cache_cmd_header(const buffer_handle *cmd_hdl, const ert_start_kernel_cmd *cmd)
{
m_cached_header = cmd->header;
}

void
io_test_bo_set_base::
restore_cmd_header(const buffer_handle *cmd_hdl, ert_start_kernel_cmd *cmd)
{
if (m_cached_header != 0)
cmd->header = m_cached_header;
}

io_test_bo_set_base::
io_test_bo_set_base(device* dev, const std::string& xclbin_name) :
m_bo_array{}
Expand Down Expand Up @@ -384,6 +399,47 @@ elf_io_test_bo_set(device* dev, const std::string& xclbin_name) :
}
}

elf_full_io_test_bo_set::
elf_full_io_test_bo_set(device* dev, const std::string& xclbin_name)
: io_test_bo_set_base(dev, xclbin_name)
{
auto elf_path = get_xclbin_path(dev, xclbin_name.c_str());
m_elf = xrt::elf(elf_path);
auto mod = xrt::module{m_elf};
auto kernel_name = get_kernel_name(dev, xclbin_name.c_str());

try {
m_kernel_index = module_int::get_ctrlcode_id(mod, kernel_name);
} catch (const std::exception& e) {
m_kernel_index = module_int::no_ctrl_code_id;
}

for (int i = 0; i < IO_TEST_BO_MAX_TYPES; i++) {
auto& ibo = m_bo_array[i];
auto type = static_cast<io_test_bo_type>(i);

switch(type) {
case IO_TEST_BO_CMD:
alloc_cmd_bo(ibo, m_dev);
break;
case IO_TEST_BO_INSTRUCTION:
create_ctrl_bo_from_elf(ibo, patcher::buf_type::ctrltext);
break;
case IO_TEST_BO_INPUT:
create_data_bo_from_file(ibo, "ifm.bin", m_FLAG_OPT);
break;
case IO_TEST_BO_PARAMETERS:
create_data_bo_from_file(ibo, "wts.bin", m_FLAG_OPT);
break;
case IO_TEST_BO_OUTPUT:
create_data_bo_from_file(ibo, "ofm.bin", m_FLAG_NO_FILL|m_FLAG_OPT);
break;
default:
break;
}
}
}

elf_preempt_io_test_bo_set::
elf_preempt_io_test_bo_set(device* dev, const std::string& xclbin_name)
: io_test_bo_set_base(dev, xclbin_name)
Expand Down Expand Up @@ -605,6 +661,30 @@ init_cmd(hw_ctx& hwctx, bool dump)
patcher::buf_type::ctrltext, m_elf, module_int::no_ctrl_code_id);
}

void
elf_full_io_test_bo_set::
init_cmd(hw_ctx& hwctx, bool dump)
{
exec_buf ebuf(*m_bo_array[IO_TEST_BO_CMD].tbo.get(), ERT_START_DPU);

xrt_core::cuidx_type cu_idx{0};
ebuf.set_cu_idx(cu_idx);

if (m_bo_array[IO_TEST_BO_INPUT].tbo.get()) {
ebuf.add_arg_64(3);
ebuf.add_arg_bo(*m_bo_array[IO_TEST_BO_INPUT].tbo.get(), "0");
ebuf.add_arg_bo(*m_bo_array[IO_TEST_BO_PARAMETERS].tbo.get(), "1");
ebuf.add_arg_bo(*m_bo_array[IO_TEST_BO_OUTPUT].tbo.get(), "2");
}

if (dump)
ebuf.dump();

ebuf.add_ctrl_bo(*m_bo_array[IO_TEST_BO_INSTRUCTION].tbo.get());
ebuf.patch_ctrl_code(*m_bo_array[IO_TEST_BO_INSTRUCTION].tbo.get(),
patcher::buf_type::ctrltext, m_elf, m_kernel_index);
}

void
elf_preempt_io_test_bo_set::
init_cmd(hw_ctx& hwctx, bool dump)
Expand Down Expand Up @@ -839,6 +919,11 @@ run(const std::vector<fence_handle*>& wait_fences,

auto cbo = m_bo_array[IO_TEST_BO_CMD].tbo.get();
auto chdl = cbo->get();
auto cpkt = reinterpret_cast<ert_start_kernel_cmd *>(cbo->map());

Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blank line with only whitespace. Remove trailing whitespace for consistency with coding standards.

Suggested change

Copilot uses AI. Check for mistakes.
restore_cmd_header(chdl, cpkt);
cache_cmd_header(chdl, cpkt);

for (const auto& fence : wait_fences)
hwq->submit_wait(fence);
hwq->submit_command(chdl);
Expand Down
18 changes: 17 additions & 1 deletion test/shim_test/io.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ class io_test_bo_set_base
static const char *
bo_type2name(int type);

void
cache_cmd_header(const xrt_core::buffer_handle *cmd_hdl, const ert_start_kernel_cmd *cmd);

void
restore_cmd_header(const xrt_core::buffer_handle *cmd_hdl, ert_start_kernel_cmd *cmd);

std::array<io_test_bo, IO_TEST_BO_MAX_TYPES>&
get_bos();

Expand All @@ -86,6 +92,7 @@ class io_test_bo_set_base
device *m_dev;
xrt::elf m_elf = {};
uint32_t m_kernel_index;
uint32_t m_cached_header = 0;
const int m_FLAG_USR_BUF = 1 << 0;
const int m_FLAG_OPT = 1 << 1;
const int m_FLAG_NO_FILL = 1 << 2;
Expand Down Expand Up @@ -124,6 +131,15 @@ class elf_io_test_bo_set : public io_test_bo_set_base
init_cmd(hw_ctx& hwctx, bool dump) override;
};

class elf_full_io_test_bo_set : public io_test_bo_set_base
{
public:
elf_full_io_test_bo_set(device *dev, const std::string& xclbin_name);

void
init_cmd(hw_ctx& hwctx, bool dump) override;
};

class elf_preempt_io_test_bo_set : public io_test_bo_set_base
{
public:
Expand Down Expand Up @@ -190,4 +206,4 @@ class elf_io_gemm_test_bo_set : public io_test_bo_set_base
std::unique_ptr<xrt_core::buffer_handle> m_dbo;
};

#endif // _SHIMTEST_IO_H_
#endif // _SHIMTEST_IO_H_
Loading