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

Add PID argument to aie mem and reg read/write apis #8275

Merged
merged 2 commits into from
Oct 28, 2024
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
29 changes: 15 additions & 14 deletions src/runtime_src/core/common/api/xrt_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,11 +387,12 @@ namespace xrt::aie {
// of that partition. Get patition info using the context id passed and
// convert relative column index to absolute using this info
static uint16_t
get_abs_col(const xrt_core::device* device, uint16_t context_id, uint16_t col)
get_abs_col(const xrt_core::device* device, pid_t pid, uint16_t context_id, uint16_t col)
{
auto data = xrt_core::device_query_default<xrt_core::query::aie_partition_info>(device, {});
for (const auto& entry : data) {
if (std::stoi(entry.metadata.id) != context_id)
// compare PID and context id
if (entry.pid != pid || std::stoi(entry.metadata.id) != context_id)
continue;

auto abs_col = col + entry.start_col;
Expand Down Expand Up @@ -427,13 +428,13 @@ open_context(xrt::aie::device::access_mode am)

std::vector<char>
device::
read_aie_mem(uint16_t context_id, uint16_t col, uint16_t row, uint32_t offset, uint32_t size) const
read_aie_mem(pid_t pid, uint16_t context_id, uint16_t col, uint16_t row, uint32_t offset, uint32_t size) const
{
return xdp::native::profiling_wrapper("xrt::aie::device::read_aie_mem",
[this, &col, row, offset, size, context_id] {
[this, &col, row, offset, size, context_id, pid] {
try {
// calculate absolute col index
auto abs_col = get_abs_col(get_handle().get(), context_id, col);
auto abs_col = get_abs_col(get_handle().get(), pid, context_id, col);
is_4byte_aligned_or_throw(offset); // DRC check
return get_handle()->read_aie_mem(abs_col, row, offset, size);
}
Expand All @@ -445,13 +446,13 @@ read_aie_mem(uint16_t context_id, uint16_t col, uint16_t row, uint32_t offset, u

size_t
device::
write_aie_mem(uint16_t context_id, uint16_t col, uint16_t row, uint32_t offset, const std::vector<char>& data)
write_aie_mem(pid_t pid, uint16_t context_id, uint16_t col, uint16_t row, uint32_t offset, const std::vector<char>& data)
{
return xdp::native::profiling_wrapper("xrt::aie::device::write_aie_mem",
[this, &col, row, offset, &data, context_id] {
[this, &col, row, offset, &data, context_id, pid] {
try {
// calculate absolute col index
auto abs_col = get_abs_col(get_handle().get(), context_id, col);
auto abs_col = get_abs_col(get_handle().get(), pid, context_id, col);
is_4byte_aligned_or_throw(offset); // DRC check
return get_handle()->write_aie_mem(abs_col, row, offset, data);
}
Expand All @@ -462,13 +463,13 @@ write_aie_mem(uint16_t context_id, uint16_t col, uint16_t row, uint32_t offset,
}
uint32_t
device::
read_aie_reg(uint16_t context_id, uint16_t col, uint16_t row, uint32_t reg_addr) const
read_aie_reg(pid_t pid, uint16_t context_id, uint16_t col, uint16_t row, uint32_t reg_addr) const
{
return xdp::native::profiling_wrapper("xrt::device::read_aie_reg",
[this, &col, row, reg_addr, context_id] {
[this, &col, row, reg_addr, context_id, pid] {
try {
// calculate absolute col index
auto abs_col = get_abs_col(get_handle().get(), context_id, col);
auto abs_col = get_abs_col(get_handle().get(), pid, context_id, col);
is_4byte_aligned_or_throw(reg_addr); // DRC check
return get_handle()->read_aie_reg(abs_col, row, reg_addr);
}
Expand All @@ -480,13 +481,13 @@ read_aie_reg(uint16_t context_id, uint16_t col, uint16_t row, uint32_t reg_addr)

bool
device::
write_aie_reg(uint16_t context_id, uint16_t col, uint16_t row, uint32_t reg_addr, uint32_t reg_val)
write_aie_reg(pid_t pid, uint16_t context_id, uint16_t col, uint16_t row, uint32_t reg_addr, uint32_t reg_val)
{
return xdp::native::profiling_wrapper("xrt::device::write_aie_reg",
[this, &col, row, reg_addr, &reg_val, context_id] {
[this, &col, row, reg_addr, &reg_val, context_id, pid] {
try {
// calculate absolute col index
auto abs_col = get_abs_col(get_handle().get(), context_id, col);
auto abs_col = get_abs_col(get_handle().get(), pid, context_id, col);
is_4byte_aligned_or_throw(reg_addr); // DRC check
return get_handle()->write_aie_reg(abs_col, row, reg_addr, reg_val);
}
Expand Down
16 changes: 12 additions & 4 deletions src/runtime_src/core/include/xrt/xrt_aie.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ class device : public xrt::device
/**
* read_aie_mem() - Read AIE tile's memory
*
* @param pid
* process id of process that opened hw_context
* @param context_id
* context id corresponding to AIE tile
* @param col
Expand All @@ -109,11 +111,13 @@ class device : public xrt::device
*/
XCL_DRIVER_DLLESPEC
std::vector<char>
read_aie_mem(uint16_t context_id, uint16_t col, uint16_t row, uint32_t offset, uint32_t size) const;
read_aie_mem(pid_t pid, uint16_t context_id, uint16_t col, uint16_t row, uint32_t offset, uint32_t size) const;

/**
* write_aie_mem() - Write data to AIE tile's memory
*
* @param pid
* process id of process that opened hw_context
* @param context_id
* context id corresponding to AIE tile
* @param col
Expand All @@ -132,11 +136,13 @@ class device : public xrt::device
*/
XCL_DRIVER_DLLESPEC
size_t
write_aie_mem(uint16_t context_id, uint16_t col, uint16_t row, uint32_t offset, const std::vector<char>& data);
write_aie_mem(pid_t pid, uint16_t context_id, uint16_t col, uint16_t row, uint32_t offset, const std::vector<char>& data);

/**
* read_aie_reg() - Read AIE Tile's register
*
* @param pid
* process id of process that opened hw_context
* @param context_id
* context id corresponding to AIE tile
* @param col
Expand All @@ -153,11 +159,13 @@ class device : public xrt::device
*/
XCL_DRIVER_DLLESPEC
uint32_t
read_aie_reg(uint16_t context_id, uint16_t col, uint16_t row, uint32_t reg_addr) const;
read_aie_reg(pid_t pid, uint16_t context_id, uint16_t col, uint16_t row, uint32_t reg_addr) const;

/**
* write_aie_reg() - Write AIE Tile's register
*
* @param pid
* process id of process that opened hw_context
* @param context_id
* context id corresponding to AIE tile
* @param col
Expand All @@ -176,7 +184,7 @@ class device : public xrt::device
*/
XCL_DRIVER_DLLESPEC
bool
write_aie_reg(uint16_t context_id, uint16_t col, uint16_t row, uint32_t reg_addr, uint32_t reg_val);
write_aie_reg(pid_t pid, uint16_t context_id, uint16_t col, uint16_t row, uint32_t reg_addr, uint32_t reg_val);

private:
XCL_DRIVER_DLLESPEC
Expand Down
Loading