From 840fe51450c07988f142077c4d5bfd15145d4fb3 Mon Sep 17 00:00:00 2001 From: Peter Colberg Date: Thu, 21 Apr 2022 22:18:43 -0400 Subject: [PATCH] Factor out function for auto-discovery parsing of kernel arguments --- src/acl_auto_configure.cpp | 236 +++++++++++++++++++------------------ 1 file changed, 122 insertions(+), 114 deletions(-) diff --git a/src/acl_auto_configure.cpp b/src/acl_auto_configure.cpp index 33bc7068..fd125193 100644 --- a/src/acl_auto_configure.cpp +++ b/src/acl_auto_configure.cpp @@ -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 &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(addr_space_type); + arg_info.access_qualifier = + static_cast(access_qualifier); + arg_info.category = static_cast(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(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 { @@ -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(addr_space_type); - devdef.accel[i].iface.args[j].access_qualifier = - static_cast(access_qualifier); - devdef.accel[i].iface.args[j].category = - static_cast(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(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