From 55cee45e5ad69b71aab50aa3f29d34d0e915f4eb Mon Sep 17 00:00:00 2001 From: Vijay Sri Lakshmanan <159942650+xvijaysri@users.noreply.github.com> Date: Tue, 1 Oct 2024 10:54:58 -0700 Subject: [PATCH] Add DRC for dpu_kernel_id of AIE_PARTITION section and m_kernel_id of IP_LAYOUT section. (#8463) * Added DRC for dpu_kernel_id of AIE_PARTITION section and m_kernel_id of IP_LAYOUT section. Signed-off-by: xvijaysri * fix warnings in windows Signed-off-by: xvijaysri * add a message to indicate which m_kernel_id is missing Signed-off-by: xvijaysri * added a comment Signed-off-by: xvijaysri --------- Signed-off-by: xvijaysri --- .../tools/xclbinutil/XclBinUtilMain.cxx | 7 ++- .../tools/xclbinutil/XclBinUtilities.cxx | 43 ++++++++++++++++++- .../tools/xclbinutil/XclBinUtilities.h | 1 + 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/src/runtime_src/tools/xclbinutil/XclBinUtilMain.cxx b/src/runtime_src/tools/xclbinutil/XclBinUtilMain.cxx index e6be5881ea8..2da10e3cb19 100644 --- a/src/runtime_src/tools/xclbinutil/XclBinUtilMain.cxx +++ b/src/runtime_src/tools/xclbinutil/XclBinUtilMain.cxx @@ -522,7 +522,12 @@ int main_(int argc, const char** argv) { if (xclBin.findSection(ASK_GROUP_CONNECTIVITY) != nullptr) xclBin.removeSection("GROUP_CONNECTIVITY"); } - + + if (xclBin.findSection(IP_LAYOUT) != nullptr && xclBin.findSection(AIE_PARTITION) != nullptr){ + if(!XUtil::checkAIEPartitionIPLayoutCompliance(xclBin)){ + throw std::runtime_error("ERROR: The AIE_PARTITION section in the xclbin is not compliant with IP_LAYOUT section"); + } + } // Auto add GROUP_TOPOLOGY and/or GROUP_CONNECTIVITY if ((bSkipBankGrouping == false) && (xclBin.findSection(ASK_GROUP_TOPOLOGY) == nullptr) && diff --git a/src/runtime_src/tools/xclbinutil/XclBinUtilities.cxx b/src/runtime_src/tools/xclbinutil/XclBinUtilities.cxx index f493004256f..c4c2712c67a 100644 --- a/src/runtime_src/tools/xclbinutil/XclBinUtilities.cxx +++ b/src/runtime_src/tools/xclbinutil/XclBinUtilities.cxx @@ -32,6 +32,7 @@ #include #include #include +#include #if (BOOST_VERSION >= 106400) @@ -908,8 +909,48 @@ transformMemoryBankGroupingCollections(const std::vector allDpuKernelIDs; + Section *pAIEPartition = xclbin.findSection(AIE_PARTITION); + std::string jsonFile = pAIEPartition->getPathAndName(); + boost::property_tree::ptree pt; + boost::property_tree::read_json(jsonFile, pt); + const boost::property_tree::ptree& ptAIEPartition = pt.get_child("aie_partition"); + std::vector ptPDIs = XUtil::as_vector(ptAIEPartition, "PDIs"); + for (const auto& pdi : ptPDIs) { + std::vector ptCDOs = XUtil::as_vector(pdi, "cdo_groups"); + for (const auto& cdo_group : ptCDOs) { + std::vector dpuKernelIDs = XUtil::as_vector_simple(cdo_group, "dpu_kernel_ids"); + allDpuKernelIDs.insert(dpuKernelIDs.begin(), dpuKernelIDs.end()); + } + } + + // Get IP_LAYOUT metadata + Section *pIPLayout = xclbin.findSection(IP_LAYOUT); + boost::property_tree::ptree ptIPLayout; + pIPLayout->getPayload(ptIPLayout); + boost::property_tree::ptree ptIPlayout = ptIPLayout.get_child("ip_layout"); + boost::property_tree::ptree ipDatas = ptIPlayout.get_child("m_ip_data"); + for (const auto& element : ipDatas) { + boost::property_tree::ptree ptIPData = element.second; + std::string sm_type = ptIPData.get("m_type"); + std::string sSubType = ptIPData.get("m_subtype", ""); + // Check if each m_kernel_id is present in the set of all dpu_kernel_ids + if(sm_type == "IP_PS_KERNEL" && sSubType == "DPU"){ + std::string sKernelId = ptIPData.get("m_kernel_id", ""); + if(allDpuKernelIDs.find(sKernelId) == allDpuKernelIDs.end()){ + XUtil::TRACE("There is no matching dpu_kernel_id in AIE_PARTITION for m_kernel_id " + sKernelId + " in IP_LAYOUT"); + return false; + } + } + } + return true; +} void XclBinUtilities::createMemoryBankGrouping(XclBin & xclbin) diff --git a/src/runtime_src/tools/xclbinutil/XclBinUtilities.h b/src/runtime_src/tools/xclbinutil/XclBinUtilities.h index e405fe8b9e3..efe065e086b 100644 --- a/src/runtime_src/tools/xclbinutil/XclBinUtilities.h +++ b/src/runtime_src/tools/xclbinutil/XclBinUtilities.h @@ -166,6 +166,7 @@ std::string getUUIDAsString( const unsigned char (&_uuid)[16] ); int exec(const std::filesystem::path &cmd, const std::vector &args, bool bThrow, std::ostringstream & os_stdout, std::ostringstream & os_stderr); void write_htonl(std::ostream & _buf, uint32_t _word32); +bool checkAIEPartitionIPLayoutCompliance(XclBin & xclbin); void createMemoryBankGrouping(XclBin & xclbin); // temporary for 2024.1, https://jira.xilinx.com/browse/SDXFLO-6890