Skip to content

Temporal Sharing Overhead test ELF flow (mobilenet) #8866

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Apr 11, 2025
16 changes: 8 additions & 8 deletions src/runtime_src/core/common/query_requests.h
Original file line number Diff line number Diff line change
Expand Up @@ -601,9 +601,9 @@ struct xclbin_name : request
enum class type {
validate,
gemm,
mobilenet,
validate_elf,
gemm_elf,
mobilenet_elf,
preemption_4x4,
preemption_4x8
};
Expand All @@ -624,8 +624,8 @@ struct xclbin_name : request
return "preemption_4x4";
case type::preemption_4x8:
return "preemption_4x8";
case type::mobilenet:
return "mobilenet";
case type::mobilenet_elf:
return "mobilenet_elf";
}
return "unknown";
}
Expand All @@ -651,8 +651,7 @@ struct sequence_name : request
tct_one_column,
tct_all_column,
gemm_int8,
aie_reconfig_overhead,
mobilenet
aie_reconfig_overhead
};

static std::string
Expand All @@ -669,8 +668,6 @@ struct sequence_name : request
return "gemm_int8";
case type::aie_reconfig_overhead:
return "aie_reconfig_overhead";
case type::mobilenet:
return "mobilenet";
}
return "unknown";
}
Expand Down Expand Up @@ -701,7 +698,8 @@ struct elf_name : request
preemption_noop_4x4,
preemption_noop_4x8,
preemption_memtile_4x4,
preemption_memtile_4x8
preemption_memtile_4x8,
mobilenet
};

static std::string
Expand All @@ -728,6 +726,8 @@ struct elf_name : request
return "preemption_memtile_4x4";
case type::preemption_memtile_4x8:
return "preemption_memtile_4x8";
case type::mobilenet:
return "mobilenet";
}
return "unknown";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ boost::property_tree::ptree TestTemporalSharingOvd::run(std::shared_ptr<xrt_core
ptree.erase("xclbin");

// Query the xclbin name from the device
const auto xclbin_name = xrt_core::device_query<xrt_core::query::xclbin_name>(dev, xrt_core::query::xclbin_name::type::mobilenet);

const auto xclbin_name = xrt_core::device_query<xrt_core::query::xclbin_name>(dev, xrt_core::query::xclbin_name::type::mobilenet_elf);
// Find the platform file path for the xclbin
auto xclbin_path = XBValidateUtils::findPlatformFile(xclbin_name, ptree);

Expand All @@ -49,26 +48,7 @@ boost::property_tree::ptree TestTemporalSharingOvd::run(std::shared_ptr<xrt_core
}

// Determine The DPU Kernel Name
auto xkernels = xclbin.get_kernels();

// Find the first kernel whose name starts with "DPU"
auto itr = std::find_if(xkernels.begin(), xkernels.end(), [](xrt::xclbin::kernel& k) {
auto name = k.get_name();
return name.rfind("DPU",0) == 0; // Starts with "DPU"
});

xrt::xclbin::kernel xkernel;
if (itr != xkernels.end())
xkernel = *itr;
else {
// Log an error if no kernel with "DPU" is found and set the status to failed
XBValidateUtils::logger(ptree, "Error", "No kernel with `DPU` found in the xclbin");
ptree.put("status", XBValidateUtils::test_token_failed);
return ptree;
}

// Get the name of the found kernel
auto kernelName = xkernel.get_name();
auto kernelName = XBValidateUtils::get_kernel_name(xclbin, ptree);

// Create a working device from the provided device
auto working_dev = xrt::device(dev);
Expand All @@ -85,14 +65,12 @@ boost::property_tree::ptree TestTemporalSharingOvd::run(std::shared_ptr<xrt_core
}
};

const auto seq_name = xrt_core::device_query<xrt_core::query::sequence_name>(dev, xrt_core::query::sequence_name::type::mobilenet);
auto dpu_instr = XBValidateUtils::findPlatformFile(seq_name, ptree);
const auto elf_name = xrt_core::device_query<xrt_core::query::elf_name>(dev, xrt_core::query::elf_name::type::mobilenet);
auto elf_path = XBValidateUtils::findPlatformFile(elf_name, ptree);

if (!std::filesystem::exists(dpu_instr))
{
XBValidateUtils::logger(ptree, "Error", "Dpu instruction file not found");
if (!std::filesystem::exists(elf_path)) {
XBValidateUtils::logger(ptree, "Error", "ELF file not found");
ptree.put("status", XBValidateUtils::test_token_failed);
return ptree;
}

const auto ifm_name = xrt_core::device_query<xrt_core::query::mobilenet>(dev, xrt_core::query::mobilenet::type::mobilenet_ifm);
Expand Down Expand Up @@ -123,7 +101,7 @@ boost::property_tree::ptree TestTemporalSharingOvd::run(std::shared_ptr<xrt_core
std::vector<TestCase> testcases;

// Create two test cases and add them to the vector
TestParams params(xclbin, working_dev, kernelName, dpu_instr, ifm_file, param_file, buffer_sizes_file, 1, num_kernel_iterations);
TestParams params(xclbin, working_dev, kernelName, elf_path, ifm_file, param_file, buffer_sizes_file, 1, num_kernel_iterations);
testcases.emplace_back(params);
testcases.emplace_back(params);

Expand Down
41 changes: 18 additions & 23 deletions src/runtime_src/core/tools/common/tests/TestValidateUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "core/common/module_loader.h"
#include "tools/common/XBUtilities.h"
#include "tools/common/XBUtilitiesCore.h"
#include "xrt/experimental/xrt_ext.h"

#include "TestValidateUtilities.h"
namespace xq = xrt_core::query;
Expand All @@ -23,27 +24,22 @@ namespace xq = xrt_core::query;
// - device: Reference to the xrt::device object
// - kernel: Reference to the xrt::kernel object
BO_set::BO_set(const xrt::device& device,
const xrt::kernel& kernel,
const BufferSizes& buffer_sizes,
const std::string& dpu_instr,
const std::string& ifm_file,
const std::string& param_file)
: buffer_sizes(buffer_sizes),
bo_ifm (device, buffer_sizes.ifm_size, XRT_BO_FLAGS_HOST_ONLY, kernel.group_id(1)),
bo_param (device, buffer_sizes.param_size, XRT_BO_FLAGS_HOST_ONLY, kernel.group_id(2)),
bo_ofm (device, buffer_sizes.ofm_size, XRT_BO_FLAGS_HOST_ONLY, kernel.group_id(3)),
bo_inter (device, buffer_sizes.inter_size, XRT_BO_FLAGS_HOST_ONLY, kernel.group_id(4)),
bo_instr (device, buffer_sizes.instr_size, XCL_BO_FLAGS_CACHEABLE, kernel.group_id(5)),
bo_mc (device, buffer_sizes.mc_size, XRT_BO_FLAGS_HOST_ONLY, kernel.group_id(7))
bo_ifm (xrt::ext::bo{device, buffer_sizes.ifm_size}),
bo_param (xrt::ext::bo{device, buffer_sizes.param_size}),
bo_ofm (xrt::ext::bo{device, buffer_sizes.ofm_size}),
bo_inter (xrt::ext::bo{device, buffer_sizes.inter_size}),
bo_mc (xrt::ext::bo{device, buffer_sizes.mc_size})
{
XBValidateUtils::init_buf_bin((int*)bo_ifm.map<int*>(), buffer_sizes.ifm_size, ifm_file);
XBValidateUtils::init_buf_bin((int*)bo_param.map<int*>(), buffer_sizes.param_size, param_file);
XBValidateUtils::init_buf_bin((int*)bo_instr.map<int*>(), buffer_sizes.instr_size, dpu_instr);
}

// Method to synchronize buffer objects to the device
void BO_set::sync_bos_to_device() {
bo_instr.sync(XCL_BO_SYNC_BO_TO_DEVICE);
bo_ifm.sync(XCL_BO_SYNC_BO_TO_DEVICE);
bo_param.sync(XCL_BO_SYNC_BO_TO_DEVICE);
bo_mc.sync(XCL_BO_SYNC_BO_TO_DEVICE);
Expand All @@ -53,14 +49,15 @@ void BO_set::sync_bos_to_device() {
// Parameters:
// - run: Reference to the xrt::run object
void BO_set::set_kernel_args(xrt::run& run) const {
uint64_t opcode = 1;
// to-do: replace with XBU::get_opcode() when dpu sequence flow is taken out
uint64_t opcode = 3;
run.set_arg(0, opcode);
run.set_arg(1, bo_ifm);
run.set_arg(2, bo_param);
run.set_arg(3, bo_ofm);
run.set_arg(4, bo_inter);
run.set_arg(5, bo_instr);
run.set_arg(6, bo_instr.size()/sizeof(int));
run.set_arg(1, 0);
run.set_arg(2, 0);
run.set_arg(3, bo_ifm);
run.set_arg(4, bo_param);
run.set_arg(5, bo_ofm);
run.set_arg(6, bo_inter);
run.set_arg(7, bo_mc);
}

Expand All @@ -71,9 +68,11 @@ TestCase::initialize()
// Initialize kernels, buffer objects, and runs
for (int j = 0; j < params.queue_len; j++) {
xrt::kernel kernel;
kernel = xrt::kernel(hw_ctx, params.kernel_name);
xrt::elf elf = xrt::elf(params.elf_file);
xrt::module mod{elf};
kernel = xrt::ext::kernel{hw_ctx, mod, params.kernel_name};
BufferSizes buffer_sizes = XBValidateUtils::read_buffer_sizes(params.buffer_sizes_file);
auto bos = BO_set(params.device, kernel, buffer_sizes, params.dpu_file, params.ifm_file, params.param_file);
auto bos = BO_set(params.device, buffer_sizes, params.ifm_file, params.param_file);
bos.sync_bos_to_device();
auto run = xrt::run(kernel);
bos.set_kernel_args(run);
Expand Down Expand Up @@ -118,10 +117,6 @@ read_buffer_sizes(const std::string& json_file) {
buffer_sizes.inter_size = root.get<size_t>("buffer_sizes.inter_size");
buffer_sizes.mc_size = root.get<size_t>("buffer_sizes.mc_size");
buffer_sizes.ofm_size = root.get<size_t>("buffer_sizes.ofm_size");
buffer_sizes.instr_word_size = root.get<size_t>("buffer_sizes.instr_word_size");

// Calculate derived value
buffer_sizes.instr_size = buffer_sizes.instr_word_size * sizeof(int);

return buffer_sizes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class TestParams {
xrt::xclbin xclbin; // Xclbin object
xrt::device device;
std::string kernel_name;
std::string dpu_file;
std::string elf_file;
std::string ifm_file;
std::string param_file;
std::string buffer_sizes_file;
Expand All @@ -40,7 +40,7 @@ class TestParams {
TestParams(xrt::xclbin xclbin,
xrt::device device,
std::string kernel_name,
std::string dpu_file,
std::string elf_file,
std::string ifm_file,
std::string param_file,
std::string buffer_sizes_file,
Expand All @@ -50,7 +50,7 @@ class TestParams {
: xclbin(std::move(xclbin)),
device(std::move(device)),
kernel_name(std::move(kernel_name)),
dpu_file(std::move(dpu_file)),
elf_file(std::move(elf_file)),
ifm_file(std::move(ifm_file)),
param_file(std::move(param_file)),
buffer_sizes_file(std::move(buffer_sizes_file)),
Expand All @@ -66,12 +66,11 @@ class BO_set {
xrt::bo bo_param; // Buffer object for parameters
xrt::bo bo_ofm; // Buffer object for output feature map
xrt::bo bo_inter; // Buffer object for intermediate data
xrt::bo bo_instr; // Buffer object for instructions
xrt::bo bo_mc; // Buffer object for memory controller

public:
// Constructor to initialize buffer objects
BO_set(const xrt::device&, const xrt::kernel&, const BufferSizes&, const std::string&, const std::string&, const std::string&);
BO_set(const xrt::device&, const BufferSizes&, const std::string&, const std::string&);

// Method to set kernel arguments
void set_kernel_args(xrt::run&) const;
Expand Down
Loading