Skip to content

Commit

Permalink
CR-1219310 + code cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Akshay Tondak <[email protected]>
  • Loading branch information
Akshay Tondak authored and Akshay Tondak committed Dec 6, 2024
1 parent 659d8ce commit 9a275a4
Show file tree
Hide file tree
Showing 15 changed files with 100 additions and 101 deletions.
76 changes: 0 additions & 76 deletions src/runtime_src/core/tools/common/TestRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,6 @@ runTestInternal(std::shared_ptr<xrt_core::device> dev,
is_thread_running = false;
}

static void
program_xclbin(const std::shared_ptr<xrt_core::device>& device, const std::string& xclbin)
{
auto bdf = xq::pcie_bdf::to_string(xrt_core::device_query<xq::pcie_bdf>(device));
auto xclbin_obj = xrt::xclbin{xclbin};
try {
device->load_xclbin(xclbin_obj);
}
catch (const std::exception& e) {
XBUtilities::throw_cancel(boost::format("Could not program device %s : %s") % bdf % e.what());
}
}
} //end anonymous namespace

// ----- C L A S S M E T H O D S -------------------------------------------
Expand Down Expand Up @@ -194,70 +182,6 @@ TestRunner::runPyTestCase( const std::shared_ptr<xrt_core::device>& _dev, const
}
}

int
TestRunner::validate_binary_file(const std::string& binaryfile)
{
std::ifstream infile(binaryfile);
if (!infile.good())
return EOPNOTSUPP;
else
return EXIT_SUCCESS;
}
bool
TestRunner::search_and_program_xclbin(const std::shared_ptr<xrt_core::device>& dev, boost::property_tree::ptree& ptTest)
{
xuid_t uuid;
uuid_parse(xrt_core::device_query<xq::xclbin_uuid>(dev).c_str(), uuid);

const std::string xclbin_path = XBValidateUtils::findXclbinPath(dev, ptTest);

try {
program_xclbin(dev, xclbin_path);
}
catch (const std::exception& e) {
XBValidateUtils::logger(ptTest, "Error", e.what());
ptTest.put("status", XBValidateUtils::test_token_failed);
return false;
}

return true;
}

/*
* Runs dpu sequence or elf flow for xrt_smi tests
*/
std::string
TestRunner::dpu_or_elf(const std::shared_ptr<xrt_core::device>& dev, const xrt::xclbin& xclbin,
boost::property_tree::ptree& ptTest)
{
if (xrt_core::device_query<xrt_core::query::pcie_id>(dev).device_id != 5696) { // device ID for npu3 in decimal
// Determine The DPU Kernel Name
auto xkernels = xclbin.get_kernels();

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 {
XBValidateUtils::logger(ptTest, "Error", "No kernel with `DPU` found in the xclbin");
ptTest.put("status", XBValidateUtils::test_token_failed);
}
auto kernelName = xkernel.get_name();

return kernelName;
}
else {
// Elf flow
const auto elf_name = xrt_core::device_query<xrt_core::query::elf_name>(dev, xrt_core::query::elf_name::type::nop);
auto elf_path = XBValidateUtils::findPlatformFile(elf_name, ptTest);

return elf_path;
}
}

/*
* Gets kernel depending on if 2nd param is dpu sequence or elf file
Expand Down
4 changes: 0 additions & 4 deletions src/runtime_src/core/tools/common/TestRunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,8 @@ class TestRunner : public JSONConfigurable {
const std::string & xclbin = "", bool is_explicit = false);
void runPyTestCase( const std::shared_ptr<xrt_core::device>& _dev, const std::string& py,
boost::property_tree::ptree& _ptTest);
bool search_and_program_xclbin(const std::shared_ptr<xrt_core::device>& dev, boost::property_tree::ptree& ptTest);
std::vector<std::string> findDependencies( const std::string& test_path,
const std::string& ps_kernel_name);
int validate_binary_file(const std::string& binaryfile);
std::string dpu_or_elf(const std::shared_ptr<xrt_core::device>& dev, const xrt::xclbin& xclbin,
boost::property_tree::ptree& ptTest);
xrt::kernel get_kernel(const xrt::hw_context& hwctx, const std::string& kernel_or_elf);

std::string m_xclbin;
Expand Down
4 changes: 2 additions & 2 deletions src/runtime_src/core/tools/common/tests/TestAiePs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ TestAiePs::runTest(std::shared_ptr<xrt_core::device> dev, boost::property_tree::
const std::vector<std::string> dependency_paths = findDependencies(test_path, m_xclbin);
// Load dependency xclbins onto device if any
for (const auto& path : dependency_paths) {
auto retVal = validate_binary_file(path);
auto retVal = XBValidateUtils::validate_binary_file(path);
if (retVal == EOPNOTSUPP) {
ptree.put("status", XBValidateUtils::test_token_skipped);
return;
Expand All @@ -58,7 +58,7 @@ TestAiePs::runTest(std::shared_ptr<xrt_core::device> dev, boost::property_tree::

const std::string b_file = XBValidateUtils::findXclbinPath(dev, ptree);
// Load ps kernel onto device
auto retVal = validate_binary_file(b_file);
auto retVal = XBValidateUtils::validate_binary_file(b_file);
if (retVal == EOPNOTSUPP) {
ptree.put("status", XBValidateUtils::test_token_skipped);
return;
Expand Down
2 changes: 1 addition & 1 deletion src/runtime_src/core/tools/common/tests/TestDMA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ TestDMA::run(std::shared_ptr<xrt_core::device> dev)
boost::property_tree::ptree ptree = get_test_header();

ptree.put("status", XBValidateUtils::test_token_skipped);
if (!search_and_program_xclbin(dev, ptree))
if (!XBValidateUtils::search_and_program_xclbin(dev, ptree))
return ptree;

// get DDR bank count from mem_topology if possible
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ TestHostMemBandwidthKernel::runTest(std::shared_ptr<xrt_core::device> dev, boost

const std::string b_file = XBValidateUtils::findXclbinPath(dev, ptree); // bandwidth.xclbin
std::string old_b_file = "/slavebridge.xclbin";
auto retVal = validate_binary_file(b_file);
auto retVal = XBValidateUtils::validate_binary_file(b_file);
// This is for backward compatibility support when older platforms still having slavebridge.xclbin.
auto old_binary_file = std::filesystem::path(test_path) / old_b_file;
auto check_old_b_file = validate_binary_file(old_binary_file.string());
auto check_old_b_file = XBValidateUtils::validate_binary_file(old_binary_file.string());
if (retVal == EOPNOTSUPP) {
if (check_old_b_file == EOPNOTSUPP) {
XBValidateUtils::logger(ptree, "Details", "Test is not supported on this device.");
Expand Down
2 changes: 1 addition & 1 deletion src/runtime_src/core/tools/common/tests/TestNPULatency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ TestNPULatency::run(std::shared_ptr<xrt_core::device> dev)
xrt::kernel testker;

try {
std::string sequence = dpu_or_elf(dev, xclbin, ptree);
std::string sequence = XBValidateUtils::dpu_or_elf(dev, xclbin, ptree);
hwctx = xrt::hw_context(working_dev, xclbin.get_uuid());
testker = get_kernel(hwctx, sequence);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ TestNPUThroughput::run(std::shared_ptr<xrt_core::device> dev)
xrt::kernel testker;

try {
std::string sequence = dpu_or_elf(dev, xclbin, ptree);
std::string sequence = XBValidateUtils::dpu_or_elf(dev, xclbin, ptree);
hwctx = xrt::hw_context(working_dev, xclbin.get_uuid());
testker = get_kernel(hwctx, sequence);
}
Expand Down
4 changes: 2 additions & 2 deletions src/runtime_src/core/tools/common/tests/TestPsIops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ TestPsIops::runTest(std::shared_ptr<xrt_core::device> dev, boost::property_tree:
const std::vector<std::string> dependency_paths = findDependencies(test_path, m_xclbin);
// Validate dependency xclbins onto device if any
for (const auto& path : dependency_paths) {
auto retVal = validate_binary_file(path);
auto retVal = XBValidateUtils::validate_binary_file(path);
if (retVal == EOPNOTSUPP) {
ptree.put("status", XBValidateUtils::test_token_skipped);
return;
Expand All @@ -195,7 +195,7 @@ TestPsIops::runTest(std::shared_ptr<xrt_core::device> dev, boost::property_tree:
}

const std::string b_file = XBValidateUtils::findXclbinPath(dev, ptree); // "/lib/firmware/xilinx/ps_kernels/ps_bandwidth.xclbin"
auto retVal = validate_binary_file(b_file);
auto retVal = XBValidateUtils::validate_binary_file(b_file);
if (retVal == EOPNOTSUPP) {
ptree.put("status", XBValidateUtils::test_token_skipped);
return;
Expand Down
4 changes: 2 additions & 2 deletions src/runtime_src/core/tools/common/tests/TestPsPlVerify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ TestPsPlVerify::runTest(std::shared_ptr<xrt_core::device> dev, boost::property_t

// Load dependency xclbins onto device if any
for (const auto& path : dependency_paths) {
auto retVal = validate_binary_file(path);
auto retVal = XBValidateUtils::validate_binary_file(path);
if (retVal == EOPNOTSUPP) {
ptree.put("status", XBValidateUtils::test_token_skipped);
return;
Expand All @@ -59,7 +59,7 @@ TestPsPlVerify::runTest(std::shared_ptr<xrt_core::device> dev, boost::property_t
}

// Load ps kernel onto device
auto retVal = validate_binary_file(b_file);
auto retVal = XBValidateUtils::validate_binary_file(b_file);
if (flag_s || retVal == EOPNOTSUPP) {
ptree.put("status", XBValidateUtils::test_token_skipped);
return;
Expand Down
4 changes: 2 additions & 2 deletions src/runtime_src/core/tools/common/tests/TestPsVerify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ TestPsVerify::runTest(std::shared_ptr<xrt_core::device> dev, boost::property_tre
const std::vector<std::string> dependency_paths = findDependencies(test_path, m_xclbin);
// Load dependency xclbins onto device if any
for (const auto& path : dependency_paths) {
auto retVal = validate_binary_file(path);
auto retVal = XBValidateUtils::validate_binary_file(path);
if (retVal == EOPNOTSUPP) {
ptree.put("status", XBValidateUtils::test_token_skipped);
return;
Expand All @@ -48,7 +48,7 @@ TestPsVerify::runTest(std::shared_ptr<xrt_core::device> dev, boost::property_tre

const std::string b_file = XBValidateUtils::findXclbinPath(dev, ptree);
// Load ps kernel onto device
auto retVal = validate_binary_file(b_file);
auto retVal = XBValidateUtils::validate_binary_file(b_file);
if (retVal == EOPNOTSUPP) {
ptree.put("status", XBValidateUtils::test_token_skipped);
return;
Expand Down
84 changes: 79 additions & 5 deletions src/runtime_src/core/tools/common/tests/TestValidateUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,7 @@ TestCase::initialize()
// Initialize kernels, buffer objects, and runs
for (int j = 0; j < params.queue_len; j++) {
xrt::kernel kernel;
try {
kernel = xrt::kernel(hw_ctx, params.kernel_name);
} catch (const std::exception& ) {
throw std::runtime_error("Not enough columns available. Please make sure no other workload is running on the device."); //rethrow
}
kernel = xrt::kernel(hw_ctx, params.kernel_name);
auto bos = BO_set(params.device, kernel, params.dpu_file, params.buffer_size);
bos.sync_bos_to_device();
auto run = xrt::run(kernel);
Expand Down Expand Up @@ -370,4 +366,82 @@ searchSSV2Xclbin(const std::string& logic_uuid,
_ptTest.put("status", test_token_skipped);
return "";
}

void
program_xclbin(const std::shared_ptr<xrt_core::device>& device, const std::string& xclbin)
{
auto bdf = xq::pcie_bdf::to_string(xrt_core::device_query<xq::pcie_bdf>(device));
auto xclbin_obj = xrt::xclbin{xclbin};
try {
device->load_xclbin(xclbin_obj);
}
catch (const std::exception& e) {
XBUtilities::throw_cancel(boost::format("Could not program device %s : %s") % bdf % e.what());
}
}
bool
search_and_program_xclbin(const std::shared_ptr<xrt_core::device>& dev, boost::property_tree::ptree& ptTest)
{
xuid_t uuid;
uuid_parse(xrt_core::device_query<xq::xclbin_uuid>(dev).c_str(), uuid);

const std::string xclbin_path = XBValidateUtils::findXclbinPath(dev, ptTest);

try {
program_xclbin(dev, xclbin_path);
}
catch (const std::exception& e) {
XBValidateUtils::logger(ptTest, "Error", e.what());
ptTest.put("status", XBValidateUtils::test_token_failed);
return false;
}

return true;
}

int
validate_binary_file(const std::string& binaryfile)
{
std::ifstream infile(binaryfile);
if (!infile.good())
return EOPNOTSUPP;
else
return EXIT_SUCCESS;
}

/*
* Runs dpu sequence or elf flow for xrt_smi tests
*/
std::string
dpu_or_elf(const std::shared_ptr<xrt_core::device>& dev, const xrt::xclbin& xclbin,
boost::property_tree::ptree& ptTest)
{
if (xrt_core::device_query<xrt_core::query::pcie_id>(dev).device_id != 5696) { // device ID for npu3 in decimal
// Determine The DPU Kernel Name
auto xkernels = xclbin.get_kernels();

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 {
XBValidateUtils::logger(ptTest, "Error", "No kernel with `DPU` found in the xclbin");
ptTest.put("status", XBValidateUtils::test_token_failed);
}
auto kernelName = xkernel.get_name();

return kernelName;
}
else {
// Elf flow
const auto elf_name = xrt_core::device_query<xrt_core::query::elf_name>(dev, xrt_core::query::elf_name::type::nop);
auto elf_path = XBValidateUtils::findPlatformFile(elf_name, ptTest);

return elf_path;
}
}
}// end of namespace XBValidateUtils
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,10 @@ std::string searchLegacyXclbin(const uint16_t vendor, const std::string& dev_nam
boost::property_tree::ptree& _ptTest);
std::string searchSSV2Xclbin(const std::string& logic_uuid,
boost::property_tree::ptree& _ptTest);
void program_xclbin(const std::shared_ptr<xrt_core::device>& device, const std::string& xclbin);
bool search_and_program_xclbin(const std::shared_ptr<xrt_core::device>& dev, boost::property_tree::ptree& ptTest);
int validate_binary_file(const std::string& binaryfile);
std::string dpu_or_elf(const std::shared_ptr<xrt_core::device>& dev, const xrt::xclbin& xclbin,
boost::property_tree::ptree& ptTest);
} //End of namespace XBValidateUtils
#endif
2 changes: 1 addition & 1 deletion src/runtime_src/core/tools/common/tests/Testm2m.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Testm2m::run(std::shared_ptr<xrt_core::device> dev)
return ptree;
}

if (!search_and_program_xclbin(dev, ptree)) {
if (!XBValidateUtils::search_and_program_xclbin(dev, ptree)) {
return ptree;
}

Expand Down
2 changes: 1 addition & 1 deletion src/runtime_src/core/tools/common/tests/Testp2p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ Testp2p::run(std::shared_ptr<xrt_core::device> dev)
boost::property_tree::ptree ptree = get_test_header();
auto no_dma = xrt_core::device_query_default<xrt_core::query::nodma>(dev, 0);

if (!search_and_program_xclbin(dev, ptree)) {
if (!XBValidateUtils::search_and_program_xclbin(dev, ptree)) {
return ptree;
}

Expand Down
2 changes: 1 addition & 1 deletion src/runtime_src/core/tools/xbutil2/xbutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ R"(
}]
},{
"validate": [{
"test": ["latency", "throughput", "cmd-chain-latency", "cmd-chain-throughput", "df-bw", "tct-one-col", "tct-all-col", "gemm", "aie-reconfig-overhead", "spatial-sharing-overhead", "temporal-sharing-overhead"]
"test": ["spatial-sharing-overhead", "latency", "throughput", "cmd-chain-latency", "cmd-chain-throughput", "df-bw", "tct-one-col", "tct-all-col", "gemm", "aie-reconfig-overhead", temporal-sharing-overhead"]
}]
}]
}]
Expand Down

0 comments on commit 9a275a4

Please sign in to comment.