Skip to content

Commit a10729c

Browse files
committed
Fix kernel id - csr address mapping issue in simulation runtime
Currently simulation uses arithmetics to derive kernel id and csr start register address, which is error prone. This change adds a new MMD call to pass kernel-id to csr address mapping to the lower runtime so it could use the information directly.
1 parent 5084201 commit a10729c

File tree

4 files changed

+31
-2
lines changed

4 files changed

+31
-2
lines changed

include/acl_hal.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,10 @@ typedef struct {
247247
const std::string &signal_name,
248248
unsigned int &finish_counter);
249249

250+
void (*simulation_set_kernel_cra_address_map)(
251+
unsigned int physical_device_id,
252+
const std::vector<uintptr_t> &kernel_csr_address_map);
253+
250254
size_t (*read_csr)(unsigned int physical_device_id, uintptr_t offset,
251255
void *ptr, size_t size);
252256

include/acl_hal_mmd.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,12 @@ typedef struct {
149149
// accounted and returned in a subsequent invocation of this function.
150150
void (*aocl_mmd_simulation_streaming_kernel_done)(
151151
int handle, const std::string &signal_name, unsigned int &finish_counter);
152+
153+
// Pass kernel-id to csr-address mapping read from the current binary
154+
// to the simulation runtime, so that it can detect which start register
155+
// has been written by the runtime.
156+
void (*aocl_mmd_simulation_set_kernel_cra_address_map)(
157+
int handle, const std::vector<uintptr_t> &kernel_csr_address_map);
152158
} acl_mmd_dispatch_t;
153159

154160
typedef struct {

src/acl_hal_mmd.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ void acl_hal_mmd_simulation_streaming_kernel_done(
161161
unsigned int physical_device_id, const std::string &kernel_name,
162162
unsigned int &finish_counter);
163163

164+
void acl_hal_mmd_simulation_set_kernel_cra_address_map(
165+
unsigned int physical_device_id,
166+
const std::vector<uintptr_t> &kernel_csr_address_map);
167+
164168
size_t acl_hal_mmd_read_csr(unsigned int physical_device_id, uintptr_t offset,
165169
void *ptr, size_t size);
166170

@@ -360,8 +364,9 @@ static acl_hal_t acl_hal_mmd = {
360364
acl_hal_mmd_shared_alloc, // shared_alloc
361365
acl_hal_mmd_simulation_streaming_kernel_start, // simulation_streaming_kernel_start
362366
acl_hal_mmd_simulation_streaming_kernel_done, // simulation_streaming_kernel_done
363-
acl_hal_mmd_read_csr, // read_csr
364-
acl_hal_mmd_write_csr, // write_csr
367+
acl_hal_mmd_simulation_set_kernel_cra_address_map, // simulation_set_kernel_cra_address_map
368+
acl_hal_mmd_read_csr, // read_csr
369+
acl_hal_mmd_write_csr, // write_csr
365370
};
366371

367372
// This will contain the device physical id to tell us which device across all
@@ -2865,6 +2870,14 @@ void acl_hal_mmd_simulation_streaming_kernel_done(
28652870
device_info[physical_device_id].handle, kernel_name, finish_counter);
28662871
}
28672872

2873+
void acl_hal_mmd_simulation_set_kernel_cra_address_map(
2874+
unsigned int physical_device_id,
2875+
const std::vector<uintptr_t> &kernel_csr_address_map) {
2876+
device_info[physical_device_id]
2877+
.mmd_dispatch->aocl_mmd_simulation_set_kernel_cra_address_map(
2878+
device_info[physical_device_id].handle, kernel_csr_address_map);
2879+
}
2880+
28682881
size_t acl_hal_mmd_read_csr(unsigned int physical_device_id, uintptr_t offset,
28692882
void *ptr, size_t size) {
28702883
return device_info[physical_device_id].mmd_dispatch->aocl_mmd_read(

src/acl_kernel_if.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,16 +921,22 @@ int acl_kernel_if_update(const acl_device_def_autodiscovery_t &devdef,
921921
// The Kernel CSR registers
922922
// The new and improved config ROM give us the address *offsets* from
923923
// the first kernel CSR, and the range of each kernel CSR.
924+
std::vector<uintptr_t> kernel_csr_address_map;
924925
for (unsigned ii = 0; ii < devdef.accel.size(); ++ii) {
925926
kern->accel_csr[ii].address =
926927
OFFSET_KERNEL_CRA + devdef.hal_info[ii].csr.address;
927928
kern->accel_csr[ii].bytes = devdef.hal_info[ii].csr.num_bytes;
929+
kernel_csr_address_map.push_back(kern->accel_csr[ii].address);
928930

929931
ACL_KERNEL_IF_DEBUG_MSG(
930932
kern, "Kernel_%s CSR { 0x%08" PRIxPTR ", 0x%08" PRIxPTR " }\n",
931933
devdef.accel[ii].iface.name.c_str(), kern->accel_csr[ii].address,
932934
kern->accel_csr[ii].bytes);
933935
}
936+
if (acl_platform.offline_mode == ACL_CONTEXT_MPSIM) {
937+
acl_get_hal()->simulation_set_kernel_cra_address_map(
938+
kern->physical_device_id, kernel_csr_address_map);
939+
}
934940

935941
// The Kernel performance monitor registers
936942
for (unsigned ii = 0; ii < devdef.accel.size(); ++ii) {

0 commit comments

Comments
 (0)