Skip to content

Commit

Permalink
VITIS-9039 Add an IPU specific test to validate (#7676)
Browse files Browse the repository at this point in the history
* add no-op IPU test

* add ipu-verify test

* Signing the commit

Signed-off-by: AShivangi <[email protected]>

* requested changes

Signed-off-by: AShivangi <[email protected]>

* use module_loader xclbin_path()

Signed-off-by: AShivangi <[email protected]>

* remove unused code

Signed-off-by: AShivangi <[email protected]>

* requested changes

Signed-off-by: AShivangi <[email protected]>

* build fix

Signed-off-by: AShivangi <[email protected]>

---------

Signed-off-by: AShivangi <[email protected]>
  • Loading branch information
AShivangi authored Aug 31, 2023
1 parent c465386 commit 9f4b430
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 6 deletions.
18 changes: 16 additions & 2 deletions src/runtime_src/core/tools/common/TestRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "TestRunner.h"
#include "core/common/error.h"
#include "core/common/query_requests.h"
#include "core/common/module_loader.h"
#include "core/tools/common/Process.h"
#include "tools/common/XBUtilities.h"
#include "tools/common/XBUtilitiesCore.h"
Expand Down Expand Up @@ -68,7 +69,6 @@ program_xclbin(const std::shared_ptr<xrt_core::device>& device, const std::strin
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 @@ -407,13 +407,27 @@ std::string
TestRunner::findXclbinPath( const std::shared_ptr<xrt_core::device>& _dev,
boost::property_tree::ptree& _ptTest)
{
auto xclbin_name = _ptTest.get<std::string>("xclbin", "");
std::string xclbin_path;
#ifdef _WIN32
boost::ignore_unused(_dev);
try {
xclbin_path = xrt_core::environment::xclbin_path(xclbin_name);
}
catch(const std::exception) {
const auto fmt = boost::format("%s not available. Skipping validation.") % xclbin_name;
logger(_ptTest, "Details", boost::str(fmt));
_ptTest.put("status", test_token_skipped);
}
#else
const auto platform_path = findPlatformPath(_dev, _ptTest);
const auto xclbin_path = _ptTest.get<std::string>("xclbin_directory", platform_path) + _ptTest.get<std::string>("xclbin", "");
xclbin_path = _ptTest.get<std::string>("xclbin_directory", platform_path) + xclbin_name;
if (!boost::filesystem::exists(xclbin_path)) {
const auto fmt = boost::format("%s not available. Skipping validation.") % xclbin_path;
logger(_ptTest, "Details", boost::str(fmt));
_ptTest.put("status", test_token_skipped);
}
#endif
return xclbin_path;
}

Expand Down
4 changes: 2 additions & 2 deletions src/runtime_src/core/tools/common/TestRunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class TestRunner {
const std::string & get_name() const { return m_name; };
boost::property_tree::ptree get_test_header();
const std::string & getConfigName() const { return get_name(); };
std::string findXclbinPath( const std::shared_ptr<xrt_core::device>& _dev,
boost::property_tree::ptree& _ptTest);

// Child class helper methods
protected:
Expand All @@ -57,8 +59,6 @@ class TestRunner {
boost::property_tree::ptree& _ptTest);
std::string findPlatformPath(const std::shared_ptr<xrt_core::device>& _dev,
boost::property_tree::ptree& _ptTest);
std::string findXclbinPath( 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);

Expand Down
97 changes: 97 additions & 0 deletions src/runtime_src/core/tools/common/tests/TestIPU.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.

// ------ I N C L U D E F I L E S -------------------------------------------
// Local - Include Files
#include "TestIPU.h"
#include "tools/common/XBUtilities.h"
#include "xrt/xrt_bo.h"
#include "xrt/xrt_device.h"
#include "xrt/xrt_hw_context.h"
#include "xrt/xrt_kernel.h"
namespace XBU = XBUtilities;

#include <boost/filesystem.hpp>

static constexpr size_t host_app = 1; //opcode
static constexpr size_t buffer_size = 128;

// ----- C L A S S M E T H O D S -------------------------------------------
TestIPU::TestIPU()
: TestRunner("verify",
"Run 'Hello World' test on IPU",
"1x4.xclbin"){}

boost::property_tree::ptree
TestIPU::run(std::shared_ptr<xrt_core::device> dev)
{
boost::property_tree::ptree ptree = get_test_header();

auto xclbin_path = findXclbinPath(dev, ptree);
if (!boost::filesystem::exists(xclbin_path)) {
return ptree;
}
// log xclbin test dir for debugging purposes
logger(ptree, "Xclbin", xclbin_path);

xrt::xclbin xclbin;
try {
xclbin = xrt::xclbin(xclbin_path);
}
catch (const std::runtime_error& ex) {
logger(ptree, "Error", ex.what());
ptree.put("status", test_token_failed);
return ptree;
}

// 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 {
logger(ptree, "Error", "No kernel with `DPU` found in the xclbin");
ptree.put("status", test_token_failed);
return ptree;
}
auto kernelName = xkernel.get_name();
logger(ptree, "Details", boost::str(boost::format("Kernel name is '%s'") % kernelName));

auto working_dev = xrt::device{dev->get_device_id()};
working_dev.register_xclbin(xclbin);
xrt::hw_context hwctx{working_dev, xclbin.get_uuid()};
xrt::kernel kernel{hwctx, kernelName};

//Create BOs
xrt::bo bo_ifm(working_dev, buffer_size, XRT_BO_FLAGS_HOST_ONLY, kernel.group_id(1));
xrt::bo bo_param(working_dev, buffer_size, XRT_BO_FLAGS_HOST_ONLY, kernel.group_id(2));
xrt::bo bo_ofm(working_dev, buffer_size, XRT_BO_FLAGS_HOST_ONLY, kernel.group_id(3));
xrt::bo bo_inter(working_dev, buffer_size, XRT_BO_FLAGS_HOST_ONLY, kernel.group_id(4));
xrt::bo bo_instr(working_dev, buffer_size, XCL_BO_FLAGS_CACHEABLE, kernel.group_id(5));
xrt::bo bo_mc(working_dev, buffer_size, XRT_BO_FLAGS_HOST_ONLY, kernel.group_id(7));
std::memset(bo_instr.map<char*>(), buffer_size, '0');

//Sync BOs
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);

try {
auto run = kernel(host_app, bo_ifm, bo_param, bo_ofm, bo_inter, bo_instr, buffer_size, bo_mc);
// Wait for kernel to be done
run.wait();
}
catch (const std::exception& ex) {
logger(ptree, "Error", ex.what());
ptree.put("status", test_token_failed);
}

ptree.put("status", test_token_passed);
return ptree;
}
18 changes: 18 additions & 0 deletions src/runtime_src/core/tools/common/tests/TestIPU.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.

#ifndef __TestIPU_h_
#define __TestIPU_h_

#include "tools/common/TestRunner.h"
#include "xrt/xrt_device.h"

class TestIPU : public TestRunner {
public:
boost::property_tree::ptree run(std::shared_ptr<xrt_core::device> dev);

public:
TestIPU();
};

#endif
14 changes: 12 additions & 2 deletions src/runtime_src/core/tools/common/tests/TestVerify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// ------ I N C L U D E F I L E S -------------------------------------------
// Local - Include Files
#include "TestVerify.h"
#include "TestIPU.h"
#include "tools/common/XBUtilities.h"
namespace XBU = XBUtilities;

Expand All @@ -16,7 +17,16 @@ TestVerify::TestVerify()
boost::property_tree::ptree
TestVerify::run(std::shared_ptr<xrt_core::device> dev)
{
boost::property_tree::ptree ptree = get_test_header();
runTestCase(dev, "22_verify.py", ptree);
auto device_name = xrt_core::device_query_default<xrt_core::query::rom_vbnv>(dev, "");
boost::property_tree::ptree ptree;
//to-do: Do it in a cleaner way
if (device_name.find("IPU") != std::string::npos) {
//run ipu verify
ptree = TestIPU{}.run(dev);
}
else {
ptree = get_test_header();
runTestCase(dev, "22_verify.py", ptree);
}
return ptree;
}

0 comments on commit 9f4b430

Please sign in to comment.