Skip to content

Commit ccba323

Browse files
pcolbergzibaiwan
authored andcommitted
Parse logical to physical host-pipe mappings from auto-discovery string
1 parent 0f8829f commit ccba323

File tree

3 files changed

+143
-0
lines changed

3 files changed

+143
-0
lines changed

include/acl.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,14 @@ struct acl_device_global_mem_def_t {
524524
bool reset_on_reuse;
525525
};
526526

527+
// Mapping of logical to physical host pipes.
528+
struct acl_hostpipe_mapping {
529+
std::string logical_name;
530+
std::string physical_name;
531+
bool implement_in_csr;
532+
uintptr_t csr_address;
533+
};
534+
527535
// Part of acl_device_def_t where members are populated from the information
528536
// in the autodiscovery string. This will get updated every time the device
529537
// is programmed with a new device binary as the new binary would contain a
@@ -548,6 +556,8 @@ typedef struct acl_device_def_autodiscovery_t {
548556
device_global_mem_defs;
549557
bool cra_ring_root_exist =
550558
true; // Set the default value to true for backwards compatibility flows.
559+
560+
std::vector<acl_hostpipe_mapping> hostpipe_mappings;
551561
} acl_device_def_autodiscovery_t;
552562

553563
typedef struct acl_device_def_t {

src/acl_auto_configure.cpp

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,36 @@ static bool read_ulonglong_counters(const std::string &str,
198198
return true;
199199
}
200200

201+
// Reads the next word in str and converts it into a uintptr_t.
202+
// Returns true if a valid integer was read or false if an error occurred.
203+
// pos is updated to the position immediately following the parsed word
204+
// even if an error occurs.
205+
static bool read_uintptr_counters(const std::string &str,
206+
std::string::size_type &pos, uintptr_t &val,
207+
std::vector<int> &counters) noexcept {
208+
std::string result;
209+
pos = read_word(str, pos, result);
210+
decrement_section_counters(counters);
211+
212+
size_t end = 0;
213+
unsigned long long parsed;
214+
try {
215+
parsed = std::stoull(result, &end);
216+
} catch (const std::exception &) {
217+
return false;
218+
}
219+
if (end != result.size()) {
220+
return false;
221+
}
222+
223+
val = static_cast<uintptr_t>(parsed);
224+
if (val != parsed) {
225+
return false;
226+
}
227+
228+
return true;
229+
}
230+
201231
// Reads the next word in str and converts it into an unsigned or using its
202232
// default value. Returns true if a valid integer was read or false if an error
203233
// occurred. pos is updated to the position immediately following the parsed
@@ -593,6 +623,44 @@ static bool read_streaming_kernel_arg_info(
593623
result = read_string_counters(config_str, curr_pos,
594624
streaming_arg_info.interface_name, counters);
595625
}
626+
return result;
627+
}
628+
629+
static bool read_hostpipe_mappings(
630+
const std::string &config_str, std::string::size_type &curr_pos,
631+
std::vector<acl_hostpipe_mapping> &hostpipe_mappings,
632+
std::vector<int> &counters, std::string &err_str) noexcept {
633+
unsigned int num_mappings = 0;
634+
bool result =
635+
read_uint_counters(config_str, curr_pos, num_mappings, counters);
636+
637+
unsigned int num_fields_per_mapping = 0;
638+
if (result) {
639+
result = read_uint_counters(config_str, curr_pos, num_fields_per_mapping,
640+
counters);
641+
}
642+
643+
for (unsigned int i = 0; result && (i < num_mappings); i++) {
644+
counters.emplace_back(num_fields_per_mapping);
645+
646+
acl_hostpipe_mapping mapping{};
647+
result = read_string_counters(config_str, curr_pos, mapping.logical_name,
648+
counters) &&
649+
read_string_counters(config_str, curr_pos, mapping.physical_name,
650+
counters) &&
651+
read_bool_counters(config_str, curr_pos, mapping.implement_in_csr,
652+
counters) &&
653+
read_uintptr_counters(config_str, curr_pos, mapping.csr_address,
654+
counters);
655+
hostpipe_mappings.emplace_back(mapping);
656+
657+
while (result && counters.back() > 0) {
658+
std::string tmp;
659+
result = read_string_counters(config_str, curr_pos, tmp, counters);
660+
}
661+
check_section_counters(counters);
662+
counters.pop_back();
663+
}
596664

597665
return result;
598666
}
@@ -1129,6 +1197,11 @@ bool acl_load_device_def_from_str(const std::string &config_str,
11291197
if (result && counters.back() > 0) {
11301198
result = read_bool_counters(config_str, curr_pos,
11311199
devdef.cra_ring_root_exist, counters);
1200+
1201+
// Read program scoped hostpipes mappings
1202+
if (result && counters.back() > 0) {
1203+
result = read_hostpipe_mappings(
1204+
config_str, curr_pos, devdef.hostpipe_mappings, counters, err_str);
11321205
}
11331206

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

test/acl_auto_configure_test.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,3 +1487,63 @@ TEST(auto_configure, cra_ring_root_exist) {
14871487

14881488
CHECK_EQUAL(1, devdef.cra_ring_root_exist);
14891489
}
1490+
1491+
// Will finalize later, Zibai todo.
1492+
1493+
// TEST(auto_configure, hostpipe_mappings) {
1494+
// const std::string config_str{
1495+
// "23 45 " RANDOM_HASH
1496+
// " pac_a10 0 1 13 DDR 2 2 24 1 2 0 4294967296 4294967296 8589934592 0 - 0 "
1497+
// "0 0 0 0 0 5 4 pipe_logical_name1 pipe_physical_name1 1 12345 "
1498+
// "pipe_logical_name2 pipe_physical_name2 0 12323 pipe_logical_name3 "
1499+
// "pipe_physical_name1 1 12313 pipe_logical_name1 pipe_physical_name1 0 "
1500+
// "12316 pipe_logical_name1 pipe_physical_name3 0 12342 3 90 "
1501+
// "_ZTS3CRCILi0EE 512 256 1 0 0 1 0 1 0 9 6 0 0 8 1 0 0 6 2 1 8 1024 0 3 6 "
1502+
// "0 0 8 1 0 0 6 0 0 8 1 0 0 6 0 0 8 1 0 0 6 2 1 8 1024 0 2 6 0 0 8 1 0 0 "
1503+
// "6 0 0 8 1 0 0 6 0 0 8 1 0 0 0 0 1 2 64 4096 1 1 1 3 1 1 1 3 1 0 64 "
1504+
// "_ZTS11LZReductionILi0EE 0 256 1 0 0 0 0 1 0 5 6 0 0 8 1 0 0 6 2 1 8 "
1505+
// "1024 0 3 6 0 0 8 1 0 0 6 0 0 8 1 0 0 6 0 0 8 1 0 0 0 0 2 2 64 131072 65 "
1506+
// "32768 1 1 1 3 1 1 1 3 1 0 125 _ZTS13StaticHuffmanILi0EE 256 256 1 0 0 1 "
1507+
// "0 1 0 10 6 0 0 8 1 0 0 6 0 0 4 1 0 0 6 2 1 8 1024 0 2 6 0 0 8 1 0 0 6 0 "
1508+
// "0 8 1 0 0 6 0 0 8 1 0 0 6 2 1 8 1024 0 2 6 0 0 8 1 0 0 6 0 0 8 1 0 0 6 "
1509+
// "0 0 8 1 0 0 0 0 15 2 64 116 65 116 66 1152 67 512 68 256 69 120 70 120 "
1510+
// "71 1152 72 116 73 1152 74 512 75 256 76 120 77 120 78 1152 1 1 1 3 1 1 "
1511+
// "1 3 1 0"};
1512+
1513+
// acl_device_def_autodiscovery_t devdef;
1514+
// {
1515+
// bool result;
1516+
// std::string err_str;
1517+
// ACL_LOCKED(result =
1518+
// acl_load_device_def_from_str(config_str, devdef, err_str));
1519+
// std::cerr << err_str;
1520+
// CHECK(result);
1521+
// }
1522+
1523+
// CHECK_EQUAL(5, devdef.hostpipe_mappings.size());
1524+
1525+
// CHECK(devdef.hostpipe_mappings[0].logical_name == "pipe_logical_name1");
1526+
// CHECK(devdef.hostpipe_mappings[0].physical_name == "pipe_physical_name1");
1527+
// CHECK(devdef.hostpipe_mappings[0].implement_in_csr);
1528+
// CHECK(devdef.hostpipe_mappings[0].csr_address == 12345);
1529+
1530+
// CHECK(devdef.hostpipe_mappings[1].logical_name == "pipe_logical_name2");
1531+
// CHECK(devdef.hostpipe_mappings[1].physical_name == "pipe_physical_name2");
1532+
// CHECK(!devdef.hostpipe_mappings[1].implement_in_csr);
1533+
// CHECK(devdef.hostpipe_mappings[1].csr_address == 12323);
1534+
1535+
// CHECK(devdef.hostpipe_mappings[2].logical_name == "pipe_logical_name3");
1536+
// CHECK(devdef.hostpipe_mappings[2].physical_name == "pipe_physical_name1");
1537+
// CHECK(devdef.hostpipe_mappings[2].implement_in_csr);
1538+
// CHECK(devdef.hostpipe_mappings[2].csr_address == 12313);
1539+
1540+
// CHECK(devdef.hostpipe_mappings[3].logical_name == "pipe_logical_name1");
1541+
// CHECK(devdef.hostpipe_mappings[3].physical_name == "pipe_physical_name1");
1542+
// CHECK(!devdef.hostpipe_mappings[3].implement_in_csr);
1543+
// CHECK(devdef.hostpipe_mappings[3].csr_address == 12316);
1544+
1545+
// CHECK(devdef.hostpipe_mappings[4].logical_name == "pipe_logical_name1");
1546+
// CHECK(devdef.hostpipe_mappings[4].physical_name == "pipe_physical_name3");
1547+
// CHECK(!devdef.hostpipe_mappings[4].implement_in_csr);
1548+
// CHECK(devdef.hostpipe_mappings[4].csr_address == 12342);
1549+
// }

0 commit comments

Comments
 (0)