Skip to content

Commit 348c8a6

Browse files
committed
Skip CSR version check when cra_ring_root doesn't exist
1. Parse the new field from the auto-discovery string 2. Changed csr_version to be optional. 3.Skip csr version check if cra_ring_root doesn't exit. 4.Update the forward-compatibility auto-discovery string test. Note:previous test had an issue: The number of fields per device global is fixed (here to 1), not variable. I had to update that as well. 5.Add new unit tests.
1 parent aec4d87 commit 348c8a6

File tree

6 files changed

+118
-14
lines changed

6 files changed

+118
-14
lines changed

include/acl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,8 @@ typedef struct acl_device_def_autodiscovery_t {
526526
// Device global definition.
527527
std::unordered_map<std::string, acl_device_global_mem_def_t>
528528
device_global_mem_defs;
529+
bool cra_ring_root_exist =
530+
true; // Set the default value to true for backwards compatibility flows.
529531
} acl_device_def_autodiscovery_t;
530532

531533
typedef struct acl_device_def_t {

include/acl_kernel_if.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ typedef struct {
5050

5151
acl_bsp_io io;
5252

53-
unsigned int csr_version;
53+
// csr_version is absent if there is no accelerators or cra_ring_root doesn't
54+
// exist
55+
std::optional<unsigned int> csr_version;
5456

5557
// Depth of hardware kernel invocation queue
5658
unsigned int *accel_invoc_queue_depth;
@@ -69,7 +71,8 @@ int acl_kernel_if_init(acl_kernel_if *kern, acl_bsp_io bsp_io,
6971
int acl_kernel_if_update(const acl_device_def_autodiscovery_t &devdef,
7072
acl_kernel_if *kern);
7173
int acl_kernel_if_is_valid(acl_kernel_if *kern);
72-
int acl_kernel_if_post_pll_config_init(acl_kernel_if *kern);
74+
int acl_kernel_if_post_pll_config_init(bool cra_ring_root_exist,
75+
acl_kernel_if *kern);
7376

7477
void acl_kernel_if_register_callbacks(
7578
acl_kernel_update_callback kernel_update,

src/acl_auto_configure.cpp

Lines changed: 25 additions & 0 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 a boolean.
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_bool_counters(const std::string &str,
107+
std::string::size_type &pos, bool &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<bool>(std::stoi(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
@@ -1052,6 +1071,12 @@ bool acl_load_device_def_from_str(const std::string &config_str,
10521071
config_str, curr_pos, devdef.device_global_mem_defs, counters, err_str);
10531072
}
10541073

1074+
// Check whether csr_ring_root exist in the IP.
1075+
if (result && counters.back() > 0) {
1076+
result = read_bool_counters(config_str, curr_pos,
1077+
devdef.cra_ring_root_exist, counters);
1078+
}
1079+
10551080
// forward compatibility: bypassing remaining fields at the end of device
10561081
// description section
10571082
while (result && counters.size() > 0 &&

src/acl_hal_mmd.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,7 +1113,9 @@ static int l_try_device(unsigned int physical_device_id, const char *name,
11131113

11141114
// Post-PLL config init function - at this point, it's safe to talk to the
11151115
// kernel CSR registers.
1116-
if (acl_kernel_if_post_pll_config_init(&kern[physical_device_id]))
1116+
if (acl_kernel_if_post_pll_config_init(
1117+
sys->device[physical_device_id].autodiscovery_def.cra_ring_root_exist,
1118+
&kern[physical_device_id]))
11171119
return 0;
11181120

11191121
return 1;
@@ -2150,7 +2152,9 @@ int acl_hal_mmd_program_device(unsigned int physical_device_id,
21502152
}
21512153
// Post-PLL config init function - at this point, it's safe to talk to the
21522154
// kernel CSR registers.
2153-
if (acl_kernel_if_post_pll_config_init(&kern[physical_device_id]))
2155+
if (acl_kernel_if_post_pll_config_init(
2156+
devdef->autodiscovery_def.cra_ring_root_exist,
2157+
&kern[physical_device_id]))
21542158
return -1;
21552159

21562160
return 0;

src/acl_kernel_if.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ static uintptr_t acl_kernel_cra_set_segment_rom(acl_kernel_if *kern,
471471

472472
static int acl_kernel_cra_read(acl_kernel_if *kern, unsigned int accel_id,
473473
unsigned int addr, unsigned int *val) {
474+
assert(kern->csr_version);
474475
uintptr_t segment_offset = acl_kernel_cra_set_segment(kern, accel_id, addr);
475476
acl_assert_locked_or_sig();
476477
return acl_kernel_if_read_32b(
@@ -479,6 +480,7 @@ static int acl_kernel_cra_read(acl_kernel_if *kern, unsigned int accel_id,
479480

480481
int acl_kernel_cra_read_64b(acl_kernel_if *kern, unsigned int accel_id,
481482
unsigned int addr, uint64_t *val) {
483+
assert(kern->csr_version);
482484
uintptr_t segment_offset = acl_kernel_cra_set_segment(kern, accel_id, addr);
483485
acl_assert_locked_or_sig();
484486
return acl_kernel_if_read_64b(
@@ -530,6 +532,7 @@ static int acl_kernel_rom_cra_read_block(acl_kernel_if *kern, unsigned int addr,
530532

531533
static int acl_kernel_cra_write(acl_kernel_if *kern, unsigned int accel_id,
532534
unsigned int addr, unsigned int val) {
535+
assert(kern->csr_version);
533536
uintptr_t segment_offset = acl_kernel_cra_set_segment(kern, accel_id, addr);
534537
acl_assert_locked_or_sig();
535538
return acl_kernel_if_write_32b(
@@ -538,6 +541,7 @@ static int acl_kernel_cra_write(acl_kernel_if *kern, unsigned int accel_id,
538541

539542
static int acl_kernel_cra_write_64b(acl_kernel_if *kern, unsigned int accel_id,
540543
unsigned int addr, uint64_t val) {
544+
assert(kern->csr_version);
541545
uintptr_t segment_offset = acl_kernel_cra_set_segment(kern, accel_id, addr);
542546
acl_assert_locked();
543547
return acl_kernel_if_write_64b(
@@ -547,6 +551,7 @@ static int acl_kernel_cra_write_64b(acl_kernel_if *kern, unsigned int accel_id,
547551
static int acl_kernel_cra_write_block(acl_kernel_if *kern,
548552
unsigned int accel_id, unsigned int addr,
549553
unsigned int *val, size_t size) {
554+
assert(kern->csr_version);
550555
uintptr_t segment_offset = acl_kernel_cra_set_segment(kern, accel_id, addr);
551556
uintptr_t logical_addr =
552557
kern->accel_csr[accel_id].address + addr - OFFSET_KERNEL_CRA;
@@ -704,8 +709,6 @@ int acl_kernel_if_init(acl_kernel_if *kern, acl_bsp_io bsp_io,
704709
kern->accel_perf_mon = NULL;
705710
kern->accel_num_printfs = NULL;
706711

707-
kern->csr_version = 0;
708-
709712
kern->autorun_profiling_kernel_id = -1;
710713

711714
// The simulator doesn't have any kernel interface information until the aocx
@@ -1017,7 +1020,8 @@ int acl_kernel_if_update(const acl_device_def_autodiscovery_t &devdef,
10171020
// Post-PLL config init function - at this point it's safe to talk to
10181021
// the kernel CSR registers.
10191022
// Returns 0 on success
1020-
int acl_kernel_if_post_pll_config_init(acl_kernel_if *kern) {
1023+
int acl_kernel_if_post_pll_config_init(bool cra_ring_root_exist,
1024+
acl_kernel_if *kern) {
10211025
unsigned int csr, version;
10221026
unsigned k;
10231027
char *profile_start_cycle = getenv("ACL_PROFILE_START_CYCLE");
@@ -1032,7 +1036,7 @@ int acl_kernel_if_post_pll_config_init(acl_kernel_if *kern) {
10321036
kern->io.printf("HAL Kern Error: Post PLL init: Invalid kernel handle");
10331037
assert(0 && "Invalid kernel handle");
10341038
}
1035-
if (kern->num_accel > 0) {
1039+
if (kern->num_accel > 0 && cra_ring_root_exist) {
10361040
acl_kernel_cra_read(kern, 0, KERNEL_OFFSET_CSR, &csr);
10371041
version = ACL_KERNEL_READ_BIT_RANGE(csr, KERNEL_CSR_LAST_VERSION_BIT,
10381042
KERNEL_CSR_FIRST_VERSION_BIT);
@@ -1041,7 +1045,9 @@ int acl_kernel_if_post_pll_config_init(acl_kernel_if *kern) {
10411045
"Read CSR version from kernel 0: Version = %u\n",
10421046
kern->csr_version);
10431047
} else {
1044-
kern->csr_version = 0;
1048+
ACL_KERNEL_IF_DEBUG_MSG(kern,
1049+
"No accelerator found or CRA ring root doesn't "
1050+
"exist, not setting kern->csr_version\n");
10451051
}
10461052

10471053
// If environment variables set, configure the profile hardware
@@ -1148,7 +1154,8 @@ void acl_kernel_if_launch_kernel_on_custom_sof(
11481154
// Version is defined in upper 16-bits of the status register and cached
11491155
// in the kern->csr_version field. The value is cached after PLL init to
11501156
// avoid reading back on every kernel launch, which would add overhead.
1151-
if (!(kern->csr_version >= CSR_VERSION_ID_18_1 &&
1157+
if (kern->csr_version.has_value() &&
1158+
!(kern->csr_version >= CSR_VERSION_ID_18_1 &&
11521159
kern->csr_version <= CSR_VERSION_ID)) {
11531160
kern->io.printf("Hardware CSR version ID differs from version expected by "
11541161
"software. Either:\n");
@@ -1239,7 +1246,8 @@ void acl_kernel_if_launch_kernel_on_custom_sof(
12391246
}
12401247
}
12411248

1242-
if (kern->csr_version != CSR_VERSION_ID_18_1) {
1249+
if (kern->csr_version.has_value() &&
1250+
(kern->csr_version != CSR_VERSION_ID_18_1)) {
12431251
for (uintptr_t p = 0; p < image->arg_value_size; p += sizeof(int)) {
12441252
unsigned int pword = *(unsigned int *)(image->arg_value + p);
12451253
ACL_KERNEL_IF_DEBUG_MSG_VERBOSE(
@@ -1256,7 +1264,9 @@ void acl_kernel_if_launch_kernel_on_custom_sof(
12561264
acl_kernel_cra_write_block(kern, accel_id, offset, (unsigned int *)image_p,
12571265
image_size_static);
12581266
}
1259-
if (kern->csr_version != CSR_VERSION_ID_18_1 && image->arg_value_size > 0) {
1267+
1268+
if (kern->csr_version.has_value() &&
1269+
(kern->csr_version != CSR_VERSION_ID_18_1 && image->arg_value_size > 0)) {
12601270
acl_kernel_cra_write_block(
12611271
kern, accel_id, offset + (unsigned int)image_size_static,
12621272
(unsigned int *)image->arg_value, image->arg_value_size);

test/acl_auto_configure_test.cpp

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,11 +482,11 @@ TEST(auto_configure, many_ok_forward_compatibility) {
482482
// sections and subsections to check forward compatibility
483483

484484
std::string str(VERSIONIDTOSTR(
485-
ACL_AUTO_CONFIGURE_VERSIONID) " 28 "
485+
ACL_AUTO_CONFIGURE_VERSIONID) " 29 "
486486
"sample40byterandomhash000000000000000000 "
487487
"a10gx 0 1 15 DDR 2 1 6 0 2147483648 100 "
488488
"100 100 100 200 200 200 200 0 0 0 0 2 "
489-
"1 name1 1 name2 47 "
489+
"1 name1 name2 0 0 47 "
490490
"40 external_sort_stage_0 0 128 1 0 0 1 0 "
491491
"1 0 1 10 0 0 4 1 0 0 0 500 500 500 0 0 "
492492
"0 0 1 1 1 3 1 1 1 3 1 0 0 800 800 800 "
@@ -1410,3 +1410,63 @@ TEST(auto_configure, two_streaming_args_and_non_streaming_kernel) {
14101410
CHECK(!args[i].streaming_arg_info_available);
14111411
}
14121412
}
1413+
1414+
TEST(auto_configure, cra_ring_root_not_exist) {
1415+
const std::string config_str{
1416+
"23 50 2ccb683dee8e34a004c1a27e6d722090a8cc684d custom_ipa 0 1 9 0 2 1 2 "
1417+
"0 2199023255552 3 "
1418+
"- 0 6 5 ZTSZ4mainE4MyIP_arg_input_a 1 0 8 32768 "
1419+
"ZTSZ4mainE4MyIP_arg_input_b 1 0 8 32768 ZTSZ4mainE4MyIP_arg_input_c"
1420+
" 1 0 8 32768 ZTSZ4mainE4MyIP_arg_n 1 0 4 32768 "
1421+
"ZTSZ4mainE4MyIP_streaming_start 1 0 0 32768 "
1422+
"ZTSZ4mainE4MyIP_streaming_done"
1423+
" 0 1 0 32768 0 0 0 0 1 64 _ZTSZ4mainE4MyIP 0 128 1 0 0 1 0 1 0 4 8 2 1 "
1424+
"8 4 0 0 1 ZTSZ4mainE4MyIP_arg_input_a 8"
1425+
" 2 1 8 4 0 0 1 ZTSZ4mainE4MyIP_arg_input_b 8 2 1 8 4 0 0 1 "
1426+
"ZTSZ4mainE4MyIP_arg_input_c"
1427+
" 8 0 0 4 1 0 0 1 ZTSZ4mainE4MyIP_arg_n 0 0 0 0 1 1 1 3 1 1 1 3 1 1 1 "
1428+
"ZTSZ4mainE4MyIP_streaming_start"
1429+
" ZTSZ4mainE4MyIP_streaming_done"};
1430+
1431+
acl_device_def_autodiscovery_t devdef;
1432+
{
1433+
bool result;
1434+
std::string err_str;
1435+
ACL_LOCKED(result =
1436+
acl_load_device_def_from_str(config_str, devdef, err_str));
1437+
std::cerr << err_str;
1438+
CHECK(result);
1439+
}
1440+
1441+
CHECK_EQUAL(0, devdef.cra_ring_root_exist);
1442+
}
1443+
1444+
TEST(auto_configure, cra_ring_root_exist) {
1445+
const std::string config_str{
1446+
"23 50 2ccb683dee8e34a004c1a27e6d722090a8cc684d custom_ipa 0 1 9 0 2 1 2 "
1447+
"0 2199023255552 3 "
1448+
"- 0 6 5 ZTSZ4mainE4MyIP_arg_input_a 1 0 8 32768 "
1449+
"ZTSZ4mainE4MyIP_arg_input_b 1 0 8 32768 ZTSZ4mainE4MyIP_arg_input_c"
1450+
" 1 0 8 32768 ZTSZ4mainE4MyIP_arg_n 1 0 4 32768 "
1451+
"ZTSZ4mainE4MyIP_streaming_start 1 0 0 32768 "
1452+
"ZTSZ4mainE4MyIP_streaming_done"
1453+
" 0 1 0 32768 0 0 0 1 1 64 _ZTSZ4mainE4MyIP 0 128 1 0 0 1 0 1 0 4 8 2 1 "
1454+
"8 4 0 0 1 ZTSZ4mainE4MyIP_arg_input_a 8"
1455+
" 2 1 8 4 0 0 1 ZTSZ4mainE4MyIP_arg_input_b 8 2 1 8 4 0 0 1 "
1456+
"ZTSZ4mainE4MyIP_arg_input_c"
1457+
" 8 0 0 4 1 0 0 1 ZTSZ4mainE4MyIP_arg_n 0 0 0 0 1 1 1 3 1 1 1 3 1 1 1 "
1458+
"ZTSZ4mainE4MyIP_streaming_start"
1459+
" ZTSZ4mainE4MyIP_streaming_done"};
1460+
1461+
acl_device_def_autodiscovery_t devdef;
1462+
{
1463+
bool result;
1464+
std::string err_str;
1465+
ACL_LOCKED(result =
1466+
acl_load_device_def_from_str(config_str, devdef, err_str));
1467+
std::cerr << err_str;
1468+
CHECK(result);
1469+
}
1470+
1471+
CHECK_EQUAL(1, devdef.cra_ring_root_exist);
1472+
}

0 commit comments

Comments
 (0)