Skip to content
Merged
19 changes: 19 additions & 0 deletions src/runtime_src/core/common/api/aie/xrt_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<uint32_t>(mem_index);
}
};

}
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions src/runtime_src/core/common/api/xrt_kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1771,6 +1771,10 @@ class kernel_impl : public std::enable_shared_from_this<kernel_impl>
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())
Expand Down
58 changes: 58 additions & 0 deletions src/runtime_src/core/common/api/xrt_xclbin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
#include <boost/algorithm/string.hpp>

#include <array>
#include <cstring>
#include <filesystem>
#include <fstream>
#include <map>
#include <numeric>
#include <regex>
#include <set>
Expand Down Expand Up @@ -389,6 +391,7 @@ class xclbin_impl
std::vector<xclbin::ip> m_ips;
std::vector<xclbin::kernel> m_kernels;
std::vector<xclbin::aie_partition> m_aie_partitions;
std::map<std::string, int32_t> m_gmio_name_to_mem_index;

// encoded / compressed memory connection used by
// xrt core to manage compute unit connectivity.
Expand All @@ -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<std::string, int32_t>
init_gmio_connectivity(const xclbin_impl*,
const std::vector<xclbin::kernel>& kernels)
{
std::map<std::string, int32_t> 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
Expand Down Expand Up @@ -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))
{}
};
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1094,6 +1143,15 @@ get_aie_partitions() const
return handle ? handle->get_aie_partitions() : std::vector<xclbin::aie_partition>{};
}

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
Expand Down
12 changes: 12 additions & 0 deletions src/runtime_src/core/include/xrt/experimental/xrt_xclbin.h
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,18 @@ class xclbin : public detail::pimpl<xclbin_impl>
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
*
Expand Down
11 changes: 11 additions & 0 deletions src/runtime_src/core/include/xrt/xrt_graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Loading