Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only write changing parts of kernel arguments to kernel CRA #324

Merged
merged 1 commit into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/acl_kernel_if.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ typedef struct {

// CRA address offset for backwards compatibility
unsigned int cra_address_offset = 8;

char **accel_arg_cache;
} acl_kernel_if;

// *********************** Public functions **************************
Expand Down
54 changes: 51 additions & 3 deletions src/acl_kernel_if.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,10 @@ int acl_kernel_if_update(const acl_device_def_autodiscovery_t &devdef,
(unsigned int *)acl_malloc(kern->num_accel * sizeof(unsigned int));
assert(kern->accel_invoc_queue_depth);

kern->accel_arg_cache =
(char **)acl_malloc(kern->num_accel * sizeof(char *));
assert(kern->accel_arg_cache);

// Kernel IRQ is a separate thread. Need to use circular buffer to make this
// multithread safe.
kern->accel_queue_front = (int *)acl_malloc(kern->num_accel * sizeof(int));
Expand All @@ -920,6 +924,7 @@ int acl_kernel_if_update(const acl_device_def_autodiscovery_t &devdef,
for (unsigned b = 0; b < max_same_accel_launches; ++b) {
kern->accel_job_ids[a][b] = -1;
}
kern->accel_arg_cache[a] = nullptr;
}
}

Expand Down Expand Up @@ -1182,9 +1187,42 @@ void acl_kernel_if_launch_kernel_on_custom_sof(

if (kern->csr_version.has_value() &&
(kern->csr_version != CSR_VERSION_ID_18_1 && image->arg_value_size > 0)) {
acl_kernel_cra_write_block(
kern, accel_id, offset + (unsigned int)image_size_static,
(unsigned int *)image->arg_value, image->arg_value_size);
if (kern->accel_arg_cache[accel_id] == nullptr) {
acl_kernel_cra_write_block(
kern, accel_id, offset + (unsigned int)image_size_static,
(unsigned int *)image->arg_value, image->arg_value_size);
kern->accel_arg_cache[accel_id] =
(char *)acl_malloc(image->arg_value_size);
memcpy(kern->accel_arg_cache[accel_id], (char *)image->arg_value,
image->arg_value_size);
} else {
for (size_t step = 0; step < image->arg_value_size;) {
size_t size_to_write = 0;
size_t cmp_size = (image->arg_value_size - step) > sizeof(int)
? sizeof(int)
: (image->arg_value_size - step);
while (cmp_size > 0 &&
memcmp(kern->accel_arg_cache[accel_id] + step + size_to_write,
image->arg_value + step + size_to_write, cmp_size) != 0) {
size_to_write += cmp_size;
cmp_size =
(image->arg_value_size - step - size_to_write) > sizeof(int)
? sizeof(int)
: (image->arg_value_size - step - size_to_write);
}
if (size_to_write == 0) {
step += (unsigned)sizeof(int);
} else {
acl_kernel_cra_write_block(
kern, accel_id, offset + (unsigned int)(image_size_static + step),
(unsigned int *)(image->arg_value + step), size_to_write);
step += size_to_write;
}
}
// image->arg_value_size should not change
memcpy(kern->accel_arg_cache[accel_id], (char *)image->arg_value,
image->arg_value_size);
}
}

kern->accel_job_ids[accel_id][next_launch_index] = (int)activation_id;
Expand Down Expand Up @@ -1693,13 +1731,23 @@ void acl_kernel_if_close(acl_kernel_if *kern) {
acl_free(kern->accel_queue_front);
if (kern->accel_queue_back)
acl_free(kern->accel_queue_back);
if (kern->accel_arg_cache) {
for (unsigned int a = 0; a < kern->num_accel; a++) {
if (kern->accel_arg_cache[a]) {
acl_free((void *)kern->accel_arg_cache[a]);
kern->accel_arg_cache[a] = NULL;
}
}
acl_free((void *)kern->accel_arg_cache);
}
kern->accel_csr = NULL;
kern->accel_perf_mon = NULL;
kern->accel_num_printfs = NULL;
kern->accel_job_ids = NULL;
kern->accel_invoc_queue_depth = NULL;
kern->accel_queue_front = NULL;
kern->accel_queue_back = NULL;
kern->accel_arg_cache = NULL;
kern->autorun_profiling_kernel_id = -1;
}

Expand Down