From bc18f22811c538299e1fca9e86ea14b5d9ae2c0e Mon Sep 17 00:00:00 2001 From: bisingha Date: Wed, 10 Apr 2024 10:10:28 +0000 Subject: [PATCH] Removing json file dependecy for the aie test Signed-off-by: bisingha --- .../core/include/experimental/xrt_xclbin.h | 8 ++++ .../core/tools/common/tests/TestAiePl.cpp | 47 ++++++++++++++----- .../tests/aie_pl_util/pl_controller.cpp | 21 ++------- .../tests/aie_pl_util/pl_controller.hpp | 4 +- .../tests/aie_pl_util/pl_controller_aie2.cpp | 19 ++------ .../tests/aie_pl_util/pl_controller_aie2.hpp | 4 +- 6 files changed, 56 insertions(+), 47 deletions(-) diff --git a/src/runtime_src/core/include/experimental/xrt_xclbin.h b/src/runtime_src/core/include/experimental/xrt_xclbin.h index 0d68f95c4d..2a9ef00030 100644 --- a/src/runtime_src/core/include/experimental/xrt_xclbin.h +++ b/src/runtime_src/core/include/experimental/xrt_xclbin.h @@ -797,6 +797,14 @@ class xclbin : public detail::pimpl const axlf* get_axlf() const; + /** + * It is a wrapper to access the private function get_axlf_section() + * to get the AIE_METADATA + */ + std::pair getAIE_Metadata_Wrapper(xrt::xclbin xclbin_obj){ + return xclbin_obj.get_axlf_section(AIE_METADATA); + } + /** * get_axlf_section() - Retrieve specified xclbin section * diff --git a/src/runtime_src/core/tools/common/tests/TestAiePl.cpp b/src/runtime_src/core/tools/common/tests/TestAiePl.cpp index 659034de3c..fe17026685 100644 --- a/src/runtime_src/core/tools/common/tests/TestAiePl.cpp +++ b/src/runtime_src/core/tools/common/tests/TestAiePl.cpp @@ -13,6 +13,7 @@ namespace XBU = XBUtilities; // XRT includes #include "experimental/xrt_system.h" +#include "experimental/xrt_xclbin.h" #include "xrt/xrt_bo.h" #include "xrt/xrt_device.h" #include "xrt/xrt_kernel.h" @@ -40,8 +41,8 @@ TestAiePl::run(std::shared_ptr dev) return ptree; } -bool run_pl_controller_aie1(xrt::device device, xrt::uuid uuid, std::string aie_control, std::string dma_lock) { - xf::plctrl::plController m_pl_ctrl(aie_control.c_str(), dma_lock.c_str()); +bool run_pl_controller_aie1(xrt::device device, xrt::uuid uuid, std::string dma_lock, boost::property_tree::ptree aie_meta) { + xf::plctrl::plController m_pl_ctrl(dma_lock.c_str(), aie_meta); unsigned int num_iter = 2; unsigned int num_sample = 16; @@ -143,9 +144,9 @@ bool run_pl_controller_aie1(xrt::device device, xrt::uuid uuid, std::string aie_ return match; } -bool run_pl_controller_aie2(xrt::device device, xrt::uuid uuid, std::string aie_control, std::string dma_lock) { +bool run_pl_controller_aie2(xrt::device device, xrt::uuid uuid, std::string dma_lock, boost::property_tree::ptree aie_meta) { // instance of plController - xf::plctrl::plController_aie2 m_pl_ctrl(aie_control.c_str(), dma_lock.c_str()); + xf::plctrl::plController_aie2 m_pl_ctrl(dma_lock.c_str(), aie_meta); unsigned int num_iter = 1; unsigned int num_sample = 32; @@ -227,24 +228,44 @@ bool run_pl_controller_aie2(xrt::device device, xrt::uuid uuid, std::string aie_ return match; } +bool getAIE_Metadata(std::string test_path, boost::property_tree::ptree& aie_meta){ + bool res = true; + + //default is pl_controller_aie.xclbin + std::string b_file = "pl_controller_aie.xclbin"; + auto binaryFile = std::filesystem::path(test_path) / b_file; + std::ifstream infile(binaryFile.string()); + if (!infile.good()) { + b_file = "vck5000_pcie_pl_controller.xclbin.xclbin"; + auto binaryFile = std::filesystem::path(test_path) / b_file; + std::ifstream infile(binaryFile.string()); + if (!infile.good()) { + return false; + } + } + + //create an xclbin obj + auto xclbin_obj = xrt::xclbin(binaryFile); + auto metadata = xclbin_obj.getAIE_Metadata_Wrapper(xclbin_obj); + std::istringstream metadataStream(metadata.first); + boost::property_tree::read_json(metadataStream, aie_meta); + return res; +} + void TestAiePl::runTest(std::shared_ptr dev, boost::property_tree::ptree& ptree) { xrt::device device(dev); const std::string test_path = findPlatformPath(dev, ptree); - const std::string aie_control_file = "aie_control_config.json"; - auto aie_control = std::filesystem::path(test_path) / aie_control_file; + boost::property_tree::ptree aie_meta; - std::ifstream aiefile(aie_control.string()); - if (!aiefile.good()) { - logger(ptree, "Details", boost::str(boost::format("The given file could not be found: %s") % aie_control.string())); + if (!getAIE_Metadata(test_path, aie_meta)) { + logger(ptree, "Details", boost::str(boost::format("The AIE_METADATA could not be found: %s"))); ptree.put("status", test_token_skipped); return; } - boost::property_tree::ptree aie_meta; - read_json(aie_control.string(), aie_meta); auto driver_info_node = aie_meta.get_child("aie_metadata.driver_config"); auto hw_gen_node = driver_info_node.get_child("hw_gen"); auto hw_gen = std::stoul(hw_gen_node.data()); @@ -276,10 +297,10 @@ TestAiePl::runTest(std::shared_ptr dev, boost::property_tree:: // Check for AIE Hardware Generation switch (hw_gen) { case 1: - match = run_pl_controller_aie1(device, uuid, aie_control.string(), dma_lock.string()); + match = run_pl_controller_aie1(device, uuid, dma_lock.string(), aie_meta); break; case 2: - match = run_pl_controller_aie2(device, uuid, aie_control.string(), dma_lock.string()); + match = run_pl_controller_aie2(device, uuid, dma_lock.string(), aie_meta); break; default: logger(ptree, "Error", "Unsupported AIE Hardware"); diff --git a/src/runtime_src/core/tools/common/tests/aie_pl_util/pl_controller.cpp b/src/runtime_src/core/tools/common/tests/aie_pl_util/pl_controller.cpp index 00950d3ff9..1a9a2ec0a4 100644 --- a/src/runtime_src/core/tools/common/tests/aie_pl_util/pl_controller.cpp +++ b/src/runtime_src/core/tools/common/tests/aie_pl_util/pl_controller.cpp @@ -20,10 +20,9 @@ namespace xf { namespace plctrl { -plController::plController(const std::string& aie_info_path, - const std::string& dma_info_path) - : m_aie_info_path(aie_info_path), - m_dma_info_path(dma_info_path), +plController::plController(const std::string& dma_info_path, boost::property_tree::ptree& aie_meta_info) + : m_dma_info_path(dma_info_path), + m_aie_meta_info(aie_meta_info), m_outputSize(0), m_ping_pong(false) { @@ -170,11 +169,7 @@ void plController::get_rtp() { boost::property_tree::ptree aie_meta; - std::ifstream jsonFile(m_aie_info_path); - if (!jsonFile.good()) - throw std::runtime_error("get_rtp():ERROR:No aie info file specified"); - - boost::property_tree::json_parser::read_json(m_aie_info_path, aie_meta); + aie_meta = m_aie_meta_info; for (auto& rtp_node : aie_meta.get_child("aie_metadata.RTPs")) { rtp_type rtp = {}; @@ -210,13 +205,7 @@ std::vector plController::get_tiles(const std::string& graph_name) { boost::property_tree::ptree aie_meta; - - std::ifstream jsonFile(m_aie_info_path); - if (!jsonFile.good()) - throw std::runtime_error( - "ERROR (get_tiles):No aie info file specified"); - - boost::property_tree::json_parser::read_json(m_aie_info_path, aie_meta); + aie_meta = m_aie_meta_info; std::vector tiles; for (auto& graph : aie_meta.get_child("aie_metadata.graphs")) { diff --git a/src/runtime_src/core/tools/common/tests/aie_pl_util/pl_controller.hpp b/src/runtime_src/core/tools/common/tests/aie_pl_util/pl_controller.hpp index 44d315b608..d96578c11e 100644 --- a/src/runtime_src/core/tools/common/tests/aie_pl_util/pl_controller.hpp +++ b/src/runtime_src/core/tools/common/tests/aie_pl_util/pl_controller.hpp @@ -40,7 +40,7 @@ class plController /* Constructor */ plController() = delete; - plController(const std::string& aie_info_path, const std::string& dma_info_path); + plController(const std::string& dma_info_path, boost::property_tree::ptree& aie_meta_info); void enqueue_set_aie_iteration(const std::string& graphName, int num_iter); @@ -94,8 +94,8 @@ class plController std::vector m_opcodeBuffer; std::vector m_metadata; - std::string m_aie_info_path; std::string m_dma_info_path; + boost::property_tree::ptree m_aie_meta_info; uint32_t m_outputSize; bool m_ping_pong; }; diff --git a/src/runtime_src/core/tools/common/tests/aie_pl_util/pl_controller_aie2.cpp b/src/runtime_src/core/tools/common/tests/aie_pl_util/pl_controller_aie2.cpp index e8a0a1dea0..86e9b10def 100644 --- a/src/runtime_src/core/tools/common/tests/aie_pl_util/pl_controller_aie2.cpp +++ b/src/runtime_src/core/tools/common/tests/aie_pl_util/pl_controller_aie2.cpp @@ -60,9 +60,9 @@ void dynBuffer::add(uint32_t* data, int blk_size) { m_usedSize += blk_size; } -plController_aie2::plController_aie2(const std::string& aie_info_path, const std::string& dma_info_path) - : m_aie_info_path(aie_info_path), - m_dma_info_path(dma_info_path), +plController_aie2::plController_aie2(const std::string& dma_info_path, boost::property_tree::ptree& aie_meta_info) + : m_dma_info_path(dma_info_path), + m_aie_meta_info(aie_meta_info), m_outputSize(0), m_set_num_iter(false) { @@ -179,12 +179,7 @@ void plController_aie2::enqueue_write(int addr, int val) { // re-use this code from "core/edge/common/aie_parser.cpp" void plController_aie2::get_rtp() { boost::property_tree::ptree aie_meta; - std::ifstream jsonFile(m_aie_info_path); - if (!jsonFile.good()) - throw std::runtime_error("get_rtp():ERROR:No aie info file specified"); - - boost::property_tree::json_parser::read_json(m_aie_info_path, aie_meta); - + aie_meta = m_aie_meta_info; for (auto& rtp_node : aie_meta.get_child("aie_metadata.RTPs")) { rtp_type rtp; @@ -216,11 +211,7 @@ void plController_aie2::get_rtp() { std::vector plController_aie2::get_tiles(const std::string& graph_name) { boost::property_tree::ptree aie_meta; - std::ifstream jsonFile(m_aie_info_path); - if (!jsonFile.good()) - throw std::runtime_error("get_tiles():ERROR:No aie info file specified"); - - boost::property_tree::json_parser::read_json(m_aie_info_path, aie_meta); + aie_meta = m_aie_meta_info; std::vector tiles; for (auto& graph : aie_meta.get_child("aie_metadata.graphs")) { diff --git a/src/runtime_src/core/tools/common/tests/aie_pl_util/pl_controller_aie2.hpp b/src/runtime_src/core/tools/common/tests/aie_pl_util/pl_controller_aie2.hpp index de212ad454..e3788a23e3 100644 --- a/src/runtime_src/core/tools/common/tests/aie_pl_util/pl_controller_aie2.hpp +++ b/src/runtime_src/core/tools/common/tests/aie_pl_util/pl_controller_aie2.hpp @@ -51,7 +51,7 @@ class plController_aie2 { /* Constructor */ plController_aie2() = delete; - plController_aie2(const std::string& aie_info_path, const std::string& dma_info_path); + plController_aie2(const std::string& dma_info_path, boost::property_tree::ptree& aie_meta_info); void enqueue_set_aie_iteration(const std::string& graphName, int num_iter); @@ -95,8 +95,8 @@ class plController_aie2 { std::unordered_map m_rtps; dynBuffer m_opcodeBuffer; - std::string m_aie_info_path = "aie_control_config.json"; std::string m_dma_info_path = "dma_lock_report.json"; + boost::property_tree::ptree m_aie_meta_info; uint32_t m_outputSize = 0; bool m_set_num_iter = false;