Skip to content

Commit 2b68b90

Browse files
committed
acl_kernel_if_update_status: factor out processing of finished kernel invocation
Signed-off-by: Peter Colberg <[email protected]>
1 parent ae0be39 commit 2b68b90

File tree

1 file changed

+39
-30
lines changed

1 file changed

+39
-30
lines changed

src/acl_kernel_if.cpp

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,6 +1411,43 @@ static void acl_kernel_if_update_status_query(acl_kernel_if *kern,
14111411
}
14121412
}
14131413

1414+
// Processes finished kernel invocation.
1415+
static void acl_kernel_if_update_status_finish(acl_kernel_if *kern,
1416+
const unsigned int accel_id,
1417+
const int activation_id,
1418+
const unsigned int printf_size) {
1419+
#ifdef TEST_PROFILING_HARDWARE
1420+
// Test readback of fake profile data using the acl_hal_mmd function that
1421+
// would be called from the acl runtime.
1422+
ACL_KERNEL_IF_DEBUG_MSG(kern, ":: testing profile hardware on accel_id=%u.\n",
1423+
accel_id);
1424+
1425+
uint64_t data[10];
1426+
acl_hal_mmd_get_profile_data(kern->physical_device_id, accel_id, data, 6);
1427+
acl_hal_mmd_reset_profile_counters(kern->physical_device_id, accel_id);
1428+
acl_hal_mmd_get_profile_data(kern->physical_device_id, accel_id, data, 6);
1429+
#endif
1430+
1431+
// Just clear the "done" bit. The "go" bit should already have been
1432+
// cleared, but this is harmless anyway.
1433+
// Since csr version 19, done bit is cleared when finish counter is read.
1434+
// Since csr version 2022.3, done bit needs to be cleared explicitly.
1435+
if (kern->csr_version == CSR_VERSION_ID_18_1 ||
1436+
kern->csr_version >= CSR_VERSION_ID_2022_3) {
1437+
unsigned int dum;
1438+
acl_kernel_cra_write(kern, accel_id, KERNEL_OFFSET_CSR, 0);
1439+
acl_kernel_cra_read(kern, accel_id, KERNEL_OFFSET_CSR, &dum);
1440+
}
1441+
1442+
if (kern->accel_num_printfs[accel_id] > 0) {
1443+
ACL_KERNEL_IF_DEBUG_MSG(kern,
1444+
":: Calling acl_process_printf_buffer_fn with "
1445+
"activation_id=%d and printf_size=%u.\n",
1446+
activation_id, printf_size);
1447+
acl_process_printf_buffer_fn(activation_id, (int)printf_size, 0);
1448+
}
1449+
}
1450+
14141451
// Called when we receive a kernel status interrupt. Cycle through all of
14151452
// the running accelerators and check for updated status.
14161453
void acl_kernel_if_update_status(acl_kernel_if *kern) {
@@ -1470,36 +1507,8 @@ void acl_kernel_if_update_status(acl_kernel_if *kern) {
14701507
// Tell the host library this job is done
14711508
kern->accel_job_ids[accel_id][next_queue_back] = -1;
14721509

1473-
#ifdef TEST_PROFILING_HARDWARE
1474-
// Test readback of fake profile data using the acl_hal_mmd function that
1475-
// would be called from the acl runtime.
1476-
ACL_KERNEL_IF_DEBUG_MSG(
1477-
kern, ":: testing profile hardware on accel_id=%u.\n", accel_id);
1478-
1479-
uint64_t data[10];
1480-
acl_hal_mmd_get_profile_data(kern->physical_device_id, accel_id, data, 6);
1481-
acl_hal_mmd_reset_profile_counters(kern->physical_device_id, accel_id);
1482-
acl_hal_mmd_get_profile_data(kern->physical_device_id, accel_id, data, 6);
1483-
#endif
1484-
1485-
// Just clear the "done" bit. The "go" bit should already have been
1486-
// cleared, but this is harmless anyway.
1487-
// Since csr version 19, done bit is cleared when finish counter is read.
1488-
// Since csr version 2022.3, done bit needs to be cleared explicitly.
1489-
if (kern->csr_version == CSR_VERSION_ID_18_1 ||
1490-
kern->csr_version >= CSR_VERSION_ID_2022_3) {
1491-
unsigned int dum;
1492-
acl_kernel_cra_write(kern, accel_id, KERNEL_OFFSET_CSR, 0);
1493-
acl_kernel_cra_read(kern, accel_id, KERNEL_OFFSET_CSR, &dum);
1494-
}
1495-
1496-
if (kern->accel_num_printfs[accel_id] > 0) {
1497-
ACL_KERNEL_IF_DEBUG_MSG(kern,
1498-
":: Calling acl_process_printf_buffer_fn with "
1499-
"activation_id=%d and printf_size=%u.\n",
1500-
activation_id, printf_size);
1501-
acl_process_printf_buffer_fn(activation_id, (int)printf_size, 0);
1502-
}
1510+
acl_kernel_if_update_status_finish(kern, accel_id, activation_id,
1511+
printf_size);
15031512

15041513
// Executing the following update after reading from performance
15051514
// and efficiency monitors will clobber the throughput reported by

0 commit comments

Comments
 (0)