Skip to content

Commit 6f3b97f

Browse files
committed
Factor out function for auto-discovery parsing of device global definition
1 parent e1cc1f4 commit 6f3b97f

File tree

1 file changed

+62
-48
lines changed

1 file changed

+62
-48
lines changed

src/acl_auto_configure.cpp

Lines changed: 62 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,64 @@ read_system_global_mem_def(const std::string &config_str,
364364
return result;
365365
}
366366

367+
static bool read_device_global_mem_def(
368+
const std::string &config_str, std::string::size_type &curr_pos,
369+
const unsigned int total_fields_device_global,
370+
std::unordered_map<std::string, acl_device_global_mem_def_t>
371+
&device_global_mem_defs,
372+
std::vector<int> &counters, std::string &err_str) noexcept {
373+
bool result = true;
374+
375+
counters.emplace_back(total_fields_device_global);
376+
377+
// read device global name
378+
std::string device_global_name;
379+
if (result && counters.back() > 0) {
380+
result = read_string_counters(config_str, curr_pos, device_global_name,
381+
counters);
382+
}
383+
384+
// read device global address
385+
uint32_t dev_global_addr = 0; // Default
386+
if (result && counters.back() > 0) {
387+
result =
388+
read_uint32_counters(config_str, curr_pos, dev_global_addr, counters);
389+
}
390+
// read device global address size
391+
uint32_t dev_global_size = 0; // Default
392+
if (result && counters.back() > 0) {
393+
result =
394+
read_uint32_counters(config_str, curr_pos, dev_global_size, counters);
395+
}
396+
397+
acl_device_global_mem_def_t dev_global_def = {dev_global_addr,
398+
dev_global_size};
399+
bool ok = device_global_mem_defs.insert({device_global_name, dev_global_def})
400+
.second;
401+
if (!ok) {
402+
// Device global name already exist in map, but it should have been
403+
// unique.
404+
std::stringstream err_ss;
405+
err_ss << "Device global name should be unique. " << device_global_name
406+
<< " is repeated.\n";
407+
err_str = err_ss.str();
408+
result = false;
409+
}
410+
411+
// forward compatibility: bypassing remaining fields at the end of device
412+
// global memory
413+
while (result && counters.size() > 0 &&
414+
counters.back() > 0) { // total_fields_device_global>0
415+
std::string tmp;
416+
result =
417+
result && read_string_counters(config_str, curr_pos, tmp, counters);
418+
check_section_counters(counters);
419+
}
420+
counters.pop_back(); // removing total_fields_device_global
421+
422+
return result;
423+
}
424+
367425
static bool read_kernel_arg_info(const std::string &config_str,
368426
const bool kernel_arg_info_available,
369427
std::string::size_type &curr_pos,
@@ -657,54 +715,10 @@ bool acl_load_device_def_from_str(const std::string &config_str,
657715

658716
for (auto i = 0U; result && (i < num_device_global);
659717
i++) { // device_global_memories
660-
counters.emplace_back(total_fields_device_global);
661-
662-
// read device global name
663-
std::string device_global_name;
664-
if (result && counters.back() > 0) {
665-
result = read_string_counters(config_str, curr_pos, device_global_name,
666-
counters);
667-
}
668-
669-
// read device global address
670-
uint32_t dev_global_addr = 0; // Default
671-
if (result && counters.back() > 0) {
672-
result = read_uint32_counters(config_str, curr_pos, dev_global_addr,
673-
counters);
674-
}
675-
// read device global address size
676-
uint32_t dev_global_size = 0; // Default
677-
if (result && counters.back() > 0) {
678-
result = read_uint32_counters(config_str, curr_pos, dev_global_size,
679-
counters);
680-
}
681-
682-
acl_device_global_mem_def_t dev_global_def = {dev_global_addr,
683-
dev_global_size};
684-
bool ok = devdef.device_global_mem_defs
685-
.insert({device_global_name, dev_global_def})
686-
.second;
687-
if (!ok) {
688-
// Device global name already exist in map, but it should have been
689-
// unique.
690-
std::stringstream err_ss;
691-
err_ss << "Device global name should be unique. " << device_global_name
692-
<< " is repeated.\n";
693-
err_str = err_ss.str();
694-
result = false;
695-
}
696-
697-
// forward compatibility: bypassing remaining fields at the end of device
698-
// global memory
699-
while (result && counters.size() > 0 &&
700-
counters.back() > 0) { // total_fields_device_global>0
701-
std::string tmp;
702-
result =
703-
result && read_string_counters(config_str, curr_pos, tmp, counters);
704-
check_section_counters(counters);
705-
}
706-
counters.pop_back(); // removing total_fields_device_global
707-
} // device_global_memories
718+
read_device_global_mem_def(
719+
config_str, curr_pos, total_fields_device_global,
720+
devdef.device_global_mem_defs, counters, err_str);
721+
} // device_global_memories
708722
}
709723

710724
// forward compatibility: bypassing remaining fields at the end of device

0 commit comments

Comments
 (0)