Skip to content

Commit 20ed205

Browse files
committed
Add header caching to shim_test code to match xrt::run
Signed-off-by: Hayden Laccabue <[email protected]>
1 parent 3062aaa commit 20ed205

File tree

7 files changed

+170
-173
lines changed

7 files changed

+170
-173
lines changed

test/shim_test/bo_import_export.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class test_2proc_export_import_bo : public test_2proc
4040
auto sdev = get_userpf_device(get_dev_id());
4141
auto dev = sdev.get();
4242

43+
io_test_bo_set_base::clear_cmd_header_cache();
4344
io_test_bo_set boset{dev};
4445
boset.get_bos()[IO_TEST_BO_INPUT].tbo = std::make_shared<bo>(dev, idata.pid, idata.hdl);
4546
boset.run();
@@ -77,6 +78,7 @@ TEST_export_import_bo(device::id_type id, std::shared_ptr<device>& sdev, const s
7778
void
7879
TEST_export_import_bo_single_proc(device::id_type id, std::shared_ptr<device>& sdev, const std::vector<uint64_t>& arg)
7980
{
81+
io_test_bo_set_base::clear_cmd_header_cache();
8082
auto dev = sdev.get();
8183

8284
// Create IO test BO set and share input BO with same process

test/shim_test/cmd_fence.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ TEST_cmd_fence_device(device::id_type id, std::shared_ptr<device>& sdev, arg_typ
167167
// Can't fork with opened device.
168168
sdev.reset();
169169

170+
io_test_bo_set_base::clear_cmd_header_cache();
170171
test_2proc_cmd_fence_device t2p(id);
171172
t2p.run_test();
172173
}

test/shim_test/dev_info.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ xclbin_info xclbin_infos[] = {
7474
.type = KERNEL_TYPE_TXN_FULL_ELF,
7575
},
7676
{
77-
.name = "nop.xclbin",
77+
.name = "nop.elf",
7878
.device = npu3_device_id,
7979
.revision_id = npu_any_revision_id,
8080
.ip_name2idx = {
@@ -96,7 +96,7 @@ xclbin_info xclbin_infos[] = {
9696
.type = KERNEL_TYPE_TXN_FULL_ELF,
9797
},
9898
{
99-
.name = "nop.xclbin",
99+
.name = "nop.elf",
100100
.device = npu3_device_id1,
101101
.revision_id = npu_any_revision_id,
102102
.ip_name2idx = {

test/shim_test/io.cpp

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,33 @@ elf_init_no_arg_cmd(xrt::elf& elf, cuidx_type idx, bool dump, bo& cmd, bo& inst)
224224

225225
} // namespace
226226

227+
std::map<uint32_t, uint32_t> io_test_bo_set_base::s_cmd_header_cache;
228+
229+
void
230+
io_test_bo_set_base::
231+
cache_cmd_header(const buffer_handle *cmd_hdl, const ert_start_kernel_cmd *cmd)
232+
{
233+
auto handle = cmd_hdl->get_properties().kmhdl;
234+
s_cmd_header_cache.try_emplace(handle, cmd->header);
235+
}
236+
237+
void
238+
io_test_bo_set_base::
239+
restore_cmd_header(const buffer_handle *cmd_hdl, ert_start_kernel_cmd *cmd)
240+
{
241+
auto handle = cmd_hdl->get_properties().kmhdl;
242+
auto it = s_cmd_header_cache.find(handle);
243+
if (it != s_cmd_header_cache.end())
244+
cmd->header = it->second;
245+
}
246+
247+
void
248+
io_test_bo_set_base::
249+
clear_cmd_header_cache()
250+
{
251+
s_cmd_header_cache.clear();
252+
}
253+
227254
io_test_bo_set_base::
228255
io_test_bo_set_base(device* dev, const std::string& xclbin_name) :
229256
m_bo_array{}
@@ -904,6 +931,11 @@ run(const std::vector<fence_handle*>& wait_fences,
904931

905932
auto cbo = m_bo_array[IO_TEST_BO_CMD].tbo.get();
906933
auto chdl = cbo->get();
934+
auto cpkt = reinterpret_cast<ert_start_kernel_cmd *>(cbo->map());
935+
936+
restore_cmd_header(chdl, cpkt);
937+
cache_cmd_header(chdl, cpkt);
938+
907939
for (const auto& fence : wait_fences)
908940
hwq->submit_wait(fence);
909941
hwq->submit_command(chdl);
@@ -948,32 +980,6 @@ get_preemption_checkpoints()
948980
return 0;
949981
}
950982

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-
977983
unsigned long
978984
elf_preempt_io_test_bo_set::
979985
get_preemption_checkpoints()

test/shim_test/io.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,18 @@ 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-
7973
static const char *
8074
bo_type2name(int type);
8175

76+
static void
77+
cache_cmd_header(const xrt_core::buffer_handle *cmd_hdl, const ert_start_kernel_cmd *cmd);
78+
79+
static void
80+
restore_cmd_header(const xrt_core::buffer_handle *cmd_hdl, ert_start_kernel_cmd *cmd);
81+
82+
static void
83+
clear_cmd_header_cache();
84+
8285
std::array<io_test_bo, IO_TEST_BO_MAX_TYPES>&
8386
get_bos();
8487

@@ -96,7 +99,7 @@ class io_test_bo_set_base
9699
const int m_FLAG_OPT = 1 << 1;
97100
const int m_FLAG_NO_FILL = 1 << 2;
98101
const int m_FLAG_DEV_BUF = 1 << 3;
99-
uint32_t m_cached_cmd_header = 0;
102+
static std::map<uint32_t, uint32_t> s_cmd_header_cache;
100103

101104
void
102105
create_data_bo_from_file(io_test_bo& ibo, const std::string filename, int flags);
@@ -206,4 +209,4 @@ class elf_io_gemm_test_bo_set : public io_test_bo_set_base
206209
std::unique_ptr<xrt_core::buffer_handle> m_dbo;
207210
};
208211

209-
#endif // _SHIMTEST_IO_H_
212+
#endif // _SHIMTEST_IO_H_

0 commit comments

Comments
 (0)