Skip to content

Commit

Permalink
Fix for CR-1219310 : Spatial sharing overhead test failure on linux (#…
Browse files Browse the repository at this point in the history
…8652)

* CR-1219310 + code cleanup

Signed-off-by: Akshay Tondak <[email protected]>

* Fix for spatial sharing crash

Signed-off-by: Akshay Tondak <[email protected]>

* Param size changes and turbo addition

Signed-off-by: Akshay Tondak <[email protected]>

---------

Signed-off-by: Akshay Tondak <[email protected]>
Co-authored-by: Akshay Tondak <[email protected]>
  • Loading branch information
aktondak and Akshay Tondak authored Dec 11, 2024
1 parent ae8996c commit feb0fe3
Show file tree
Hide file tree
Showing 17 changed files with 114 additions and 110 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
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
namespace XBU = XBUtilities;

static constexpr size_t host_app = 1; //opcode
static constexpr size_t buffer_size = 1024; //1 KB
static constexpr size_t buffer_size = 1024 * 1024 * 1024; //1 GB

// Method to run the test
// Parameters:
Expand Down Expand Up @@ -96,7 +96,7 @@ boost::property_tree::ptree TestSpatialSharingOvd::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, 8, buffer_size, 10000);
TestParams params(xclbin, working_dev, kernelName, dpu_instr, 2, buffer_size, 10);
testcases.emplace_back(params);
testcases.emplace_back(params);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


namespace XBU = XBUtilities;
static constexpr size_t buffer_size = 1024; //1 KB
static constexpr size_t buffer_size = 1024*1024*1024; //1 GB

boost::property_tree::ptree
TestTemporalSharingOvd::run(std::shared_ptr<xrt_core::device> dev) {
Expand Down Expand Up @@ -67,7 +67,7 @@ TestTemporalSharingOvd::run(std::shared_ptr<xrt_core::device> dev) {
std::vector<TestCase> testcases;

// Create two test cases and add them to the vector
TestParams params(xclbin, working_dev, kernelName, dpu_instr, 8, buffer_size, 10000);
TestParams params(xclbin, working_dev, kernelName, dpu_instr, 1, buffer_size, 10);
testcases.emplace_back(params);
testcases.emplace_back(params);

Expand Down
99 changes: 89 additions & 10 deletions src/runtime_src/core/tools/common/tests/TestValidateUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
#include "TestValidateUtilities.h"
namespace xq = xrt_core::query;

static constexpr size_t param_size = 0x100;
static constexpr size_t inter_size = 0x100;
static constexpr size_t mc_size = 0x100;

// Constructor for BO_set
// BO_set is a collection of all the buffer objects so that the operations on all buffers can be done from a single object
// Parameters:
Expand All @@ -24,17 +28,18 @@ namespace xq = xrt_core::query;
BO_set::BO_set(const xrt::device& device, const xrt::kernel& kernel, const std::string& dpu_instr, size_t buffer_size)
: buffer_size(buffer_size),
bo_ifm (device, buffer_size, XRT_BO_FLAGS_HOST_ONLY, kernel.group_id(1)),
bo_param (device, buffer_size, XRT_BO_FLAGS_HOST_ONLY, kernel.group_id(2)),
bo_param (device, param_size, XRT_BO_FLAGS_HOST_ONLY, kernel.group_id(2)),
bo_ofm (device, buffer_size, XRT_BO_FLAGS_HOST_ONLY, kernel.group_id(3)),
bo_inter (device, buffer_size, XRT_BO_FLAGS_HOST_ONLY, kernel.group_id(4)),
bo_mc (device, buffer_size, XRT_BO_FLAGS_HOST_ONLY, kernel.group_id(7))
bo_inter (device, inter_size, XRT_BO_FLAGS_HOST_ONLY, kernel.group_id(4)),
bo_mc (device, mc_size, XRT_BO_FLAGS_HOST_ONLY, kernel.group_id(7))
{
if (dpu_instr.empty()) {
// Create a no-op instruction if no instruction file is provided
std::memset(bo_instr.map<char*>(), (uint8_t)0, buffer_size);
} else {
size_t instr_size = XBValidateUtils::get_instr_size(dpu_instr);
bo_instr = xrt::bo(device, instr_size, XCL_BO_FLAGS_CACHEABLE, kernel.group_id(5));
bo_instr = xrt::bo(device, instr_size * sizeof(int), XCL_BO_FLAGS_CACHEABLE, kernel.group_id(5));
XBValidateUtils::init_instr_buf(bo_instr, dpu_instr);
}
}

Expand All @@ -57,7 +62,7 @@ void BO_set::set_kernel_args(xrt::run& run) const {
run.set_arg(3, bo_ofm);
run.set_arg(4, bo_inter);
run.set_arg(5, bo_instr);
run.set_arg(6, buffer_size/sizeof(int));
run.set_arg(6, bo_instr.size()/sizeof(int));
run.set_arg(7, bo_mc);
}

Expand All @@ -68,11 +73,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 +371,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
Loading

0 comments on commit feb0fe3

Please sign in to comment.