Skip to content

Commit 4c34cda

Browse files
committed
Update kernel invocation image debug print
1 parent 11e307f commit 4c34cda

File tree

1 file changed

+53
-29
lines changed

1 file changed

+53
-29
lines changed

src/acl_kernel_if.cpp

Lines changed: 53 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -97,22 +97,23 @@ void acl_kernel_if_register_callbacks(
9797
// **************************** Utility Functions ***************************
9898
// **************************************************************************
9999
void print_invocation_image(acl_kernel_if *kern, char *image_ptr,
100-
size_t image_size, unsigned int offset,
101-
bool is_static) {
100+
size_t image_size, size_t size_to_write,
101+
unsigned int csr_offset, bool is_static,
102+
bool is_write = true, size_t print_offset = 0) {
102103
std::string image_type = is_static ? "stat" : "args";
103-
for (uintptr_t p = 0; p < image_size; p += sizeof(int)) {
104+
std::string overwrite = is_write ? "Writing" : "Keeping";
105+
size_t print_end = print_offset + size_to_write;
106+
assert(print_end <= image_size && "printing invocation image out of bound");
107+
for (uintptr_t p = print_offset; p < print_end; p += sizeof(int)) {
104108
unsigned int pword = 0;
105-
if (p + sizeof(int) > image_size) {
106-
for (size_t i = 0; i < image_size - p; i += sizeof(char)) {
107-
safe_memcpy(((char *)(&pword)) + i, image_ptr + p + i, sizeof(char),
108-
sizeof(int), image_size - p - i);
109-
}
110-
} else {
111-
pword = *(unsigned int *)(image_ptr + p);
112-
}
109+
uintptr_t cpy_size =
110+
(print_end - p > sizeof(int)) ? sizeof(int) : (print_end - p);
111+
safe_memcpy(((char *)(&pword)), image_ptr + p, cpy_size * sizeof(char),
112+
sizeof(int), (print_end - p) * sizeof(char));
113113
ACL_KERNEL_IF_DEBUG_MSG_VERBOSE(
114-
kern, 2, ":: Writing inv image (%s) [%2d] @%8p := %4x\n",
115-
image_type.c_str(), (int)(p), (void *)(offset + p), pword);
114+
kern, 2, ":: %s inv image (%s) [%2d] @%8p := %4x\n",
115+
overwrite.c_str(), image_type.c_str(), (int)(p),
116+
(void *)(csr_offset + p), pword);
116117
}
117118
}
118119

@@ -1143,36 +1144,35 @@ void acl_kernel_if_launch_kernel_on_custom_sof(
11431144
(image->work_dim));
11441145
}
11451146

1146-
if ((kern->io.debug_verbosity) >= 2) {
1147-
// We only write the static part of the invocation image if the kernel uses
1148-
// CRA control.
1149-
if (!kern->streaming_control_signal_names[accel_id]) {
1150-
print_invocation_image(kern, (char *)image_p, image_size_static, offset,
1151-
true);
1152-
}
1153-
1154-
if (kern->csr_version.has_value() &&
1155-
(kern->csr_version != CSR_VERSION_ID_18_1)) {
1156-
print_invocation_image(kern, image->arg_value, image->arg_value_size,
1157-
(unsigned int)(offset + image_size_static), false);
1158-
}
1159-
}
1160-
11611147
// When csr version is 18.1, the kernel args is part of the image. otherwise,
11621148
// it is in dynamic memory. Only write the static part of the invocation
11631149
// image if this kernel uses CRA control.
11641150
if (!kern->streaming_control_signal_names[accel_id]) {
11651151
if (kern->csr_version == CSR_VERSION_ID_18_1) {
11661152
// Just write everything for older CSR version
1153+
if ((kern->io.debug_verbosity) >= 2) {
1154+
print_invocation_image(kern, (char *)image_p, image_size_static,
1155+
image_size_static, offset, true);
1156+
}
11671157
acl_kernel_cra_write_block(kern, accel_id, offset,
11681158
(unsigned int *)image_p, image_size_static);
11691159
} else {
11701160
char *img_cache_ptr = kern->static_img_cache[accel_id].get();
11711161
assert(img_cache_ptr && "kernel image cache not initialized!");
11721162
if (memcmp(img_cache_ptr, (char *)image_p, image_size_static) != 0) {
1163+
// Something changed in static part of the invocation image,
1164+
// write everything to csr
1165+
if ((kern->io.debug_verbosity) >= 2) {
1166+
print_invocation_image(kern, (char *)image_p, image_size_static,
1167+
image_size_static, offset, true);
1168+
}
11731169
acl_kernel_cra_write_block(kern, accel_id, offset,
11741170
(unsigned int *)image_p, image_size_static);
11751171
memcpy(img_cache_ptr, (char *)image_p, image_size_static);
1172+
} else if ((kern->io.debug_verbosity) >= 2) {
1173+
// Nothing's changed, just print the static part of the invocation image
1174+
print_invocation_image(kern, (char *)image_p, image_size_static,
1175+
image_size_static, offset, true, false);
11761176
}
11771177
}
11781178
}
@@ -1182,9 +1182,17 @@ void acl_kernel_if_launch_kernel_on_custom_sof(
11821182
(kern->csr_version != CSR_VERSION_ID_18_1 && image->arg_value_size > 0)) {
11831183
accel_has_agent_args = true;
11841184
if (!kern->accel_arg_cache[accel_id]) {
1185+
// The first time invoking the kernel, just write all the arguments
1186+
if ((kern->io.debug_verbosity) >= 2) {
1187+
print_invocation_image(kern, image->arg_value, image->arg_value_size,
1188+
image->arg_value_size,
1189+
(unsigned int)(offset + image_size_static),
1190+
false);
1191+
}
11851192
acl_kernel_cra_write_block(
11861193
kern, accel_id, offset + (unsigned int)image_size_static,
11871194
(unsigned int *)image->arg_value, image->arg_value_size);
1195+
// Initialize kernel argument cache and cache the values
11881196
kern->accel_arg_cache[accel_id] =
11891197
std::make_unique<char[]>(image->arg_value_size);
11901198
memcpy(kern->accel_arg_cache[accel_id].get(), (char *)image->arg_value,
@@ -1197,6 +1205,7 @@ void acl_kernel_if_launch_kernel_on_custom_sof(
11971205
size_t cmp_size = (image->arg_value_size - step) > sizeof(int)
11981206
? sizeof(int)
11991207
: (image->arg_value_size - step);
1208+
// Find range of changed arguments and record size of that block
12001209
while (cmp_size > 0 &&
12011210
memcmp(arg_cache_ptr + step + size_to_write,
12021211
image->arg_value + step + size_to_write, cmp_size) != 0) {
@@ -1207,8 +1216,23 @@ void acl_kernel_if_launch_kernel_on_custom_sof(
12071216
: (image->arg_value_size - step - size_to_write);
12081217
}
12091218
if (size_to_write == 0) {
1210-
step += (unsigned)sizeof(int);
1219+
// Current compared block is the same as before, skipping write
1220+
size_t size_to_skip = (image->arg_value_size - step > sizeof(int))
1221+
? sizeof(int)
1222+
: (image->arg_value_size - step);
1223+
if ((kern->io.debug_verbosity) >= 2) {
1224+
print_invocation_image(
1225+
kern, image->arg_value, image->arg_value_size, size_to_skip,
1226+
(unsigned int)(offset + image_size_static), false, false, step);
1227+
}
1228+
step += size_to_skip;
12111229
} else {
1230+
// Write the changed argument block to csr
1231+
if ((kern->io.debug_verbosity) >= 2) {
1232+
print_invocation_image(
1233+
kern, image->arg_value, image->arg_value_size, size_to_write,
1234+
(unsigned int)(offset + image_size_static), false, true, step);
1235+
}
12121236
acl_kernel_cra_write_block(
12131237
kern, accel_id, offset + (unsigned int)(image_size_static + step),
12141238
(unsigned int *)(image->arg_value + step), size_to_write);

0 commit comments

Comments
 (0)