@@ -97,22 +97,23 @@ void acl_kernel_if_register_callbacks(
97
97
// **************************** Utility Functions ***************************
98
98
// **************************************************************************
99
99
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 ) {
102
103
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 )) {
104
108
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 ));
113
113
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);
116
117
}
117
118
}
118
119
@@ -1143,36 +1144,35 @@ void acl_kernel_if_launch_kernel_on_custom_sof(
1143
1144
(image->work_dim ));
1144
1145
}
1145
1146
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
-
1161
1147
// When csr version is 18.1, the kernel args is part of the image. otherwise,
1162
1148
// it is in dynamic memory. Only write the static part of the invocation
1163
1149
// image if this kernel uses CRA control.
1164
1150
if (!kern->streaming_control_signal_names [accel_id]) {
1165
1151
if (kern->csr_version == CSR_VERSION_ID_18_1) {
1166
1152
// 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
+ }
1167
1157
acl_kernel_cra_write_block (kern, accel_id, offset,
1168
1158
(unsigned int *)image_p, image_size_static);
1169
1159
} else {
1170
1160
char *img_cache_ptr = kern->static_img_cache [accel_id].get ();
1171
1161
assert (img_cache_ptr && " kernel image cache not initialized!" );
1172
1162
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
+ }
1173
1169
acl_kernel_cra_write_block (kern, accel_id, offset,
1174
1170
(unsigned int *)image_p, image_size_static);
1175
1171
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 );
1176
1176
}
1177
1177
}
1178
1178
}
@@ -1182,9 +1182,17 @@ void acl_kernel_if_launch_kernel_on_custom_sof(
1182
1182
(kern->csr_version != CSR_VERSION_ID_18_1 && image->arg_value_size > 0 )) {
1183
1183
accel_has_agent_args = true ;
1184
1184
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
+ }
1185
1192
acl_kernel_cra_write_block (
1186
1193
kern, accel_id, offset + (unsigned int )image_size_static,
1187
1194
(unsigned int *)image->arg_value , image->arg_value_size );
1195
+ // Initialize kernel argument cache and cache the values
1188
1196
kern->accel_arg_cache [accel_id] =
1189
1197
std::make_unique<char []>(image->arg_value_size );
1190
1198
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(
1197
1205
size_t cmp_size = (image->arg_value_size - step) > sizeof (int )
1198
1206
? sizeof (int )
1199
1207
: (image->arg_value_size - step);
1208
+ // Find range of changed arguments and record size of that block
1200
1209
while (cmp_size > 0 &&
1201
1210
memcmp (arg_cache_ptr + step + size_to_write,
1202
1211
image->arg_value + step + size_to_write, cmp_size) != 0 ) {
@@ -1207,8 +1216,23 @@ void acl_kernel_if_launch_kernel_on_custom_sof(
1207
1216
: (image->arg_value_size - step - size_to_write);
1208
1217
}
1209
1218
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;
1211
1229
} 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
+ }
1212
1236
acl_kernel_cra_write_block (
1213
1237
kern, accel_id, offset + (unsigned int )(image_size_static + step),
1214
1238
(unsigned int *)(image->arg_value + step), size_to_write);
0 commit comments