From b44edf87a027e719a75174f5c6f2b2ecdaec9598 Mon Sep 17 00:00:00 2001 From: Sophie Mao Date: Thu, 28 Sep 2023 12:26:49 -0700 Subject: [PATCH] Update invocation image debug prints The runtime prints invocation image data in steps size of integer size, this doesn't take into the account when the last block of data has a smaller size. This change is added to handle this special case. --- src/acl_kernel_if.cpp | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/src/acl_kernel_if.cpp b/src/acl_kernel_if.cpp index 471a90e1..9784a694 100644 --- a/src/acl_kernel_if.cpp +++ b/src/acl_kernel_if.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #undef TEST_PROFILING_HARDWARE #ifdef TEST_PROFILING_HARDWARE @@ -95,6 +96,26 @@ void acl_kernel_if_register_callbacks( // ************************************************************************** // **************************** Utility Functions *************************** // ************************************************************************** +void print_invocation_image(acl_kernel_if *kern, char *image_ptr, + size_t image_size, unsigned int offset, + bool is_static) { + std::string image_type = is_static ? "stat" : "args"; + for (uintptr_t p = 0; p < image_size; p += sizeof(int)) { + unsigned int pword = 0; + if (p + sizeof(int) > image_size) { + for (size_t i = 0; i < image_size - p; i += sizeof(char)) { + safe_memcpy(((char *)(&pword)) + i, image_ptr + p + i, sizeof(char), + sizeof(int), image_size - p - i); + } + } else { + pword = *(unsigned int *)(image_ptr + p); + } + ACL_KERNEL_IF_DEBUG_MSG_VERBOSE( + kern, 2, ":: Writing inv image (%s) [%2d] @%8p := %4x\n", + image_type.c_str(), (int)(p), (void *)(offset + p), pword); + } +} + // Returns 0 on success, -1 on failure static int check_version_id(acl_kernel_if *kern) { unsigned int version = 0; @@ -1140,22 +1161,14 @@ void acl_kernel_if_launch_kernel_on_custom_sof( // We only write the static part of the invocation image if the kernel uses // CRA control. if (!kern->streaming_control_signal_names[accel_id]) { - for (uintptr_t p = 0; p < image_size_static; p += sizeof(int)) { - unsigned int pword = *(unsigned int *)(image_p + p); - ACL_KERNEL_IF_DEBUG_MSG_VERBOSE( - kern, 2, ":: Writing inv image [%2d] @%8p := %4x\n", (int)(p), - (void *)(offset + p), pword); - } + print_invocation_image(kern, (char *)image_p, image_size_static, offset, + true); } if (kern->csr_version.has_value() && (kern->csr_version != CSR_VERSION_ID_18_1)) { - for (uintptr_t p = 0; p < image->arg_value_size; p += sizeof(int)) { - unsigned int pword = *(unsigned int *)(image->arg_value + p); - ACL_KERNEL_IF_DEBUG_MSG_VERBOSE( - kern, 2, ":: Writing inv image [%2d] @%8p := %4x\n", (int)(p), - (void *)(offset + image_size_static + p), pword); - } + print_invocation_image(kern, image->arg_value, image->arg_value_size, + (unsigned int)(offset + image_size_static), false); } }