diff --git a/src/runtime_src/core/common/api/aie/xrt_graph.cpp b/src/runtime_src/core/common/api/aie/xrt_graph.cpp index 1f1dd1a9f05..a317677d7c9 100644 --- a/src/runtime_src/core/common/api/aie/xrt_graph.cpp +++ b/src/runtime_src/core/common/api/aie/xrt_graph.cpp @@ -13,6 +13,8 @@ #include "core/include/xrt/xrt_aie.h" #include "core/include/xrt/xrt_bo.h" #include "core/include/xrt/xrt_device.h" +#include "core/include/xrt/xrt_hw_context.h" +#include "core/include/xrt/experimental/xrt_xclbin.h" #include "core/include/xcl_graph.h" #include "core/common/api/device_int.h" @@ -116,6 +118,16 @@ class graph_impl { m_graphHandle->read_graph_rtp(port, buffer, size); } + + uint32_t + gmio_bank_id(const std::string& gmio_name) const + { + auto xclbin = hw_ctx.get_xclbin(); + if (!xclbin) + throw std::runtime_error("gmio_bank_id: graph has no hw_context with xclbin (create graph from hw_context)"); + int32_t mem_index = xclbin.get_gmio_mem_index(gmio_name); + return static_cast(mem_index); + } }; } @@ -354,6 +366,13 @@ get_timestamp() const return xdp::native::profiling_wrapper("xrt::graph::get_timestamp", [this]{return (handle->get_timestamp());}); } +uint32_t +graph:: +gmio_bank_id(const std::string& gmio_name) const +{ + return handle->gmio_bank_id(gmio_name); +} + void graph:: run(uint32_t iterations) diff --git a/src/runtime_src/core/common/api/xrt_kernel.cpp b/src/runtime_src/core/common/api/xrt_kernel.cpp index 68d5dea8032..4270bee69c8 100644 --- a/src/runtime_src/core/common/api/xrt_kernel.cpp +++ b/src/runtime_src/core/common/api/xrt_kernel.cpp @@ -1771,6 +1771,10 @@ class kernel_impl : public std::enable_shared_from_this xrt_core::hw_context_int::set_exclusive(hwctx); } + // AIE-only xclbins now have IP_LAYOUT; reject early with a clear message + if (auto axlf = xclbin.get_axlf(); axlf && xrt_core::xclbin::is_aie_only(axlf)) + throw xrt_core::error(ENOTSUP, "xrt::kernel cannot be opened for AIE-only xclbins."); + // Compare the matching CUs against the CU sort order to create cumask const auto& kernel_cus = xkernel.get_cus(nm); // xrt::xclbin::ip objects for matching nm if (kernel_cus.empty()) diff --git a/src/runtime_src/core/common/api/xrt_xclbin.cpp b/src/runtime_src/core/common/api/xrt_xclbin.cpp index fc857d6aa84..779d6c4259f 100644 --- a/src/runtime_src/core/common/api/xrt_xclbin.cpp +++ b/src/runtime_src/core/common/api/xrt_xclbin.cpp @@ -25,8 +25,10 @@ #include #include +#include #include #include +#include #include #include #include @@ -389,6 +391,7 @@ class xclbin_impl std::vector m_ips; std::vector m_kernels; std::vector m_aie_partitions; + std::map m_gmio_name_to_mem_index; // encoded / compressed memory connection used by // xrt core to manage compute unit connectivity. @@ -412,6 +415,34 @@ class xclbin_impl return mems; } + // Build gmio arg_name -> mem_data_index from the ai_engine kernel's connectivity. + static constexpr const char* aie_kernel_name = "ai_engine"; + + static std::map + init_gmio_connectivity(const xclbin_impl*, + const std::vector& kernels) + { + std::map gmio_name_to_mem_index; + for (const auto& kernel : kernels) { + if (kernel.get_name() != aie_kernel_name) + continue; + + for (const auto& arg : kernel.get_args()) { + auto arg_name = arg.get_name(); + if (arg_name.empty()) + continue; + for (const auto& mem : arg.get_mems()) { + auto it = gmio_name_to_mem_index.find(arg_name); + if (it == gmio_name_to_mem_index.end()) + gmio_name_to_mem_index[arg_name] = mem.get_index(); + else + it->second = std::max(it->second, mem.get_index()); + } + } + } + return gmio_name_to_mem_index; + } + // init_ips() - populate m_ips with xclbin::ip objects // // Iterate the IP_LAYOUT section in the xclbin and create @@ -578,6 +609,7 @@ class xclbin_impl , m_ips(init_ips(m_ximpl, m_mems)) , m_kernels(init_kernels(m_ximpl, m_ips)) , m_aie_partitions(init_aie_partitions(m_ximpl)) + , m_gmio_name_to_mem_index(init_gmio_connectivity(m_ximpl, m_kernels)) , m_membank_encoding(init_mem_encoding(m_mems)) {} }; @@ -747,6 +779,23 @@ class xclbin_impl { return get_xclbin_info()->m_aie_partitions; } + + int32_t + get_gmio_mem_index(const std::string& gmio_name) const + { + const auto* info = get_xclbin_info(); + auto it = info->m_gmio_name_to_mem_index.find(gmio_name); + if (it != info->m_gmio_name_to_mem_index.end()) + return it->second; + + std::string msg; + if (info->m_gmio_name_to_mem_index.empty()) + msg = "xclbin has no GMIO connectivity"; + else + msg = "No connectivity for GMIO port '" + gmio_name + "'"; + + throw std::runtime_error(msg); + } }; // class xclbin_full - Implementation of full xclbin @@ -1094,6 +1143,15 @@ get_aie_partitions() const return handle ? handle->get_aie_partitions() : std::vector{}; } +int32_t +xclbin:: +get_gmio_mem_index(const std::string& gmio_name) const +{ + if (!handle) + throw std::runtime_error("get_gmio_mem_index: empty xclbin"); + return handle->get_gmio_mem_index(gmio_name); +} + std::string xclbin:: get_xsa_name() const diff --git a/src/runtime_src/core/include/xrt/experimental/xrt_xclbin.h b/src/runtime_src/core/include/xrt/experimental/xrt_xclbin.h index 11e8cae8f17..8410ac81d0b 100644 --- a/src/runtime_src/core/include/xrt/experimental/xrt_xclbin.h +++ b/src/runtime_src/core/include/xrt/experimental/xrt_xclbin.h @@ -740,6 +740,18 @@ class xclbin : public detail::pimpl get_aie_partitions() const; /// @endcond + /** + * get_gmio_mem_index() - Get mem_data_index for a GMIO port. + * + * @param gmio_name + * GMIO port name (e.g. "in", "out", "gmioIn", "gmioOut"). + * @return + * mem_data_index to use as bank_id in xrt::aie::bo. + */ + XRT_API_EXPORT + int32_t + get_gmio_mem_index(const std::string& gmio_name) const; + /** * get_xsa_name() - Get Xilinx Support Archive (XSA) name of xclbin * diff --git a/src/runtime_src/core/include/xrt/xrt_graph.h b/src/runtime_src/core/include/xrt/xrt_graph.h index 3e5b9da0918..d56a9d53f4c 100644 --- a/src/runtime_src/core/include/xrt/xrt_graph.h +++ b/src/runtime_src/core/include/xrt/xrt_graph.h @@ -98,6 +98,17 @@ class graph uint64_t get_timestamp() const; + /** + * gmio_bank_id() - Get bank index for a GMIO port. + * + * @param gmio_name + * GMIO port name (e.g. "in", "out", "gmioIn", "gmioOut"). + * @return + * Bank index for xrt::aie::bo(hwctx, size, flags, bank_id). + */ + uint32_t + gmio_bank_id(const std::string& gmio_name) const; + /** * run() - Start graph execution. *