Skip to content

Commit 5ab25a9

Browse files
committed
Creating shim io test support for npu3 full elf flow
Signed-off-by: Hayden Laccabue <hlaccabu@amd.com>
1 parent 229f11b commit 5ab25a9

File tree

9 files changed

+256
-33
lines changed

9 files changed

+256
-33
lines changed

src/shim/buffer.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ uint8_t
2121
use_to_fw_debug_type(uint8_t use)
2222
{
2323
switch (use) {
24-
case XRT_BO_USE_DEBUG:
25-
return AMDXDNA_FW_BUF_DEBUG;
24+
case XRT_BO_USE_DEBUG: // USE_DEBUG and USE_UC_DEBUG should return same type, 2 different cases for different devices
2625
case XRT_BO_USE_UC_DEBUG:
2726
return AMDXDNA_FW_BUF_DEBUG;
2827
case XRT_BO_USE_DTRACE:

src/shim/hwq.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,23 @@ hwq::
9898
poll_command(xrt_core::buffer_handle *cmd) const
9999
{
100100
auto boh = static_cast<cmd_buffer*>(cmd);
101-
auto cmdpkt = reinterpret_cast<ert_packet *>(boh->vaddr());
102-
101+
auto& subcmds = boh->get_subcmd_list();
102+
// For chain commands in user mode
103+
if (subcmds.size()) {
104+
auto last_cmd_bo = subcmds.back();
105+
auto last_cmdpkt = reinterpret_cast<ert_packet *>(last_cmd_bo->vaddr());
106+
if (last_cmdpkt->state >= ERT_CMD_STATE_COMPLETED) {
107+
// Update chain BO state to match
108+
auto cmdpkt = reinterpret_cast<ert_packet *>(boh->vaddr());
109+
cmdpkt->state = last_cmdpkt->state;
110+
XRT_TRACE_POINT_LOG(poll_command_done);
111+
return 1;
112+
}
113+
return 0;
114+
}
115+
116+
// Single command
117+
auto cmdpkt = reinterpret_cast<volatile ert_packet *>(boh->vaddr());
103118
if (cmdpkt->state >= ERT_CMD_STATE_COMPLETED) {
104119
XRT_TRACE_POINT_LOG(poll_command_done);
105120
return 1;

test/shim_test/dev_info.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ xclbin_info xclbin_infos[] = {
6767
.device = npu3_device_id,
6868
.revision_id = npu_any_revision_id,
6969
.ip_name2idx = {
70-
{ "DPU:vadd", {0xffffffff} },
70+
{ "DPU:dpu", {0xffffffff} },
7171
},
7272
.workspace = "local_shim_test_data/elf_vadd_npu3",
7373
.data = "",
@@ -78,7 +78,7 @@ xclbin_info xclbin_infos[] = {
7878
.device = npu3_device_id,
7979
.revision_id = npu_any_revision_id,
8080
.ip_name2idx = {
81-
{ "DPU:nop", {0xffffffff} },
81+
{ "DPU:dpu", {0xffffffff} },
8282
},
8383
.workspace = "local_shim_test_data/elf_no_op_npu3",
8484
.data = "",
@@ -89,7 +89,7 @@ xclbin_info xclbin_infos[] = {
8989
.device = npu3_device_id1,
9090
.revision_id = npu_any_revision_id,
9191
.ip_name2idx = {
92-
{ "DPU:vadd", {0xffffffff} },
92+
{ "DPU:dpu", {0xffffffff} },
9393
},
9494
.workspace = "local_shim_test_data/elf_vadd_npu3",
9595
.data = "",
@@ -100,7 +100,7 @@ xclbin_info xclbin_infos[] = {
100100
.device = npu3_device_id1,
101101
.revision_id = npu_any_revision_id,
102102
.ip_name2idx = {
103-
{ "DPU:nop", {0xffffffff} },
103+
{ "DPU:dpu", {0xffffffff} },
104104
},
105105
.workspace = "local_shim_test_data/elf_no_op_npu3",
106106
.data = "",

test/shim_test/dev_info.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ enum kernel_type {
1313
KERNEL_TYPE_DPU_SEQ = 0,
1414
KERNEL_TYPE_TXN,
1515
KERNEL_TYPE_TXN_PREEMPT,
16+
KERNEL_TYPE_TXN_FULL_ELF,
1617
KERNEL_TYPE_TXN_FULL_ELF_PREEMPT,
1718
};
1819

test/shim_test/hwctx.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ class hw_ctx {
3434
{
3535
xrt::xclbin xclbin;
3636
xrt::elf elf;
37-
auto is_full_elf = (get_kernel_type(dev, xclbin_name) == KERNEL_TYPE_TXN_FULL_ELF_PREEMPT);
37+
auto kernel_type = get_kernel_type(dev, xclbin_name);
38+
auto is_full_elf = (kernel_type == KERNEL_TYPE_TXN_FULL_ELF_PREEMPT ||
39+
kernel_type == KERNEL_TYPE_TXN_FULL_ELF);
3840
auto path = get_xclbin_path(dev, xclbin_name);
3941

4042
try {

test/shim_test/io.cpp

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,47 @@ elf_io_test_bo_set(device* dev, const std::string& xclbin_name) :
384384
}
385385
}
386386

387+
elf_full_io_test_bo_set::
388+
elf_full_io_test_bo_set(device* dev, const std::string& xclbin_name)
389+
: io_test_bo_set_base(dev, xclbin_name)
390+
{
391+
auto elf_path = get_xclbin_path(dev, xclbin_name.c_str());
392+
m_elf = xrt::elf(elf_path);
393+
auto mod = xrt::module{m_elf};
394+
auto kernel_name = get_kernel_name(dev, xclbin_name.c_str());
395+
396+
try {
397+
m_kernel_index = module_int::get_ctrlcode_id(mod, kernel_name);
398+
} catch (const std::exception& e) {
399+
m_kernel_index = module_int::no_ctrl_code_id;
400+
}
401+
402+
for (int i = 0; i < IO_TEST_BO_MAX_TYPES; i++) {
403+
auto& ibo = m_bo_array[i];
404+
auto type = static_cast<io_test_bo_type>(i);
405+
406+
switch(type) {
407+
case IO_TEST_BO_CMD:
408+
alloc_cmd_bo(ibo, m_dev);
409+
break;
410+
case IO_TEST_BO_INSTRUCTION:
411+
create_ctrl_bo_from_elf(ibo, patcher::buf_type::ctrltext);
412+
break;
413+
case IO_TEST_BO_INPUT:
414+
create_data_bo_from_file(ibo, "ifm.bin", m_FLAG_OPT);
415+
break;
416+
case IO_TEST_BO_PARAMETERS:
417+
create_data_bo_from_file(ibo, "wts.bin", m_FLAG_OPT);
418+
break;
419+
case IO_TEST_BO_OUTPUT:
420+
create_data_bo_from_file(ibo, "ofm.bin", m_FLAG_NO_FILL|m_FLAG_OPT);
421+
break;
422+
default:
423+
break;
424+
}
425+
}
426+
}
427+
387428
elf_preempt_io_test_bo_set::
388429
elf_preempt_io_test_bo_set(device* dev, const std::string& xclbin_name)
389430
: io_test_bo_set_base(dev, xclbin_name)
@@ -605,6 +646,30 @@ init_cmd(hw_ctx& hwctx, bool dump)
605646
patcher::buf_type::ctrltext, m_elf, module_int::no_ctrl_code_id);
606647
}
607648

649+
void
650+
elf_full_io_test_bo_set::
651+
init_cmd(hw_ctx& hwctx, bool dump)
652+
{
653+
exec_buf ebuf(*m_bo_array[IO_TEST_BO_CMD].tbo.get(), ERT_START_DPU);
654+
655+
xrt_core::cuidx_type cu_idx{0};
656+
ebuf.set_cu_idx(cu_idx);
657+
658+
if (m_bo_array[IO_TEST_BO_INPUT].tbo.get()) {
659+
ebuf.add_arg_64(3);
660+
ebuf.add_arg_bo(*m_bo_array[IO_TEST_BO_INPUT].tbo.get(), "0");
661+
ebuf.add_arg_bo(*m_bo_array[IO_TEST_BO_PARAMETERS].tbo.get(), "1");
662+
ebuf.add_arg_bo(*m_bo_array[IO_TEST_BO_OUTPUT].tbo.get(), "2");
663+
}
664+
665+
if (dump)
666+
ebuf.dump();
667+
668+
ebuf.add_ctrl_bo(*m_bo_array[IO_TEST_BO_INSTRUCTION].tbo.get());
669+
ebuf.patch_ctrl_code(*m_bo_array[IO_TEST_BO_INSTRUCTION].tbo.get(),
670+
patcher::buf_type::ctrltext, m_elf, m_kernel_index);
671+
}
672+
608673
void
609674
elf_preempt_io_test_bo_set::
610675
init_cmd(hw_ctx& hwctx, bool dump)
@@ -883,6 +948,32 @@ get_preemption_checkpoints()
883948
return 0;
884949
}
885950

951+
void
952+
io_test_bo_set_base::
953+
cache_cmd_header()
954+
{
955+
auto cbo = m_bo_array[IO_TEST_BO_CMD].tbo.get();
956+
if (!cbo)
957+
return;
958+
auto pkt = reinterpret_cast<ert_packet *>(cbo->map());
959+
if (!m_cached_cmd_header)
960+
m_cached_cmd_header = pkt->header;
961+
}
962+
963+
void
964+
io_test_bo_set_base::
965+
restore_cmd_header()
966+
{
967+
auto cbo = m_bo_array[IO_TEST_BO_CMD].tbo.get();
968+
if (!cbo || !m_cached_cmd_header)
969+
return;
970+
971+
auto pkt = reinterpret_cast<ert_packet *>(cbo->map());
972+
pkt->header = m_cached_cmd_header;
973+
pkt->state = ERT_CMD_STATE_NEW;
974+
std::atomic_thread_fence(std::memory_order_seq_cst);
975+
}
976+
886977
unsigned long
887978
elf_preempt_io_test_bo_set::
888979
get_preemption_checkpoints()

test/shim_test/io.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ class io_test_bo_set_base
7070
virtual void
7171
verify_result();
7272

73+
void
74+
cache_cmd_header();
75+
76+
void
77+
restore_cmd_header();
78+
7379
static const char *
7480
bo_type2name(int type);
7581

@@ -90,6 +96,7 @@ class io_test_bo_set_base
9096
const int m_FLAG_OPT = 1 << 1;
9197
const int m_FLAG_NO_FILL = 1 << 2;
9298
const int m_FLAG_DEV_BUF = 1 << 3;
99+
uint32_t m_cached_cmd_header = 0;
93100

94101
void
95102
create_data_bo_from_file(io_test_bo& ibo, const std::string filename, int flags);
@@ -124,6 +131,15 @@ class elf_io_test_bo_set : public io_test_bo_set_base
124131
init_cmd(hw_ctx& hwctx, bool dump) override;
125132
};
126133

134+
class elf_full_io_test_bo_set : public io_test_bo_set_base
135+
{
136+
public:
137+
elf_full_io_test_bo_set(device *dev, const std::string& xclbin_name);
138+
139+
void
140+
init_cmd(hw_ctx& hwctx, bool dump) override;
141+
};
142+
127143
class elf_preempt_io_test_bo_set : public io_test_bo_set_base
128144
{
129145
public:

0 commit comments

Comments
 (0)