Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove json dependency for ai etest #2

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 37 additions & 35 deletions src/runtime_src/core/tools/common/tests/TestAiePl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ TestAiePl::run(std::shared_ptr<xrt_core::device> 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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -233,53 +233,55 @@ TestAiePl::runTest(std::shared_ptr<xrt_core::device> 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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 = {};
Expand Down Expand Up @@ -210,13 +206,8 @@ std::vector<tile_type>
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<tile_type> tiles;

for (auto& graph : aie_meta.get_child("aie_metadata.graphs")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -94,7 +94,7 @@ class plController
std::vector<uint32_t> m_opcodeBuffer;
std::vector<uint32_t> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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<long unsigned int>(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())
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -216,11 +190,8 @@ void plController_aie2::get_rtp() {

std::vector<tile_type> 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<tile_type> tiles;

for (auto& graph : aie_meta.get_child("aie_metadata.graphs")) {
Expand Down Expand Up @@ -267,52 +238,5 @@ std::vector<tile_type> plController_aie2::get_tiles(const std::string& graph_nam
return tiles;
}

std::vector<buffer_type> 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<buffer_type> buffers;

for (auto& buffer : dma_meta.get_child("S2MM")) {
for (auto& node : buffer.second.get_child("KernelPort")) {
if (node.second.get_value<std::string>() != 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<uint16_t>("Column");
b.row = buff_info.second.get<uint16_t>("Row");
b.ch_num = buff_info.second.get<uint16_t>("Channel");
b.lock_id = buff_info.second.get<uint16_t>("LockID");
b.bd_num = static_cast<uint16_t>(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<std::string>() != 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<uint16_t>("Column");
b.row = buff_info.second.get<uint16_t>("Row");
b.ch_num = buff_info.second.get<uint16_t>("Channel");
b.lock_id = buff_info.second.get<uint16_t>("LockID");
b.bd_num = static_cast<uint16_t>(std::stoul(field.second.data()));
b.s2mm = false;
}
}
}
}
return buffers;
}
} // end of namespace plctrl
} // end of namespace pl
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -90,13 +90,10 @@ class plController_aie2 {

std::vector<tile_type> get_tiles(const std::string& graph_name);

std::vector<buffer_type> get_buffers(const std::string& port_name);

std::unordered_map<std::string, rtp_type> 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;
Expand Down
Loading