Skip to content

Commit b2bdd12

Browse files
committed
Address review comments
1 parent 0c30be7 commit b2bdd12

File tree

3 files changed

+57
-30
lines changed

3 files changed

+57
-30
lines changed

include/acl.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -480,11 +480,10 @@ typedef class acl_device_program_info_t *acl_device_program_info;
480480
#define ACL_MEM_CAPABILITY_P2P (1 << 3)
481481

482482
// Definition of device global.
483-
typedef struct acl_device_global_mem_def_t {
484-
std::string name;
483+
struct acl_device_global_mem_def_t {
485484
unsigned int address;
486-
unsigned int size;
487-
} acl_device_global_mem_def_t;
485+
uint32_t size;
486+
};
488487

489488
// Part of acl_device_def_t where members are populated from the information
490489
// in the autodiscovery string. This will get updated every time the device

src/acl_auto_configure.cpp

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,25 @@ static bool read_uint_counters(const std::string &str,
9999
return true;
100100
}
101101

102+
// Reads the next word in str and converts it into an unsigned.
103+
// Returns true if a valid integer was read or false if an error occurred.
104+
// pos is updated to the position immediately following the parsed word
105+
// even if an error occurs.
106+
static bool read_uint32_counters(const std::string &str,
107+
std::string::size_type &pos, uint32_t &val,
108+
std::vector<int> &counters) noexcept {
109+
std::string result;
110+
pos = read_word(str, pos, result);
111+
decrement_section_counters(counters);
112+
try {
113+
val = static_cast<uint32_t>(std::stoul(result));
114+
} catch (const std::exception &e) {
115+
UNREFERENCED_PARAMETER(e);
116+
return false;
117+
}
118+
return true;
119+
}
120+
102121
// Reads the next word in str and converts it into an unsigned.
103122
// Returns true if a valid integer was read or false if an error occurred.
104123
// pos is updated to the position immediately following the parsed word
@@ -501,10 +520,10 @@ bool acl_load_device_def_from_str(const std::string &config_str,
501520
devdef.num_device_global = num_device_global;
502521

503522
// read total number of fields in device global
504-
int total_fields_device_global = 0;
523+
unsigned int total_fields_device_global = 0;
505524
if (result) {
506-
result = read_int_counters(config_str, curr_pos,
507-
total_fields_device_global, counters);
525+
result = read_uint_counters(config_str, curr_pos,
526+
total_fields_device_global, counters);
508527
}
509528

510529
for (auto i = 0U; result && (i < num_device_global);
@@ -525,18 +544,27 @@ bool acl_load_device_def_from_str(const std::string &config_str,
525544
read_uint_counters(config_str, curr_pos, dev_global_addr, counters);
526545
}
527546
// read device global address size
528-
unsigned int dev_global_size = 0; // Default
547+
uint32_t dev_global_size = 0; // Default
529548
if (result && counters.back() > 0) {
530-
result =
531-
read_uint_counters(config_str, curr_pos, dev_global_size, counters);
549+
result = read_uint32_counters(config_str, curr_pos, dev_global_size,
550+
counters);
532551
}
533552

534-
acl_device_global_mem_def_t dev_global_def = {
535-
device_global_name, dev_global_addr, dev_global_size};
536-
devdef.device_global_mem_defs[device_global_name] = dev_global_def;
553+
acl_device_global_mem_def_t dev_global_def = {dev_global_addr,
554+
dev_global_size};
555+
bool ok = devdef.device_global_mem_defs
556+
.insert({device_global_name, dev_global_def})
557+
.second;
558+
if (!ok) {
559+
// Device global name already exist in map, but it should have been
560+
// unique.
561+
err_ss << "Device global name should be unique. " << device_global_name
562+
<< " is repeated.\n";
563+
result = false;
564+
}
537565

538-
// forward compatibility: bypassing remaining fields at the end of global
539-
// memory
566+
// forward compatibility: bypassing remaining fields at the end of device
567+
// global memory
540568
while (result && counters.size() > 0 &&
541569
counters.back() > 0) { // total_fields_device_global>0
542570
std::string tmp;

test/acl_auto_configure_test.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -270,25 +270,25 @@ TEST(auto_configure, simple) {
270270
CHECK_EQUAL(1, (int)m_device_def.autodiscovery_def.accel[0].is_sycl_compile);
271271

272272
// Checks for device global entry.
273-
CHECK_EQUAL(2, (int)m_device_def.autodiscovery_def.num_device_global);
273+
CHECK_EQUAL(2, m_device_def.autodiscovery_def.num_device_global);
274274
CHECK(m_device_def.autodiscovery_def.device_global_mem_defs.find(
275275
"kernel15_dev_global") !=
276276
m_device_def.autodiscovery_def.device_global_mem_defs.end());
277277
CHECK(m_device_def.autodiscovery_def.device_global_mem_defs.find(
278278
"kernel15_dev_global2") !=
279279
m_device_def.autodiscovery_def.device_global_mem_defs.end());
280-
CHECK_EQUAL(4096, m_device_def.autodiscovery_def
281-
.device_global_mem_defs["kernel15_dev_global"]
282-
.address);
283-
CHECK_EQUAL(2048, m_device_def.autodiscovery_def
284-
.device_global_mem_defs["kernel15_dev_global"]
285-
.size);
286-
CHECK_EQUAL(2048, m_device_def.autodiscovery_def
287-
.device_global_mem_defs["kernel15_dev_global2"]
288-
.address);
289-
CHECK_EQUAL(1024, m_device_def.autodiscovery_def
290-
.device_global_mem_defs["kernel15_dev_global2"]
291-
.size);
280+
CHECK_EQUAL(4096, m_device_def.autodiscovery_def.device_global_mem_defs
281+
.find("kernel15_dev_global")
282+
->second.address);
283+
CHECK_EQUAL(2048, m_device_def.autodiscovery_def.device_global_mem_defs
284+
.find("kernel15_dev_global")
285+
->second.size);
286+
CHECK_EQUAL(2048, m_device_def.autodiscovery_def.device_global_mem_defs
287+
.find("kernel15_dev_global2")
288+
->second.address);
289+
CHECK_EQUAL(1024, m_device_def.autodiscovery_def.device_global_mem_defs
290+
.find("kernel15_dev_global2")
291+
->second.size);
292292

293293
// Check a second parsing.
294294
// It should allocate a new string for the name.
@@ -490,7 +490,7 @@ TEST(auto_configure, many_ok_forward_compatibility) {
490490
"sample40byterandomhash000000000000000000 "
491491
"a10gx 0 1 15 DDR 2 1 6 0 2147483648 100 "
492492
"100 100 100 200 200 200 200 0 0 0 0 2 "
493-
"1 1 1 400 47 "
493+
"1 name1 1 name2 47 "
494494
"40 external_sort_stage_0 0 128 1 0 0 1 0 "
495495
"1 0 1 10 0 0 4 1 0 0 500 500 500 500 0 0 "
496496
"0 0 1 1 1 3 1 1 1 3 1 800 800 800 800 800 "
@@ -1204,7 +1204,7 @@ TEST(auto_configure, hostpipe) {
12041204
"200 "
12051205
"2 9 host_to_dev 1 0 32 32768 300 300 300 "
12061206
"300 dev_to_host 0 1 32 32768 300 300 300 "
1207-
"300 400 1 3 400 400 0 "
1207+
"300 400 1 3 name3 400 0 "
12081208
"1 29 foo 0 128 1 0 0 1 0 1 0 0 0 0 0 0 1 "
12091209
"1 1 3 1 1 1 3 1 800 800 800 800 800 900 "
12101210
"900"

0 commit comments

Comments
 (0)