Skip to content

Commit 887666c

Browse files
committed
Factor out function for auto-discovery parsing of kernel arguments
1 parent 02e5316 commit 887666c

File tree

1 file changed

+122
-114
lines changed

1 file changed

+122
-114
lines changed

src/acl_auto_configure.cpp

Lines changed: 122 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,125 @@ static int read_string_counters(const std::string &str,
193193
return result != "";
194194
}
195195

196+
static bool read_kernel_arg_info(const std::string &config_str,
197+
bool kernel_arg_info_available,
198+
std::string::size_type &curr_pos,
199+
acl_kernel_arg_info_t &arg_info,
200+
std::vector<int> &counters) noexcept {
201+
bool result = true;
202+
auto addr_space_type = 0U;
203+
auto category = 0U;
204+
auto size = 0U;
205+
auto num_buffer_locations = 0U;
206+
int total_fields_arguments = 0;
207+
if (result) {
208+
result = result && read_int_counters(config_str, curr_pos,
209+
total_fields_arguments, counters);
210+
}
211+
counters.emplace_back(total_fields_arguments);
212+
unsigned alignment = ACL_MEM_ALIGN; // Set default to 1024 bytes
213+
result =
214+
result &&
215+
read_uint_counters(config_str, curr_pos, addr_space_type, counters) &&
216+
read_uint_counters(config_str, curr_pos, category, counters) &&
217+
read_uint_counters(config_str, curr_pos, size, counters);
218+
if (result) {
219+
result =
220+
result && read_uint_counters(config_str, curr_pos, alignment, counters);
221+
}
222+
223+
std::string buffer_location = "";
224+
if (result) {
225+
result = result && read_uint_counters(config_str, curr_pos,
226+
num_buffer_locations, counters);
227+
for (auto k = 0U; result && (k < num_buffer_locations); k++) {
228+
if (k /* FIXME j */ > 0) {
229+
buffer_location = buffer_location + " ";
230+
}
231+
232+
result = result && read_string_counters(config_str, curr_pos,
233+
buffer_location, counters);
234+
}
235+
}
236+
237+
// Only local mem contains the following params
238+
auto aspace_id = 0U;
239+
auto lmem_size_bytes = 0U;
240+
if (result && (addr_space_type == ACL_ARG_ADDR_LOCAL)) {
241+
result =
242+
result &&
243+
read_uint_counters(config_str, curr_pos, aspace_id, counters) &&
244+
read_uint_counters(config_str, curr_pos, lmem_size_bytes, counters);
245+
}
246+
247+
auto type_qualifier = 0U;
248+
auto host_accessible = 0U;
249+
std::string pipe_channel_id;
250+
if (result) {
251+
result = result &&
252+
read_uint_counters(config_str, curr_pos, type_qualifier, counters);
253+
if (result && (type_qualifier == ACL_ARG_TYPE_PIPE)) {
254+
result = result && read_uint_counters(config_str, curr_pos,
255+
host_accessible, counters);
256+
if (result && host_accessible) {
257+
result = result && read_string_counters(config_str, curr_pos,
258+
pipe_channel_id, counters);
259+
}
260+
}
261+
}
262+
263+
std::string name = "";
264+
std::string type_name = "";
265+
auto access_qualifier = 0U;
266+
if (kernel_arg_info_available) {
267+
if (result) {
268+
result =
269+
result &&
270+
read_string_counters(config_str, curr_pos, name, counters) &&
271+
read_string_counters(config_str, curr_pos, type_name, counters) &&
272+
read_uint_counters(config_str, curr_pos, access_qualifier, counters);
273+
}
274+
if (type_name == "0")
275+
type_name = "";
276+
}
277+
278+
/*****************************************************************
279+
Since the introduction of autodiscovery forwards-compatibility,
280+
new entries for each kernel argument section start here.
281+
****************************************************************/
282+
283+
if (result) {
284+
arg_info.name = name;
285+
arg_info.addr_space =
286+
static_cast<acl_kernel_arg_addr_space_t>(addr_space_type);
287+
arg_info.access_qualifier =
288+
static_cast<acl_kernel_arg_access_qualifier_t>(access_qualifier);
289+
arg_info.category = static_cast<acl_kernel_arg_category_t>(category);
290+
arg_info.size = size;
291+
arg_info.alignment = alignment;
292+
arg_info.aspace_number = aspace_id;
293+
arg_info.lmem_size_bytes = lmem_size_bytes;
294+
arg_info.type_name = type_name;
295+
arg_info.type_qualifier =
296+
static_cast<acl_kernel_arg_type_qualifier_t>(type_qualifier);
297+
arg_info.host_accessible = host_accessible;
298+
arg_info.pipe_channel_id = pipe_channel_id;
299+
arg_info.buffer_location = buffer_location;
300+
}
301+
// forward compatibility: bypassing remaining fields at the end of
302+
// arguments section
303+
while (result && counters.size() > 0 &&
304+
counters.back() > 0) { // total_fields_arguments>0
305+
std::string tmp;
306+
result =
307+
result && read_string_counters(config_str, curr_pos, tmp, counters);
308+
check_section_counters(counters);
309+
}
310+
counters.pop_back();
311+
312+
return result;
313+
}
314+
196315
bool acl_load_device_def_from_str(const std::string &config_str,
197316
acl_device_def_autodiscovery_t &devdef,
198317
std::string &err_str) noexcept {
@@ -682,121 +801,10 @@ bool acl_load_device_def_from_str(const std::string &config_str,
682801
}
683802

684803
for (auto j = 0U; result && (j < num_args); j++) { // arguments
685-
auto addr_space_type = 0U;
686-
auto category = 0U;
687-
auto size = 0U;
688-
auto num_buffer_locations = 0U;
689-
int total_fields_arguments = 0;
690-
if (result) {
691-
result =
692-
result && read_int_counters(config_str, curr_pos,
693-
total_fields_arguments, counters);
694-
}
695-
counters.emplace_back(total_fields_arguments);
696-
unsigned alignment = ACL_MEM_ALIGN; // Set default to 1024 bytes
697-
result = result &&
698-
read_uint_counters(config_str, curr_pos, addr_space_type,
699-
counters) &&
700-
read_uint_counters(config_str, curr_pos, category, counters) &&
701-
read_uint_counters(config_str, curr_pos, size, counters);
702-
if (result) {
703-
result = result && read_uint_counters(config_str, curr_pos, alignment,
704-
counters);
705-
}
706-
707-
std::string buffer_location = "";
708-
if (result) {
709-
result = result && read_uint_counters(config_str, curr_pos,
710-
num_buffer_locations, counters);
711-
for (auto k = 0U; result && (k < num_buffer_locations); k++) {
712-
if (j > 0) {
713-
buffer_location = buffer_location + " ";
714-
}
715-
716-
result = result && read_string_counters(config_str, curr_pos,
717-
buffer_location, counters);
718-
}
719-
}
720-
721-
// Only local mem contains the following params
722-
auto aspace_id = 0U;
723-
auto lmem_size_bytes = 0U;
724-
if (result && (addr_space_type == ACL_ARG_ADDR_LOCAL)) {
725-
result =
726-
result &&
727-
read_uint_counters(config_str, curr_pos, aspace_id, counters) &&
728-
read_uint_counters(config_str, curr_pos, lmem_size_bytes,
729-
counters);
730-
}
731-
732-
auto type_qualifier = 0U;
733-
auto host_accessible = 0U;
734-
std::string pipe_channel_id;
735-
if (result) {
736-
result = result && read_uint_counters(config_str, curr_pos,
737-
type_qualifier, counters);
738-
if (result && (type_qualifier == ACL_ARG_TYPE_PIPE)) {
739-
result = result && read_uint_counters(config_str, curr_pos,
740-
host_accessible, counters);
741-
if (result && host_accessible) {
742-
result =
743-
result && read_string_counters(config_str, curr_pos,
744-
pipe_channel_id, counters);
745-
}
746-
}
747-
}
804+
result = result && read_kernel_arg_info(
805+
config_str, kernel_arg_info_available, curr_pos,
806+
devdef.accel[i].iface.args[j], counters);
748807

749-
std::string name = "";
750-
std::string type_name = "";
751-
auto access_qualifier = 0U;
752-
if (kernel_arg_info_available) {
753-
if (result) {
754-
result =
755-
result &&
756-
read_string_counters(config_str, curr_pos, name, counters) &&
757-
read_string_counters(config_str, curr_pos, type_name,
758-
counters) &&
759-
read_uint_counters(config_str, curr_pos, access_qualifier,
760-
counters);
761-
}
762-
if (type_name == "0")
763-
type_name = "";
764-
}
765-
766-
/*****************************************************************
767-
Since the introduction of autodiscovery forwards-compatibility,
768-
new entries for each kernel argument section start here.
769-
****************************************************************/
770-
771-
if (result) {
772-
devdef.accel[i].iface.args[j].name = name;
773-
devdef.accel[i].iface.args[j].addr_space =
774-
static_cast<acl_kernel_arg_addr_space_t>(addr_space_type);
775-
devdef.accel[i].iface.args[j].access_qualifier =
776-
static_cast<acl_kernel_arg_access_qualifier_t>(access_qualifier);
777-
devdef.accel[i].iface.args[j].category =
778-
static_cast<acl_kernel_arg_category_t>(category);
779-
devdef.accel[i].iface.args[j].size = size;
780-
devdef.accel[i].iface.args[j].alignment = alignment;
781-
devdef.accel[i].iface.args[j].aspace_number = aspace_id;
782-
devdef.accel[i].iface.args[j].lmem_size_bytes = lmem_size_bytes;
783-
devdef.accel[i].iface.args[j].type_name = type_name;
784-
devdef.accel[i].iface.args[j].type_qualifier =
785-
static_cast<acl_kernel_arg_type_qualifier_t>(type_qualifier);
786-
devdef.accel[i].iface.args[j].host_accessible = host_accessible;
787-
devdef.accel[i].iface.args[j].pipe_channel_id = pipe_channel_id;
788-
devdef.accel[i].iface.args[j].buffer_location = buffer_location;
789-
}
790-
// forward compatibility: bypassing remaining fields at the end of
791-
// arguments section
792-
while (result && counters.size() > 0 &&
793-
counters.back() > 0) { // total_fields_arguments>0
794-
std::string tmp;
795-
result = result &&
796-
read_string_counters(config_str, curr_pos, tmp, counters);
797-
check_section_counters(counters);
798-
}
799-
counters.pop_back();
800808
} // arguments
801809

802810
// Get the number of printf format strings

0 commit comments

Comments
 (0)