diff --git a/src/runtime_src/core/tools/common/tests/TestAiePl.cpp b/src/runtime_src/core/tools/common/tests/TestAiePl.cpp index 659034de3c..e6145c7928 100644 --- a/src/runtime_src/core/tools/common/tests/TestAiePl.cpp +++ b/src/runtime_src/core/tools/common/tests/TestAiePl.cpp @@ -40,8 +40,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, boost::property_tree::ptree& aie_meta, std::string dma_lock) { + xf::plctrl::plController m_pl_ctrl(aie_meta, dma_lock.c_str()); unsigned int num_iter = 2; unsigned int num_sample = 16; @@ -143,9 +143,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, 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(aie_meta); unsigned int num_iter = 1; unsigned int num_sample = 32; @@ -233,53 +233,55 @@ TestAiePl::runTest(std::shared_ptr dev, boost::property_tree:: 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; - 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())); - 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()); - - // For AIE1 need to use a different xclbin name + // pl_controller_aie.xclbin is the default xclbin filename std::string b_file = "pl_controller_aie.xclbin"; - if (hw_gen == 1) { + auto binaryFile = std::filesystem::path(test_path) / b_file; + if (!std::filesystem::exists(binaryFile)) { + // vck5000 has the different xclbin name b_file = "vck5000_pcie_pl_controller.xclbin.xclbin"; - ptree.put("xclbin", "vck5000_pcie_pl_controller.xclbin.xclbin"); + binaryFile = std::filesystem::path(test_path) / b_file; + if (!std::filesystem::exists(binaryFile)){ + logger(ptree, "Error", boost::str(boost::format("The xclbin could not be found"))); + ptree.put("status", test_token_skipped); + return; + } } - - auto binaryFile = std::filesystem::path(test_path) / b_file; ptree.put("xclbin_directory", std::filesystem::path(test_path)); - std::ifstream infile(binaryFile.string()); - if (!infile.good()) { - logger(ptree, "Error", boost::str(boost::format("The given file could not be found: %s") % binaryFile.string())); + const auto uuid = device.load_xclbin(binaryFile.string()); + + boost::property_tree::ptree aie_meta; + auto metadata_pair = dev->get_axlf_section(AIE_METADATA); + if (!metadata_pair.first || metadata_pair.second == 0){ ptree.put("status", test_token_skipped); return; } + std::string aie_metadata(metadata_pair.first, metadata_pair.second); + std::stringstream aie_metadata_stream(aie_metadata); + try { + boost::property_tree::read_json(aie_metadata_stream, aie_meta); + } + catch(const boost::property_tree::json_parser_error& e){ + std::cerr << "JSON parsing error : " << e.what() << std::endl; + return; + } - auto uuid = device.load_xclbin(binaryFile.string()); - - // instance of plController - std::string dma_lock_file = "dma_lock_report.json"; - auto dma_lock = std::filesystem::path(test_path) / dma_lock_file; + 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()); bool match = false; // Check for AIE Hardware Generation switch (hw_gen) { - case 1: - match = run_pl_controller_aie1(device, uuid, aie_control.string(), dma_lock.string()); + case 1: { + std::string dma_lock_file = "dma_lock_report.json"; + auto dma_lock = std::filesystem::path(test_path) / dma_lock_file; + match = run_pl_controller_aie1(device, uuid, aie_meta, dma_lock.string()); break; + } case 2: - match = run_pl_controller_aie2(device, uuid, aie_control.string(), dma_lock.string()); + match = run_pl_controller_aie2(device, uuid, 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..7800d77325 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,9 +20,9 @@ namespace xf { namespace plctrl { -plController::plController(const std::string& aie_info_path, +plController::plController(boost::property_tree::ptree& aie_meta_info, const std::string& dma_info_path) - : m_aie_info_path(aie_info_path), + : m_aie_meta_info(aie_meta_info), m_dma_info_path(dma_info_path), m_outputSize(0), m_ping_pong(false) @@ -170,11 +170,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 +206,8 @@ std::vector plController::get_tiles(const std::string& graph_name) { boost::property_tree::ptree aie_meta; + aie_meta = m_aie_meta_info; - 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); 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..47c6be1057 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(boost::property_tree::ptree& m_aie_meta_info, const std::string& dma_info_path); void enqueue_set_aie_iteration(const std::string& graphName, int num_iter); @@ -94,7 +94,7 @@ class plController std::vector m_opcodeBuffer; std::vector m_metadata; - std::string m_aie_info_path; + boost::property_tree::ptree m_aie_meta_info; std::string m_dma_info_path; 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..6fd0c23856 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,8 @@ 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 boost::property_tree::ptree& aie_meta_info) + : m_aie_meta_info(aie_meta_info), m_outputSize(0), m_set_num_iter(false) { @@ -122,27 +121,6 @@ void plController_aie2::enqueue_loop_end() { m_opcodeBuffer.add(CMD_TYPE::LOOP_END); } -void plController_aie2::enqueue_set_and_enqueue_dma_bd(const std::string& portName, int idx, int dma_bd_len, int id) { - auto buffers = get_buffers(portName); - if (buffers.size() == 0) - throw std::runtime_error("Cannot find port " + portName); - else if (static_cast(idx) > buffers.size() - 1) - throw std::runtime_error("port idx " + std::to_string(idx) + "is out of range"); - auto buffer = buffers.at(idx); - - uint32_t dma_bd_value = 0x83FC0000 + dma_bd_len - 1; - m_opcodeBuffer.add(CMD_TYPE::SET_DMA_BD); - m_opcodeBuffer.add(buffer.bd_num); - m_opcodeBuffer.add(dma_bd_value); - m_opcodeBuffer.add(id); - - m_opcodeBuffer.add(CMD_TYPE::ENQUEUE_DMA_BD); - m_opcodeBuffer.add(buffer.bd_num); - m_opcodeBuffer.add(buffer.ch_num); - m_opcodeBuffer.add(buffer.s2mm); - m_opcodeBuffer.add(id); -} - void plController_aie2::enqueue_update_aie_rtp(const std::string& rtpPort, int rtpVal, int id) { auto it = m_rtps.find(rtpPort); if (it == m_rtps.end()) @@ -179,11 +157,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 +190,8 @@ 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"); + aie_meta = m_aie_meta_info; - boost::property_tree::json_parser::read_json(m_aie_info_path, aie_meta); std::vector tiles; for (auto& graph : aie_meta.get_child("aie_metadata.graphs")) { @@ -267,52 +238,5 @@ std::vector plController_aie2::get_tiles(const std::string& graph_nam return tiles; } -std::vector plController_aie2::get_buffers(const std::string& port_name) { - boost::property_tree::ptree dma_meta; - std::ifstream jsonFile(m_dma_info_path); - if (!jsonFile.good()) - throw std::runtime_error("get_buffers():ERROR:No dma info file specified"); - - boost::property_tree::json_parser::read_json(m_dma_info_path, dma_meta); - std::vector buffers; - - for (auto& buffer : dma_meta.get_child("S2MM")) { - for (auto& node : buffer.second.get_child("KernelPort")) { - if (node.second.get_value() != port_name) continue; - int count = 0; - for (auto& buff_info : buffer.second.get_child("BufferInfo")) { - for (auto& field : buff_info.second.get_child("BD")) { - buffers.push_back(buffer_type()); - auto& b = buffers.at(count++); - b.col = buff_info.second.get("Column"); - b.row = buff_info.second.get("Row"); - b.ch_num = buff_info.second.get("Channel"); - b.lock_id = buff_info.second.get("LockID"); - b.bd_num = static_cast(std::stoul(field.second.data())); - b.s2mm = true; - } - } - } - } - for (auto& buffer : dma_meta.get_child("MM2S")) { - for (auto& node : buffer.second.get_child("KernelPort")) { - if (node.second.get_value() != port_name) continue; - int count = 0; - for (auto& buff_info : buffer.second.get_child("BufferInfo")) { - for (auto& field : buff_info.second.get_child("BD")) { - buffers.push_back(buffer_type()); - auto& b = buffers.at(count++); - b.col = buff_info.second.get("Column"); - b.row = buff_info.second.get("Row"); - b.ch_num = buff_info.second.get("Channel"); - b.lock_id = buff_info.second.get("LockID"); - b.bd_num = static_cast(std::stoul(field.second.data())); - b.s2mm = false; - } - } - } - } - return buffers; -} } // end of namespace plctrl } // end of namespace pl 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..ca363be8a7 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 boost::property_tree::ptree& aie_meta_info); void enqueue_set_aie_iteration(const std::string& graphName, int num_iter); @@ -90,13 +90,10 @@ class plController_aie2 { std::vector get_tiles(const std::string& graph_name); - std::vector get_buffers(const std::string& port_name); - 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;