Skip to content

Commit

Permalink
Support context/queue in KDS (Xilinx#1731)
Browse files Browse the repository at this point in the history
Add support for context / queue feature in KDS.

Add exec_write method to specify context.

Modify exec_write to use CU offset rather than global offset, this is
a breaking change.

Reserve exec_write payload [0..6] corresponding to 0x0..0x14 for CU
control so that addr,value pair starts at 0x18.  0x10 and 0x14 are for
context in/out and are used if and only if kernel enables context feature.
  • Loading branch information
stsoe authored Aug 7, 2019
1 parent 20b7e59 commit 90e5f68
Show file tree
Hide file tree
Showing 7 changed files with 370 additions and 66 deletions.
11 changes: 9 additions & 2 deletions src/runtime_src/core/common/config_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ get_ert_slotsize()
inline bool
get_cdma()
{
static unsigned int value = detail::get_bool_value("Runtime.cdma",true);
static bool value = detail::get_bool_value("Runtime.cdma",true);
return value;
}

Expand Down Expand Up @@ -334,6 +334,13 @@ get_sw_em_driver()
return value;
}

}}
inline std::string
get_ctx_info()
{
static std::string value = detail::get_string_value("Runtime.ctx_info","");
return value;
}

}} // config,xrt_core

#endif
41 changes: 37 additions & 4 deletions src/runtime_src/core/common/xclbin_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

#include "xclbin_parser.h"
#include "config_reader.h"

// This is xclbin parser. Update this file if xclbin format has changed.

Expand Down Expand Up @@ -46,6 +47,33 @@ get_base_addr(const ip_data& ip)
return addr;
}

static int
kernel_max_ctx(const ip_data& ip)
{
auto ctx = xrt_core::config::get_ctx_info();
if (ctx.empty())
return 0;

std::string knm = reinterpret_cast<const char*>(ip.m_name);
knm = knm.substr(0,knm.find(":"));

auto pos1 = ctx.find("{"+knm+":");
if (pos1 == std::string::npos)
return 0;

auto pos2 = ctx.find("}",pos1);
if (pos2 == std::string::npos || pos2 < pos1+knm.size()+2)
return 0;

auto ctxid_str = ctx.substr(pos1+knm.size()+2,pos2);
auto ctxid = std::stoi(ctxid_str);

if (ctxid < 0 || ctxid > 31)
throw std::runtime_error("context id must be between 0 and 31");

return ctxid;
}

}

namespace xrt_core { namespace xclbin {
Expand All @@ -64,7 +92,7 @@ memidx_to_name(const axlf* top, int32_t midx)
}

std::vector<uint64_t>
get_cus(const axlf* top, bool encoding)
get_cus(const axlf* top, bool encode)
{
std::vector<uint64_t> cus;
auto ip_layout = axlf_section_type<const ::ip_layout*>::get(top,axlf_section_kind::IP_LAYOUT);
Expand All @@ -75,9 +103,14 @@ get_cus(const axlf* top, bool encoding)
const auto& ip_data = ip_layout->m_ip_data[count];
if (is_valid_cu(ip_data)) {
uint64_t addr = get_base_addr(ip_data);
if (encoding)
// encode handshaking control in lower unused address bits
addr |= ((ip_data.properties & IP_CONTROL_MASK) >> IP_CONTROL_SHIFT);
if (encode) {
// encode handshaking control in lower unused address bits [2-0]
addr |= ((ip_data.properties & IP_CONTROL_MASK) >> IP_CONTROL_SHIFT);

// encode max context in lower [7-3] bits of addr, assumes IP control
// takes three bits only. This is a hack for now.
addr |= (kernel_max_ctx(ip_data) << 3);
}
cus.push_back(addr);
}
}
Expand Down
Loading

0 comments on commit 90e5f68

Please sign in to comment.