From cfec0af860b52f51092a4a1024294d3f27afff15 Mon Sep 17 00:00:00 2001 From: Ch Vamshi Krishna <40261882+chvamshi-xilinx@users.noreply.github.com> Date: Tue, 15 Oct 2024 01:32:13 +0530 Subject: [PATCH] aie overlay load xclbin issue: Load xclbin even if xclbin doesnt have EMBEDDED_METADATA section (#8527) * dont throw an exception if there are no PL Kernels * load xclbin if it doesnt have embedded metadata Signed-off-by: ch vamshi krishna --------- Signed-off-by: ch vamshi krishna Co-authored-by: ch vamshi krishna --- src/runtime_src/core/edge/user/shim.cpp | 89 +++++++++++++------------ 1 file changed, 47 insertions(+), 42 deletions(-) diff --git a/src/runtime_src/core/edge/user/shim.cpp b/src/runtime_src/core/edge/user/shim.cpp index a74a47b2e0..1326e3d81d 100644 --- a/src/runtime_src/core/edge/user/shim.cpp +++ b/src/runtime_src/core/edge/user/shim.cpp @@ -743,7 +743,8 @@ xclLoadAxlf(const axlf *buffer) axlf_obj.kds_cfg.polling = xrt_core::config::get_ert_polling(); std::vector krnl_binary; - if (!xrt_core::xclbin::is_aie_only(buffer)) { + auto xml_header = xclbin::get_axlf_section(buffer, axlf_section_kind::EMBEDDED_METADATA); + if (xml_header) { auto kernels = xrt_core::xclbin::get_kernels(buffer); /* Calculate size of kernels */ for (auto& kernel : kernels) { @@ -1236,50 +1237,54 @@ int shim::prepare_hw_axlf(const axlf *buffer, struct drm_zocl_axlf *axlf_obj) axlf_obj->kds_cfg.polling = xrt_core::config::get_ert_polling(); std::vector krnl_binary; - if (!xrt_core::xclbin::is_aie_only(buffer)) { - auto kernels = xrt_core::xclbin::get_kernels(buffer); - /* Calculate size of kernels */ - for (auto& kernel : kernels) { - axlf_obj->za_ksize += sizeof(kernel_info) + sizeof(argument_info) * kernel.args.size(); - } - - /* Check PCIe's shim.cpp for details of kernels binary */ - krnl_binary.resize(axlf_obj->za_ksize); - axlf_obj->za_kernels = krnl_binary.data(); - for (auto& kernel : kernels) { - auto krnl = reinterpret_cast(axlf_obj->za_kernels + off); - if (kernel.name.size() > sizeof(krnl->name)) - return -EINVAL; - std::strncpy(krnl->name, kernel.name.c_str(), sizeof(krnl->name)-1); - krnl->name[sizeof(krnl->name)-1] = '\0'; - krnl->range = kernel.range; - krnl->anums = kernel.args.size(); - - krnl->features = 0; - if (kernel.sw_reset) - krnl->features |= KRNL_SW_RESET; - - int ai = 0; - for (auto& arg : kernel.args) { - if (arg.name.size() > sizeof(krnl->args[ai].name)) { - xclLog(XRT_ERROR, "%s: Argument name length %d>%d", __func__, arg.name.size(), sizeof(krnl->args[ai].name)); - return -EINVAL; - } - std::strncpy(krnl->args[ai].name, arg.name.c_str(), sizeof(krnl->args[ai].name)-1); - krnl->args[ai].name[sizeof(krnl->args[ai].name)-1] = '\0'; - krnl->args[ai].offset = arg.offset; - krnl->args[ai].size = arg.size; - // XCLBIN doesn't define argument direction yet and it only support - // input arguments. - // Driver use 1 for input argument and 2 for output. - // Let's refine this line later. - krnl->args[ai].dir = 1; - ai++; + auto xml_header = xclbin::get_axlf_section(buffer, axlf_section_kind::EMBEDDED_METADATA); + //return success even if there is no embedded metadata.AIE overlay xclbins + //wont have embedded metadata + if (!xml_header) + return 0; + auto kernels = xrt_core::xclbin::get_kernels(buffer); + /* Calculate size of kernels */ + for (auto& kernel : kernels) { + axlf_obj->za_ksize += sizeof(kernel_info) + sizeof(argument_info) * kernel.args.size(); + } + + /* Check PCIe's shim.cpp for details of kernels binary */ + krnl_binary.resize(axlf_obj->za_ksize); + axlf_obj->za_kernels = krnl_binary.data(); + for (auto& kernel : kernels) { + auto krnl = reinterpret_cast(axlf_obj->za_kernels + off); + if (kernel.name.size() > sizeof(krnl->name)) + return -EINVAL; + std::strncpy(krnl->name, kernel.name.c_str(), sizeof(krnl->name)-1); + krnl->name[sizeof(krnl->name)-1] = '\0'; + krnl->range = kernel.range; + krnl->anums = kernel.args.size(); + + krnl->features = 0; + if (kernel.sw_reset) + krnl->features |= KRNL_SW_RESET; + + int ai = 0; + for (auto& arg : kernel.args) { + if (arg.name.size() > sizeof(krnl->args[ai].name)) { + xclLog(XRT_ERROR, "%s: Argument name length %d>%d", __func__, arg.name.size(), sizeof(krnl->args[ai].name)); + return -EINVAL; } - off += sizeof(kernel_info) + sizeof(argument_info) * kernel.args.size(); + std::strncpy(krnl->args[ai].name, arg.name.c_str(), sizeof(krnl->args[ai].name)-1); + krnl->args[ai].name[sizeof(krnl->args[ai].name)-1] = '\0'; + krnl->args[ai].offset = arg.offset; + krnl->args[ai].size = arg.size; + // XCLBIN doesn't define argument direction yet and it only support + // input arguments. + // Driver use 1 for input argument and 2 for output. + // Let's refine this line later. + krnl->args[ai].dir = 1; + ai++; } + off += sizeof(kernel_info) + sizeof(argument_info) * kernel.args.size(); } - + + return 0; }