Skip to content

Commit

Permalink
Factor out function for auto-discovery parsing of kernel arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
pcolberg committed Apr 22, 2022
1 parent 02e5316 commit 840fe51
Showing 1 changed file with 122 additions and 114 deletions.
236 changes: 122 additions & 114 deletions src/acl_auto_configure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,125 @@ static int read_string_counters(const std::string &str,
return result != "";
}

static bool read_kernel_argument(const std::string &config_str,
bool kernel_arg_info_available,
std::string::size_type &curr_pos,
acl_kernel_arg_info_t &arg_info,
std::vector<int> &counters) noexcept {
bool result = true;
auto addr_space_type = 0U;
auto category = 0U;
auto size = 0U;
auto num_buffer_locations = 0U;
int total_fields_arguments = 0;
if (result) {
result = result && read_int_counters(config_str, curr_pos,
total_fields_arguments, counters);
}
counters.emplace_back(total_fields_arguments);
unsigned alignment = ACL_MEM_ALIGN; // Set default to 1024 bytes
result =
result &&
read_uint_counters(config_str, curr_pos, addr_space_type, counters) &&
read_uint_counters(config_str, curr_pos, category, counters) &&
read_uint_counters(config_str, curr_pos, size, counters);
if (result) {
result =
result && read_uint_counters(config_str, curr_pos, alignment, counters);
}

std::string buffer_location = "";
if (result) {
result = result && read_uint_counters(config_str, curr_pos,
num_buffer_locations, counters);
for (auto k = 0U; result && (k < num_buffer_locations); k++) {
if (k /* FIXME j */ > 0) {
buffer_location = buffer_location + " ";
}

result = result && read_string_counters(config_str, curr_pos,
buffer_location, counters);
}
}

// Only local mem contains the following params
auto aspace_id = 0U;
auto lmem_size_bytes = 0U;
if (result && (addr_space_type == ACL_ARG_ADDR_LOCAL)) {
result =
result &&
read_uint_counters(config_str, curr_pos, aspace_id, counters) &&
read_uint_counters(config_str, curr_pos, lmem_size_bytes, counters);
}

auto type_qualifier = 0U;
auto host_accessible = 0U;
std::string pipe_channel_id;
if (result) {
result = result &&
read_uint_counters(config_str, curr_pos, type_qualifier, counters);
if (result && (type_qualifier == ACL_ARG_TYPE_PIPE)) {
result = result && read_uint_counters(config_str, curr_pos,
host_accessible, counters);
if (result && host_accessible) {
result = result && read_string_counters(config_str, curr_pos,
pipe_channel_id, counters);
}
}
}

std::string name = "";
std::string type_name = "";
auto access_qualifier = 0U;
if (kernel_arg_info_available) {
if (result) {
result =
result &&
read_string_counters(config_str, curr_pos, name, counters) &&
read_string_counters(config_str, curr_pos, type_name, counters) &&
read_uint_counters(config_str, curr_pos, access_qualifier, counters);
}
if (type_name == "0")
type_name = "";
}

/*****************************************************************
Since the introduction of autodiscovery forwards-compatibility,
new entries for each kernel argument section start here.
****************************************************************/

if (result) {
arg_info.name = name;
arg_info.addr_space =
static_cast<acl_kernel_arg_addr_space_t>(addr_space_type);
arg_info.access_qualifier =
static_cast<acl_kernel_arg_access_qualifier_t>(access_qualifier);
arg_info.category = static_cast<acl_kernel_arg_category_t>(category);
arg_info.size = size;
arg_info.alignment = alignment;
arg_info.aspace_number = aspace_id;
arg_info.lmem_size_bytes = lmem_size_bytes;
arg_info.type_name = type_name;
arg_info.type_qualifier =
static_cast<acl_kernel_arg_type_qualifier_t>(type_qualifier);
arg_info.host_accessible = host_accessible;
arg_info.pipe_channel_id = pipe_channel_id;
arg_info.buffer_location = buffer_location;
}
// forward compatibility: bypassing remaining fields at the end of
// arguments section
while (result && counters.size() > 0 &&
counters.back() > 0) { // total_fields_arguments>0
std::string tmp;
result =
result && read_string_counters(config_str, curr_pos, tmp, counters);
check_section_counters(counters);
}
counters.pop_back();

return result;
}

bool acl_load_device_def_from_str(const std::string &config_str,
acl_device_def_autodiscovery_t &devdef,
std::string &err_str) noexcept {
Expand Down Expand Up @@ -682,121 +801,10 @@ bool acl_load_device_def_from_str(const std::string &config_str,
}

for (auto j = 0U; result && (j < num_args); j++) { // arguments
auto addr_space_type = 0U;
auto category = 0U;
auto size = 0U;
auto num_buffer_locations = 0U;
int total_fields_arguments = 0;
if (result) {
result =
result && read_int_counters(config_str, curr_pos,
total_fields_arguments, counters);
}
counters.emplace_back(total_fields_arguments);
unsigned alignment = ACL_MEM_ALIGN; // Set default to 1024 bytes
result = result &&
read_uint_counters(config_str, curr_pos, addr_space_type,
counters) &&
read_uint_counters(config_str, curr_pos, category, counters) &&
read_uint_counters(config_str, curr_pos, size, counters);
if (result) {
result = result && read_uint_counters(config_str, curr_pos, alignment,
counters);
}

std::string buffer_location = "";
if (result) {
result = result && read_uint_counters(config_str, curr_pos,
num_buffer_locations, counters);
for (auto k = 0U; result && (k < num_buffer_locations); k++) {
if (j > 0) {
buffer_location = buffer_location + " ";
}

result = result && read_string_counters(config_str, curr_pos,
buffer_location, counters);
}
}

// Only local mem contains the following params
auto aspace_id = 0U;
auto lmem_size_bytes = 0U;
if (result && (addr_space_type == ACL_ARG_ADDR_LOCAL)) {
result =
result &&
read_uint_counters(config_str, curr_pos, aspace_id, counters) &&
read_uint_counters(config_str, curr_pos, lmem_size_bytes,
counters);
}

auto type_qualifier = 0U;
auto host_accessible = 0U;
std::string pipe_channel_id;
if (result) {
result = result && read_uint_counters(config_str, curr_pos,
type_qualifier, counters);
if (result && (type_qualifier == ACL_ARG_TYPE_PIPE)) {
result = result && read_uint_counters(config_str, curr_pos,
host_accessible, counters);
if (result && host_accessible) {
result =
result && read_string_counters(config_str, curr_pos,
pipe_channel_id, counters);
}
}
}
result = result && read_kernel_argument(
config_str, kernel_arg_info_available, curr_pos,
devdef.accel[i].iface.args[j], counters);

std::string name = "";
std::string type_name = "";
auto access_qualifier = 0U;
if (kernel_arg_info_available) {
if (result) {
result =
result &&
read_string_counters(config_str, curr_pos, name, counters) &&
read_string_counters(config_str, curr_pos, type_name,
counters) &&
read_uint_counters(config_str, curr_pos, access_qualifier,
counters);
}
if (type_name == "0")
type_name = "";
}

/*****************************************************************
Since the introduction of autodiscovery forwards-compatibility,
new entries for each kernel argument section start here.
****************************************************************/

if (result) {
devdef.accel[i].iface.args[j].name = name;
devdef.accel[i].iface.args[j].addr_space =
static_cast<acl_kernel_arg_addr_space_t>(addr_space_type);
devdef.accel[i].iface.args[j].access_qualifier =
static_cast<acl_kernel_arg_access_qualifier_t>(access_qualifier);
devdef.accel[i].iface.args[j].category =
static_cast<acl_kernel_arg_category_t>(category);
devdef.accel[i].iface.args[j].size = size;
devdef.accel[i].iface.args[j].alignment = alignment;
devdef.accel[i].iface.args[j].aspace_number = aspace_id;
devdef.accel[i].iface.args[j].lmem_size_bytes = lmem_size_bytes;
devdef.accel[i].iface.args[j].type_name = type_name;
devdef.accel[i].iface.args[j].type_qualifier =
static_cast<acl_kernel_arg_type_qualifier_t>(type_qualifier);
devdef.accel[i].iface.args[j].host_accessible = host_accessible;
devdef.accel[i].iface.args[j].pipe_channel_id = pipe_channel_id;
devdef.accel[i].iface.args[j].buffer_location = buffer_location;
}
// forward compatibility: bypassing remaining fields at the end of
// arguments section
while (result && counters.size() > 0 &&
counters.back() > 0) { // total_fields_arguments>0
std::string tmp;
result = result &&
read_string_counters(config_str, curr_pos, tmp, counters);
check_section_counters(counters);
}
counters.pop_back();
} // arguments

// Get the number of printf format strings
Expand Down

0 comments on commit 840fe51

Please # to comment.