From 4b44252e8072be7c9a0766cbaad81b278500d798 Mon Sep 17 00:00:00 2001 From: Ch Vamshi Krishna <40261882+chvamshi-xilinx@users.noreply.github.com> Date: Thu, 17 Oct 2024 11:35:14 +0530 Subject: [PATCH] conflict (#8534) enabled hw_context reset_array support Signed-off-by: ch vamshi krishna Co-authored-by: ch vamshi krishna --- .../core/common/api/xrt_hw_context.cpp | 14 +++++ .../core/common/shim/hwctx_handle.h | 6 ++ .../core/edge/drm/zocl/common/zocl_drv.c | 2 +- .../core/edge/drm/zocl/edge/zocl_aie.c | 56 ++++++++++--------- .../edge/drm/zocl/edge/zocl_edge_xclbin.c | 4 +- .../core/edge/drm/zocl/include/zocl_drv.h | 1 - src/runtime_src/core/edge/user/aie/aie.cpp | 8 +-- src/runtime_src/core/edge/user/aie/aie.h | 2 +- .../core/edge/user/device_linux.cpp | 2 +- .../core/edge/user/hwctx_object.cpp | 13 +++++ src/runtime_src/core/edge/user/hwctx_object.h | 3 + src/runtime_src/core/edge/user/shim.cpp | 2 - src/runtime_src/core/include/xrt/xrt_aie.h | 23 ++++++++ 13 files changed, 95 insertions(+), 41 deletions(-) diff --git a/src/runtime_src/core/common/api/xrt_hw_context.cpp b/src/runtime_src/core/common/api/xrt_hw_context.cpp index 2a0323754e0..70b72d44ff8 100644 --- a/src/runtime_src/core/common/api/xrt_hw_context.cpp +++ b/src/runtime_src/core/common/api/xrt_hw_context.cpp @@ -264,3 +264,17 @@ hw_context:: {} } // xrt + +//////////////////////////////////////////////////////////////// +// xrt_aie_hw_context C++ API implmentations (xrt_aie.h) +//////////////////////////////////////////////////////////////// +namespace xrt::aie { + +void +hw_context:: +reset_array() +{ + auto core_handle = get_handle()->get_hwctx_handle(); + core_handle->reset_array(); +} +} //xrt::aie diff --git a/src/runtime_src/core/common/shim/hwctx_handle.h b/src/runtime_src/core/common/shim/hwctx_handle.h index 85590947b33..ce93a07776f 100755 --- a/src/runtime_src/core/common/shim/hwctx_handle.h +++ b/src/runtime_src/core/common/shim/hwctx_handle.h @@ -113,6 +113,12 @@ class hwctx_handle { throw xrt_core::error(std::errc::not_supported, __func__); } + + virtual void + reset_array() const + { + throw xrt_core::error(std::errc::not_supported, __func__); + } }; } // xrt_core diff --git a/src/runtime_src/core/edge/drm/zocl/common/zocl_drv.c b/src/runtime_src/core/edge/drm/zocl/common/zocl_drv.c index cd27898e78f..3108a3e5eaf 100644 --- a/src/runtime_src/core/edge/drm/zocl/common/zocl_drv.c +++ b/src/runtime_src/core/edge/drm/zocl/common/zocl_drv.c @@ -193,7 +193,7 @@ static void zocl_pr_slot_fini(struct drm_zocl_dev *zdev) zocl_slot = zdev->pr_slot[i]; if (zocl_slot) { zocl_free_sections(zdev, zocl_slot); - zocl_destroy_aie(zocl_slot); + zocl_cleanup_aie(zocl_slot); mutex_destroy(&zocl_slot->slot_xclbin_lock); mutex_destroy(&zocl_slot->aie_lock); zocl_xclbin_fini(zdev, zocl_slot); diff --git a/src/runtime_src/core/edge/drm/zocl/edge/zocl_aie.c b/src/runtime_src/core/edge/drm/zocl/edge/zocl_aie.c index caab9adaa17..cc8fa3bc7b7 100644 --- a/src/runtime_src/core/edge/drm/zocl/edge/zocl_aie.c +++ b/src/runtime_src/core/edge/drm/zocl/edge/zocl_aie.c @@ -199,6 +199,7 @@ get_slot(struct drm_zocl_dev * zdev, struct kds_client* client, int hw_ctx_id) mutex_unlock(&client->lock); return slot; } + int zocl_aie_request_part_fd(struct drm_zocl_dev *zdev, void *data, struct drm_file *filp) { @@ -290,7 +291,7 @@ zocl_aie_reset_work(struct work_struct *aie_work) slot->aie->fd_cnt = 0; } -int +static int zocl_aie_slot_reset(struct drm_zocl_slot* slot) { if (!slot) { @@ -364,6 +365,33 @@ zocl_aie_slot_reset(struct drm_zocl_slot* slot) } +static void +zocl_destroy_aie(struct drm_zocl_slot* slot) +{ + if (!slot->aie_information) + return; + + mutex_lock(&slot->aie_lock); + vfree(slot->aie_information); + slot->aie_information = NULL; + + if (!slot->aie) { + mutex_unlock(&slot->aie_lock); + return; + } + + if (slot->aie->aie_dev) + aie_partition_release(slot->aie->aie_dev); + + if (slot->aie->wq) + destroy_workqueue(slot->aie->wq); + + vfree(slot->aie->err.errors); + vfree(slot->aie); + slot->aie = NULL; + mutex_unlock(&slot->aie_lock); +} + int zocl_cleanup_aie(struct drm_zocl_slot *slot) { @@ -537,32 +565,6 @@ zocl_create_aie(struct drm_zocl_slot *slot, struct axlf *axlf, char __user *xclb return rval; } -void -zocl_destroy_aie(struct drm_zocl_slot* slot) -{ - if (!slot->aie_information) - return; - - mutex_lock(&slot->aie_lock); - vfree(slot->aie_information); - slot->aie_information = NULL; - - if (!slot->aie) { - mutex_unlock(&slot->aie_lock); - return; - } - - if (slot->aie->aie_dev) - aie_partition_release(slot->aie->aie_dev); - - if (slot->aie->wq) - destroy_workqueue(slot->aie->wq); - - vfree(slot->aie->err.errors); - vfree(slot->aie); - slot->aie = NULL; - mutex_unlock(&slot->aie_lock); -} diff --git a/src/runtime_src/core/edge/drm/zocl/edge/zocl_edge_xclbin.c b/src/runtime_src/core/edge/drm/zocl/edge/zocl_edge_xclbin.c index ec8a3cc4710..bc4b5606b06 100644 --- a/src/runtime_src/core/edge/drm/zocl/edge/zocl_edge_xclbin.c +++ b/src/runtime_src/core/edge/drm/zocl/edge/zocl_edge_xclbin.c @@ -193,8 +193,8 @@ zocl_xclbin_read_axlf(struct drm_zocl_dev *zdev, struct drm_zocl_axlf *axlf_obj, /* Free sections before load the new xclbin */ zocl_free_sections(zdev, slot); - /* Destroy the aie information from slot and create new */ - zocl_destroy_aie(slot); + /* Cleanup the aie information from slot and create new */ + zocl_cleanup_aie(slot); #if KERNEL_VERSION(5, 4, 0) <= LINUX_VERSION_CODE diff --git a/src/runtime_src/core/edge/drm/zocl/include/zocl_drv.h b/src/runtime_src/core/edge/drm/zocl/include/zocl_drv.h index 70b992db97f..159e14557fe 100644 --- a/src/runtime_src/core/edge/drm/zocl/include/zocl_drv.h +++ b/src/runtime_src/core/edge/drm/zocl/include/zocl_drv.h @@ -268,7 +268,6 @@ int zocl_cleanup_aie(struct drm_zocl_slot *slot); int zocl_create_aie(struct drm_zocl_slot *slot, struct axlf *axlf, char __user *xclbin, void *aie_res, uint8_t hw_gen, uint32_t partition_id); int zocl_init_aie(struct drm_zocl_slot* slot); -void zocl_destroy_aie(struct drm_zocl_slot *slot); int zocl_aie_request_part_fd(struct drm_zocl_dev *zdev, void *data,struct drm_file* filp ); int zocl_aie_reset(struct drm_zocl_dev *zdev, void* data, struct drm_file* file); int zocl_aie_freqscale(struct drm_zocl_dev *zdev, void *data, struct drm_file* filp); diff --git a/src/runtime_src/core/edge/user/aie/aie.cpp b/src/runtime_src/core/edge/user/aie/aie.cpp index f245c1da8af..0f9631a4e1f 100755 --- a/src/runtime_src/core/edge/user/aie/aie.cpp +++ b/src/runtime_src/core/edge/user/aie/aie.cpp @@ -403,7 +403,7 @@ clear_bd(aie_bd& bd) void aie_array:: -reset(const xrt_core::device* device) +reset(const xrt_core::device* device, uint32_t hw_context_id, uint32_t partition_id) { if (!dev_inst) throw xrt_core::error(-EINVAL, "Can't Reset AIE: AIE is not initialized"); @@ -416,11 +416,7 @@ reset(const xrt_core::device* device) auto drv = ZYNQ::shim::handleCheck(device->get_device_handle()); - /* TODO get partition id and uid from XCLBIN or PDI */ - uint32_t partition_id = 1; - - //TODO create similar function for hw_context - drm_zocl_aie_reset reset = { 0 , partition_id }; + drm_zocl_aie_reset reset = { hw_context_id , partition_id }; int ret = drv->resetAIEArray(reset); if (ret) throw xrt_core::error(ret, "Fail to reset AIE Array"); diff --git a/src/runtime_src/core/edge/user/aie/aie.h b/src/runtime_src/core/edge/user/aie/aie.h index 702497b2734..46627f7a572 100755 --- a/src/runtime_src/core/edge/user/aie/aie.h +++ b/src/runtime_src/core/edge/user/aie/aie.h @@ -121,7 +121,7 @@ class aie_array { wait_gmio(const std::string& gmioName); void - reset(const xrt_core::device* device); + reset(const xrt_core::device* device, uint32_t hw_context_id, uint32_t partition_id); int start_profiling(int option, const std::string& port1_name, const std::string& port2_name, uint32_t value); diff --git a/src/runtime_src/core/edge/user/device_linux.cpp b/src/runtime_src/core/edge/user/device_linux.cpp index 151bfd23c3d..5c14c881b02 100644 --- a/src/runtime_src/core/edge/user/device_linux.cpp +++ b/src/runtime_src/core/edge/user/device_linux.cpp @@ -1235,7 +1235,7 @@ reset_aie() if (!aie_array->is_context_set()) aie_array->open_context(this, xrt::aie::access_mode::primary); - aie_array->reset(this); + aie_array->reset(this, 0 /*hw_context_id*/, xrt_core::edge::aie::full_array_id); } void diff --git a/src/runtime_src/core/edge/user/hwctx_object.cpp b/src/runtime_src/core/edge/user/hwctx_object.cpp index 4c337384547..a0baac45262 100644 --- a/src/runtime_src/core/edge/user/hwctx_object.cpp +++ b/src/runtime_src/core/edge/user/hwctx_object.cpp @@ -127,4 +127,17 @@ hwctx_object::open_aie_buffer_handle(const char* name) #endif } +void +hwctx_object::reset_array() const +{ + if (!m_aie_array) + throw xrt_core::error(-EINVAL, "No AIE present in hw_context to reset"); + + auto device{xrt_core::get_userpf_device(m_shim)}; + if (!m_aie_array->is_context_set()) + m_aie_array->open_context(device.get(), xrt::aie::access_mode::primary); + + m_aie_array->reset(device.get(), m_slot_idx, m_info.partition_id); +} + } diff --git a/src/runtime_src/core/edge/user/hwctx_object.h b/src/runtime_src/core/edge/user/hwctx_object.h index 7c9b44915db..78ea78c4c99 100644 --- a/src/runtime_src/core/edge/user/hwctx_object.h +++ b/src/runtime_src/core/edge/user/hwctx_object.h @@ -108,6 +108,9 @@ namespace zynqaie { std::unique_ptr open_aie_buffer_handle(const char* name) override; + void + reset_array() const override; + #ifdef XRT_ENABLE_AIE std::shared_ptr get_aie_array_shared(); diff --git a/src/runtime_src/core/edge/user/shim.cpp b/src/runtime_src/core/edge/user/shim.cpp index 1326e3d81df..10b3a31df08 100644 --- a/src/runtime_src/core/edge/user/shim.cpp +++ b/src/runtime_src/core/edge/user/shim.cpp @@ -1283,8 +1283,6 @@ int shim::prepare_hw_axlf(const axlf *buffer, struct drm_zocl_axlf *axlf_obj) } off += sizeof(kernel_info) + sizeof(argument_info) * kernel.args.size(); } - - return 0; } diff --git a/src/runtime_src/core/include/xrt/xrt_aie.h b/src/runtime_src/core/include/xrt/xrt_aie.h index b4988174d53..03e21bb4478 100644 --- a/src/runtime_src/core/include/xrt/xrt_aie.h +++ b/src/runtime_src/core/include/xrt/xrt_aie.h @@ -255,6 +255,29 @@ class bo : public xrt::bo } }; +class hw_context : public xrt::hw_context +{ +public: + + /** + * hw_context() - Constructor that is used for AIE hw_context. + * + * @param arg + * Arguments to construct hw_context (xrt_hw_context.h). + */ + template + hw_context(Args&&... args) + : xrt::hw_context(std::forward(args)...) + {} + + /** + * reset_array() - reset the AIE Array used for this hw_context + * + */ + void + reset_array(); +}; + class profiling_impl; class profiling : public detail::pimpl {