From 87b2d35665ba6d2b644caf2e410a99213c28d5fe Mon Sep 17 00:00:00 2001 From: rbramand Date: Mon, 1 Jul 2024 17:47:13 +0530 Subject: [PATCH 1/2] Add PID param to aie mem/reg read/write apis Signed-off-by: rbramand --- .../core/common/api/xrt_device.cpp | 30 +++++++++++-------- src/runtime_src/core/include/xrt/xrt_aie.h | 16 +++++++--- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/runtime_src/core/common/api/xrt_device.cpp b/src/runtime_src/core/common/api/xrt_device.cpp index 0ddefebc4b9..22683db0a17 100644 --- a/src/runtime_src/core/common/api/xrt_device.cpp +++ b/src/runtime_src/core/common/api/xrt_device.cpp @@ -387,10 +387,14 @@ 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, int32_t pid, uint16_t context_id, uint16_t col) { auto data = xrt_core::device_query_default(device, {}); for (const auto& entry : data) { + // if PID info is present compare PID's else skip + if (entry.pid != -1 && (entry.pid != pid)) + continue; + if (std::stoi(entry.metadata.id) != context_id) continue; @@ -427,13 +431,13 @@ open_context(xrt::aie::device::access_mode am) std::vector device:: -read_aie_mem(uint16_t context_id, uint16_t col, uint16_t row, uint32_t offset, uint32_t size) const +read_aie_mem(int32_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); } @@ -445,13 +449,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& data) +write_aie_mem(int32_t pid, uint16_t context_id, uint16_t col, uint16_t row, uint32_t offset, const std::vector& 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); } @@ -462,13 +466,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(int32_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); } @@ -480,13 +484,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(int32_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, ®_val, context_id] { + [this, &col, row, reg_addr, ®_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); } diff --git a/src/runtime_src/core/include/xrt/xrt_aie.h b/src/runtime_src/core/include/xrt/xrt_aie.h index 03e21bb4478..0a956a2d0af 100644 --- a/src/runtime_src/core/include/xrt/xrt_aie.h +++ b/src/runtime_src/core/include/xrt/xrt_aie.h @@ -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 @@ -109,11 +111,13 @@ class device : public xrt::device */ XCL_DRIVER_DLLESPEC std::vector - read_aie_mem(uint16_t context_id, uint16_t col, uint16_t row, uint32_t offset, uint32_t size) const; + read_aie_mem(int32_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 @@ -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& data); + write_aie_mem(int32_t pid, uint16_t context_id, uint16_t col, uint16_t row, uint32_t offset, const std::vector& 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 @@ -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(int32_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 @@ -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(int32_t pid, uint16_t context_id, uint16_t col, uint16_t row, uint32_t reg_addr, uint32_t reg_val); private: XCL_DRIVER_DLLESPEC From 41a324a6258e566bb37f20e21af4c590a8d31ab3 Mon Sep 17 00:00:00 2001 From: rbramand Date: Tue, 9 Jul 2024 16:06:01 +0530 Subject: [PATCH 2/2] Address comments on PR Signed-off-by: rbramand --- src/runtime_src/core/common/api/xrt_device.cpp | 17 +++++++---------- src/runtime_src/core/include/xrt/xrt_aie.h | 8 ++++---- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/runtime_src/core/common/api/xrt_device.cpp b/src/runtime_src/core/common/api/xrt_device.cpp index 22683db0a17..406a987cc48 100644 --- a/src/runtime_src/core/common/api/xrt_device.cpp +++ b/src/runtime_src/core/common/api/xrt_device.cpp @@ -387,15 +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, int32_t pid, 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(device, {}); for (const auto& entry : data) { - // if PID info is present compare PID's else skip - if (entry.pid != -1 && (entry.pid != pid)) - continue; - - 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; @@ -431,7 +428,7 @@ open_context(xrt::aie::device::access_mode am) std::vector device:: -read_aie_mem(int32_t pid, 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, pid] { @@ -449,7 +446,7 @@ read_aie_mem(int32_t pid, uint16_t context_id, uint16_t col, uint16_t row, uint3 size_t device:: -write_aie_mem(int32_t pid, uint16_t context_id, uint16_t col, uint16_t row, uint32_t offset, const std::vector& data) +write_aie_mem(pid_t pid, uint16_t context_id, uint16_t col, uint16_t row, uint32_t offset, const std::vector& data) { return xdp::native::profiling_wrapper("xrt::aie::device::write_aie_mem", [this, &col, row, offset, &data, context_id, pid] { @@ -466,7 +463,7 @@ write_aie_mem(int32_t pid, uint16_t context_id, uint16_t col, uint16_t row, uint } uint32_t device:: -read_aie_reg(int32_t pid, 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, pid] { @@ -484,7 +481,7 @@ read_aie_reg(int32_t pid, uint16_t context_id, uint16_t col, uint16_t row, uint3 bool device:: -write_aie_reg(int32_t pid, 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, ®_val, context_id, pid] { diff --git a/src/runtime_src/core/include/xrt/xrt_aie.h b/src/runtime_src/core/include/xrt/xrt_aie.h index 0a956a2d0af..c1c8fdf42de 100644 --- a/src/runtime_src/core/include/xrt/xrt_aie.h +++ b/src/runtime_src/core/include/xrt/xrt_aie.h @@ -111,7 +111,7 @@ class device : public xrt::device */ XCL_DRIVER_DLLESPEC std::vector - read_aie_mem(int32_t pid, 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 @@ -136,7 +136,7 @@ class device : public xrt::device */ XCL_DRIVER_DLLESPEC size_t - write_aie_mem(int32_t pid, uint16_t context_id, uint16_t col, uint16_t row, uint32_t offset, const std::vector& data); + write_aie_mem(pid_t pid, uint16_t context_id, uint16_t col, uint16_t row, uint32_t offset, const std::vector& data); /** * read_aie_reg() - Read AIE Tile's register @@ -159,7 +159,7 @@ class device : public xrt::device */ XCL_DRIVER_DLLESPEC uint32_t - read_aie_reg(int32_t pid, 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 @@ -184,7 +184,7 @@ class device : public xrt::device */ XCL_DRIVER_DLLESPEC bool - write_aie_reg(int32_t pid, 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