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

Fix kernel id - CSR address mapping issue #285

Merged
merged 1 commit into from
Apr 5, 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
4 changes: 4 additions & 0 deletions include/acl_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@ typedef struct {
const std::string &signal_name,
unsigned int &finish_counter);

void (*simulation_set_kernel_cra_address_map)(
unsigned int physical_device_id,
const std::vector<uintptr_t> &kernel_csr_address_map);

size_t (*read_csr)(unsigned int physical_device_id, uintptr_t offset,
void *ptr, size_t size);

Expand Down
6 changes: 6 additions & 0 deletions include/acl_hal_mmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ typedef struct {
// accounted and returned in a subsequent invocation of this function.
void (*aocl_mmd_simulation_streaming_kernel_done)(
int handle, const std::string &signal_name, unsigned int &finish_counter);

// Pass kernel-id to csr-address mapping read from the current binary
// to the simulation runtime, so that it can detect which start register
// has been written by the runtime.
void (*aocl_mmd_simulation_set_kernel_cra_address_map)(
int handle, const std::vector<uintptr_t> &kernel_csr_address_map);
} acl_mmd_dispatch_t;

typedef struct {
Expand Down
17 changes: 15 additions & 2 deletions src/acl_hal_mmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ void acl_hal_mmd_simulation_streaming_kernel_done(
unsigned int physical_device_id, const std::string &kernel_name,
unsigned int &finish_counter);

void acl_hal_mmd_simulation_set_kernel_cra_address_map(
unsigned int physical_device_id,
const std::vector<uintptr_t> &kernel_csr_address_map);

size_t acl_hal_mmd_read_csr(unsigned int physical_device_id, uintptr_t offset,
void *ptr, size_t size);

Expand Down Expand Up @@ -360,8 +364,9 @@ static acl_hal_t acl_hal_mmd = {
acl_hal_mmd_shared_alloc, // shared_alloc
acl_hal_mmd_simulation_streaming_kernel_start, // simulation_streaming_kernel_start
acl_hal_mmd_simulation_streaming_kernel_done, // simulation_streaming_kernel_done
acl_hal_mmd_read_csr, // read_csr
acl_hal_mmd_write_csr, // write_csr
acl_hal_mmd_simulation_set_kernel_cra_address_map, // simulation_set_kernel_cra_address_map
acl_hal_mmd_read_csr, // read_csr
acl_hal_mmd_write_csr, // write_csr
};

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

void acl_hal_mmd_simulation_set_kernel_cra_address_map(
unsigned int physical_device_id,
const std::vector<uintptr_t> &kernel_csr_address_map) {
device_info[physical_device_id]
.mmd_dispatch->aocl_mmd_simulation_set_kernel_cra_address_map(
device_info[physical_device_id].handle, kernel_csr_address_map);
}

size_t acl_hal_mmd_read_csr(unsigned int physical_device_id, uintptr_t offset,
void *ptr, size_t size) {
return device_info[physical_device_id].mmd_dispatch->aocl_mmd_read(
Expand Down
6 changes: 6 additions & 0 deletions src/acl_kernel_if.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -921,16 +921,22 @@ int acl_kernel_if_update(const acl_device_def_autodiscovery_t &devdef,
// The Kernel CSR registers
// The new and improved config ROM give us the address *offsets* from
// the first kernel CSR, and the range of each kernel CSR.
std::vector<uintptr_t> kernel_csr_address_map;
for (unsigned ii = 0; ii < devdef.accel.size(); ++ii) {
kern->accel_csr[ii].address =
OFFSET_KERNEL_CRA + devdef.hal_info[ii].csr.address;
kern->accel_csr[ii].bytes = devdef.hal_info[ii].csr.num_bytes;
kernel_csr_address_map.push_back(kern->accel_csr[ii].address);

ACL_KERNEL_IF_DEBUG_MSG(
kern, "Kernel_%s CSR { 0x%08" PRIxPTR ", 0x%08" PRIxPTR " }\n",
devdef.accel[ii].iface.name.c_str(), kern->accel_csr[ii].address,
kern->accel_csr[ii].bytes);
}
if (acl_platform.offline_mode == ACL_CONTEXT_MPSIM) {
acl_get_hal()->simulation_set_kernel_cra_address_map(
kern->physical_device_id, kernel_csr_address_map);
}

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