Skip to content

Commit eb29930

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 eb29930

File tree

9 files changed

+139
-45
lines changed

9 files changed

+139
-45
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: 20 additions & 11 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");
@@ -1222,9 +1229,8 @@ void acl_kernel_if_launch_kernel_on_custom_sof(
12221229
} else {
12231230
offset = (unsigned int)KERNEL_OFFSET_INVOCATION_IMAGE;
12241231
image_p = (uintptr_t) & (image->work_dim);
1225-
image_size_static =
1226-
(size_t)((uintptr_t) & (image->arg_value) - (uintptr_t) &
1227-
(image->work_dim));
1232+
image_size_static = (size_t)(
1233+
(uintptr_t) & (image->arg_value) - (uintptr_t) & (image->work_dim));
12281234
}
12291235

12301236
if ((kern->io.debug_verbosity) >= 2) {
@@ -1239,7 +1245,8 @@ void acl_kernel_if_launch_kernel_on_custom_sof(
12391245
}
12401246
}
12411247

1242-
if (kern->csr_version != CSR_VERSION_ID_18_1) {
1248+
if (kern->csr_version.has_value() &&
1249+
(kern->csr_version != CSR_VERSION_ID_18_1)) {
12431250
for (uintptr_t p = 0; p < image->arg_value_size; p += sizeof(int)) {
12441251
unsigned int pword = *(unsigned int *)(image->arg_value + p);
12451252
ACL_KERNEL_IF_DEBUG_MSG_VERBOSE(
@@ -1256,7 +1263,9 @@ void acl_kernel_if_launch_kernel_on_custom_sof(
12561263
acl_kernel_cra_write_block(kern, accel_id, offset, (unsigned int *)image_p,
12571264
image_size_static);
12581265
}
1259-
if (kern->csr_version != CSR_VERSION_ID_18_1 && image->arg_value_size > 0) {
1266+
1267+
if (kern->csr_version.has_value() &&
1268+
(kern->csr_version != CSR_VERSION_ID_18_1 && image->arg_value_size > 0)) {
12601269
acl_kernel_cra_write_block(
12611270
kern, accel_id, offset + (unsigned int)image_size_static,
12621271
(unsigned int *)image->arg_value, image->arg_value_size);

src/acl_mem.cpp

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -438,9 +438,7 @@ CL_API_ENTRY cl_mem clCreateBufferWithPropertiesINTEL(
438438
case CL_MEM_ALLOC_BUFFER_LOCATION_INTEL: {
439439
tmp_mem_id = (cl_uint) * (properties + 1);
440440
} break;
441-
default: {
442-
BAIL_INFO(CL_INVALID_DEVICE, context, "Invalid properties");
443-
}
441+
default: { BAIL_INFO(CL_INVALID_DEVICE, context, "Invalid properties"); }
444442
}
445443
properties += 2;
446444
}
@@ -5569,8 +5567,8 @@ void acl_mem_migrate_buffer(void *user_data, acl_device_op_t *op) {
55695567

55705568
#ifdef MEM_DEBUG_MSG
55715569
printf("release block %zx (%u:%u) ",
5572-
(size_t)(src_mem->reserved_allocations[src_device]
5573-
[src_mem_id]),
5570+
(size_t)(
5571+
src_mem->reserved_allocations[src_device][src_mem_id]),
55745572
src_device, src_mem_id);
55755573
#endif
55765574
remove_mem_block_linked_list(
@@ -5956,9 +5954,8 @@ static void l_mem_transfer_buffer_explicitly(cl_context context,
59565954
dst_unmap_cmd.info.mem_xfer.map_flags = CL_MAP_WRITE;
59575955
}
59585956
dst_unmap_cmd.info.mem_xfer.src_mem = context->unwrapped_host_mem;
5959-
dst_unmap_cmd.info.mem_xfer.src_offset[0] =
5960-
(size_t)((char *)dst_mem->host_mem.aligned_ptr -
5961-
(char *)ACL_MEM_ALIGN);
5957+
dst_unmap_cmd.info.mem_xfer.src_offset[0] = (size_t)(
5958+
(char *)dst_mem->host_mem.aligned_ptr - (char *)ACL_MEM_ALIGN);
59625959
dst_unmap_cmd.info.mem_xfer.src_offset[1] = 0;
59635960
dst_unmap_cmd.info.mem_xfer.src_offset[2] = 0;
59645961
dst_unmap_cmd.info.mem_xfer.dst_mem = dst_mem;
@@ -6322,9 +6319,8 @@ void acl_copy_device_buffers_to_host_before_programming(
63226319
cmd.info.mem_xfer.src_offset[2] = 0;
63236320
cmd.info.mem_xfer.dst_mem = context2->unwrapped_host_mem;
63246321
if (mem->flags & CL_MEM_USE_HOST_PTR) {
6325-
cmd.info.mem_xfer.dst_offset[0] =
6326-
(size_t)((char *)mem->fields.buffer_objs.host_ptr -
6327-
(char *)ACL_MEM_ALIGN);
6322+
cmd.info.mem_xfer.dst_offset[0] = (size_t)(
6323+
(char *)mem->fields.buffer_objs.host_ptr - (char *)ACL_MEM_ALIGN);
63286324
} else {
63296325
cmd.info.mem_xfer.dst_offset[0] =
63306326
(size_t)((char *)mem->host_mem.aligned_ptr - (char *)ACL_MEM_ALIGN);
@@ -6468,9 +6464,8 @@ void acl_copy_device_buffers_from_host_after_programming(
64686464
cmd.type = CL_COMMAND_WRITE_BUFFER;
64696465
cmd.info.mem_xfer.src_mem = context2->unwrapped_host_mem;
64706466
if (mem->flags & CL_MEM_USE_HOST_PTR) {
6471-
cmd.info.mem_xfer.src_offset[0] =
6472-
(size_t)((char *)mem->fields.buffer_objs.host_ptr -
6473-
(char *)ACL_MEM_ALIGN);
6467+
cmd.info.mem_xfer.src_offset[0] = (size_t)(
6468+
(char *)mem->fields.buffer_objs.host_ptr - (char *)ACL_MEM_ALIGN);
64746469
} else {
64756470
cmd.info.mem_xfer.src_offset[0] =
64766471
(size_t)((char *)mem->host_mem.aligned_ptr - (char *)ACL_MEM_ALIGN);

src/acl_printf.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -911,11 +911,13 @@ static size_t l_dump_printf_buffer(cl_event event, cl_kernel kernel,
911911
length = get_length_specifier(data_elem._conversion_string);
912912

913913
#ifdef DEBUG
914-
printf("length specifier=%s\n", length == LS_HL ? "LS_HL"
915-
: length == LS_HH ? "LS_HH"
916-
: length == LS_H ? "LS_H"
917-
: length == LS_L ? "LS_L"
918-
: "NONE");
914+
printf("length specifier=%s\n",
915+
length == LS_HL
916+
? "LS_HL"
917+
: length == LS_HH
918+
? "LS_HH"
919+
: length == LS_H ? "LS_H"
920+
: length == LS_L ? "LS_L" : "NONE");
919921
#endif
920922

921923
// the size of the data we are converting right now

src/acl_usm.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,7 @@ CL_API_ENTRY void *CL_API_CALL clHostMemAllocINTEL(
112112
case CL_MEM_ALLOC_BUFFER_LOCATION_INTEL: {
113113
mem_id = (cl_uint) * (properties + 1);
114114
} break;
115-
default: {
116-
BAIL_INFO(CL_INVALID_PROPERTY, context, "Invalid properties");
117-
}
115+
default: { BAIL_INFO(CL_INVALID_PROPERTY, context, "Invalid properties"); }
118116
}
119117
properties += 2;
120118
}
@@ -267,9 +265,7 @@ clDeviceMemAllocINTEL(cl_context context, cl_device_id device,
267265
case CL_MEM_ALLOC_BUFFER_LOCATION_INTEL: {
268266
mem_id = (cl_uint) * (properties + 1);
269267
} break;
270-
default: {
271-
BAIL_INFO(CL_INVALID_DEVICE, context, "Invalid properties");
272-
}
268+
default: { BAIL_INFO(CL_INVALID_DEVICE, context, "Invalid properties"); }
273269
}
274270
properties += 2;
275271
}
@@ -421,9 +417,7 @@ clSharedMemAllocINTEL(cl_context context, cl_device_id device,
421417
}
422418
mem_id = (cl_uint) * (properties + 1);
423419
} break;
424-
default: {
425-
BAIL_INFO(CL_INVALID_PROPERTY, context, "Invalid properties");
426-
}
420+
default: { BAIL_INFO(CL_INVALID_PROPERTY, context, "Invalid properties"); }
427421
}
428422
properties += 2;
429423
}

0 commit comments

Comments
 (0)