From ff5dd5d93a186c700a68bb63c61ba0b5b9130cb3 Mon Sep 17 00:00:00 2001 From: Sravankumar allu Date: Wed, 7 Aug 2024 19:49:22 +0530 Subject: [PATCH] VITIS-11024 enable hw_context support for xrt::graph objects 1) bo function calls sync / async added with hw ctx along with device specific 2) profiling functions added with hw ctx along with device specific Signed-off-by: Sravankumar allu --- .../core/common/api/aie/xrt_graph.cpp | 68 ++++++++---------- src/runtime_src/core/common/api/xrt_bo.cpp | 7 +- src/runtime_src/core/common/ishim.h | 7 ++ .../core/common/shim/buffer_handle.h | 14 ++++ .../core/common/shim/hwctx_handle.h | 7 ++ .../core/common/shim/profile_handle.h | 32 +++++++++ .../core/edge/user/aie/profile_object.cpp | 57 +++++++++++++++ .../core/edge/user/aie/profile_object.h | 37 ++++++++++ .../core/edge/user/device_linux.cpp | 21 ++++++ src/runtime_src/core/edge/user/device_linux.h | 4 ++ .../core/edge/user/hwctx_object.cpp | 38 +++++++++- src/runtime_src/core/edge/user/hwctx_object.h | 18 +++++ src/runtime_src/core/edge/user/shim.cpp | 8 +-- src/runtime_src/core/edge/user/shim.h | 71 +++++++++++++++++-- src/runtime_src/core/include/xrt/xrt_aie.h | 3 + 15 files changed, 339 insertions(+), 53 deletions(-) create mode 100644 src/runtime_src/core/common/shim/profile_handle.h create mode 100644 src/runtime_src/core/edge/user/aie/profile_object.cpp create mode 100644 src/runtime_src/core/edge/user/aie/profile_object.h diff --git a/src/runtime_src/core/common/api/aie/xrt_graph.cpp b/src/runtime_src/core/common/api/aie/xrt_graph.cpp index 754c74bd641..9773bb6225f 100644 --- a/src/runtime_src/core/common/api/aie/xrt_graph.cpp +++ b/src/runtime_src/core/common/api/aie/xrt_graph.cpp @@ -22,6 +22,7 @@ #include "core/common/message.h" #include "core/common/system.h" #include "core/common/shim/graph_handle.h" +#include "core/common/shim/profile_handle.h" #include #include @@ -124,27 +125,24 @@ namespace xrt::aie { class profiling_impl { private: - std::shared_ptr device; - int profiling_hdl; + std::unique_ptr m_profile_handle{nullptr}; public: - using handle = int; - static constexpr handle invalid_handle = -1; + static constexpr int invalid_handle = -1; - explicit profiling_impl(std::shared_ptr dev) - : device(std::move(dev)), - profiling_hdl(invalid_handle) + profiling_impl(std::shared_ptr device) + : m_profile_handle{device->open_profile_handle()} {} + profiling_impl(const xrt::hw_context& hwctx) + { + auto hwctx_handle = static_cast(hwctx); + m_profile_handle = hwctx_handle->open_profile_handle(); + } + ~profiling_impl() { - try { - if (profiling_hdl != invalid_handle) - device->stop_profiling(profiling_hdl); - } - catch(...) { - // do nothing - } + stop(); } profiling_impl() = delete; @@ -152,35 +150,24 @@ class profiling_impl profiling_impl(profiling_impl&&) = delete; profiling_impl& operator=(const profiling_impl&) = delete; profiling_impl& operator=(profiling_impl&&) = delete; - - handle - start_profiling(int option, const std::string& port1_name, const std::string& port2_name, uint32_t value) + int + start(int option, const std::string& port1_name, const std::string& port2_name, uint32_t value) { - profiling_hdl = device->start_profiling(option, port1_name.c_str(), port2_name.c_str(), value); - return profiling_hdl; + return m_profile_handle->start(option, port1_name.c_str(), port2_name.c_str(), value); } uint64_t - read_profiling() + read() { - if (profiling_hdl == invalid_handle) - throw xrt_core::error(-EINVAL, "Not a valid profiling handle"); - - return device->read_profiling(profiling_hdl); - + return m_profile_handle->read(); } void - stop_profiling() + stop() { - if (profiling_hdl == invalid_handle) - throw xrt_core::error(-EINVAL, "Not a valid profiling handle"); - - device->stop_profiling(profiling_hdl); - profiling_hdl = invalid_handle; + return m_profile_handle->stop(); } - }; } // xrt::aie @@ -399,13 +386,18 @@ profiling(const xrt::device& device) : detail::pimpl(create_profiling_event(device)) {} +profiling:: +profiling(const xrt::hw_context& hwctx) + : detail::pimpl(std::make_shared(hwctx)) +{} + int profiling:: start(xrt::aie::profiling::profiling_option option, const std::string& port1_name, const std::string& port2_name, uint32_t value) const { int opt = static_cast(option); return xdp::native::profiling_wrapper("xrt::aie::profiling::start", [this, opt, &port1_name, &port2_name, value] { - return get_handle()->start_profiling(opt, port1_name, port2_name, value); + return get_handle()->start(opt, port1_name, port2_name, value); }); } @@ -414,7 +406,7 @@ profiling:: read() const { return xdp::native::profiling_wrapper("xrt::aie::profiling::read", [this] { - return get_handle()->read_profiling(); + return get_handle()->read(); }); } @@ -423,7 +415,7 @@ profiling:: stop() const { xdp::native::profiling_wrapper("xrt::aie::profiling::stop", [this] { - return get_handle()->stop_profiling(); + return get_handle()->stop(); }); } @@ -868,7 +860,7 @@ xrtAIEStartProfiling(xrtDeviceHandle handle, int option, const char *port1Name, throw xrt_core::error(-EINVAL, "Not a valid profiling option"); const std::string port1 = port1Name ? port1Name : ""; const std::string port2 = port2Name ? port2Name : ""; - auto hdl = event->start_profiling(option, port1, port2, value); + auto hdl = event->start(option, port1, port2, value); if (hdl != xrt::aie::profiling_impl::invalid_handle) { profiling_cache[hdl] = event; return hdl; @@ -901,7 +893,7 @@ xrtAIEReadProfiling(xrtDeviceHandle /*handle*/, int pHandle) try { auto it = profiling_cache.find(pHandle); if (it != profiling_cache.end()) - return it->second->read_profiling(); + return it->second->read(); else throw xrt_core::error(-EINVAL, "No such profiling handle"); } @@ -931,7 +923,7 @@ xrtAIEStopProfiling(xrtDeviceHandle /*handle*/, int pHandle) try { auto it = profiling_cache.find(pHandle); if (it != profiling_cache.end()) { - it->second->stop_profiling(); + it->second->stop(); profiling_cache.erase(pHandle); } else diff --git a/src/runtime_src/core/common/api/xrt_bo.cpp b/src/runtime_src/core/common/api/xrt_bo.cpp index 53427c255a0..5ea1dbc01d5 100755 --- a/src/runtime_src/core/common/api/xrt_bo.cpp +++ b/src/runtime_src/core/common/api/xrt_bo.cpp @@ -433,7 +433,8 @@ class bo_impl void sync(xrt::bo& bo, const std::string& port, xclBOSyncDirection dir, size_t sz, size_t offset) { - device->sync_aie_bo(bo, port.c_str(), dir, sz, offset); + //call sync & async functions with "Buffer handle" instead of with device, so that it could be handled with both device & hwctx + handle->sync_aie_bo(bo, port.c_str(), dir, sz, offset); } xrt::bo::async_handle @@ -611,7 +612,9 @@ xrt::bo::async_handle bo_impl:: async(xrt::bo& bo, const std::string& port, xclBOSyncDirection dir, size_t sz, size_t offset) { - device->sync_aie_bo_nb(bo, port.c_str(), dir, sz, offset); + //call sync & async functions with "Buffer handle" instead of with device, so that it could be handled with both device & hwctx + handle->sync_aie_bo_nb(bo, port.c_str(), dir, sz, offset); + auto a_bo_impl = std::make_shared(bo, 0, port); return xrt::bo::async_handle{a_bo_impl}; diff --git a/src/runtime_src/core/common/ishim.h b/src/runtime_src/core/common/ishim.h index 6066f5276d1..1ddfd0f0008 100755 --- a/src/runtime_src/core/common/ishim.h +++ b/src/runtime_src/core/common/ishim.h @@ -12,6 +12,7 @@ #include "core/include/shim_int.h" #include "core/include/xdp/counters.h" #include "core/common/shim/graph_handle.h" +#include "core/common/shim/profile_handle.h" #include "xrt/xrt_aie.h" #include "xrt/xrt_bo.h" @@ -204,6 +205,12 @@ struct ishim { throw not_supported_error{__func__}; } + + virtual std::unique_ptr + open_profile_handle() + { + throw not_supported_error{__func__}; + } //////////////////////////////////////////////////////////////// virtual void diff --git a/src/runtime_src/core/common/shim/buffer_handle.h b/src/runtime_src/core/common/shim/buffer_handle.h index acc95894629..4641002ff17 100755 --- a/src/runtime_src/core/common/shim/buffer_handle.h +++ b/src/runtime_src/core/common/shim/buffer_handle.h @@ -5,6 +5,8 @@ #include "core/common/shim/shared_handle.h" #include "xrt.h" +#include "xrt/xrt_bo.h" +#include "core/common/error.h" #include #include @@ -87,6 +89,18 @@ class buffer_handle bind_at(size_t /*pos*/, const buffer_handle* /*bh*/, size_t /*offset*/, size_t /*size*/) { } + + virtual void + sync_aie_bo(xrt::bo&, const char *, xclBOSyncDirection, size_t, size_t) + { + throw xrt_core::error(std::errc::not_supported, __func__); + } + + virtual void + sync_aie_bo_nb(xrt::bo&, const char *, xclBOSyncDirection, size_t, size_t) + { + throw xrt_core::error(std::errc::not_supported, __func__); + } }; } // xrt_core diff --git a/src/runtime_src/core/common/shim/hwctx_handle.h b/src/runtime_src/core/common/shim/hwctx_handle.h index efc222c32ec..ac096ee4217 100755 --- a/src/runtime_src/core/common/shim/hwctx_handle.h +++ b/src/runtime_src/core/common/shim/hwctx_handle.h @@ -8,6 +8,7 @@ #include "core/common/shim/hwqueue_handle.h" #include "core/common/shim/shared_handle.h" #include "core/common/shim/graph_handle.h" +#include "profile_handle.h" #include "xrt/xrt_hw_context.h" #include "xrt/xrt_graph.h" @@ -99,6 +100,12 @@ class hwctx_handle { throw xrt_core::error(std::errc::not_supported, __func__); } + + virtual std::unique_ptr + open_profile_handle() + { + throw xrt_core::error(std::errc::not_supported, __func__); + } }; } // xrt_core diff --git a/src/runtime_src/core/common/shim/profile_handle.h b/src/runtime_src/core/common/shim/profile_handle.h new file mode 100644 index 00000000000..2bed4a7c77f --- /dev/null +++ b/src/runtime_src/core/common/shim/profile_handle.h @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright (C) 2023-2024 Advanced Micro Devices, Inc. All rights reserved. +#ifndef XRT_CORE_PROFILE_HANDLE_H +#define XRT_CORE_PROFILE_HANDLE_H + +#include +#include "core/common/error.h" + +namespace xrt_core { + class profile_handle + { + public: + virtual int + start(int, const char*, const char*, uint32_t) + { + throw xrt_core::error(std::errc::not_supported, __func__); + } + + virtual uint64_t + read() + { + throw xrt_core::error(std::errc::not_supported, __func__); + } + + virtual void + stop() + { + throw xrt_core::error(std::errc::not_supported, __func__); + } + }; //profile_handle +} //namespace xrt_core +#endif diff --git a/src/runtime_src/core/edge/user/aie/profile_object.cpp b/src/runtime_src/core/edge/user/aie/profile_object.cpp new file mode 100644 index 00000000000..f91552ad125 --- /dev/null +++ b/src/runtime_src/core/edge/user/aie/profile_object.cpp @@ -0,0 +1,57 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved. +#include "profile_object.h" +#include "core/edge/user/shim.h" + +static inline +std::string value_or_empty(const char* s) +{ + return s == nullptr ? "" : s; +} + +namespace zynqaie { + + profile_object:: + profile_object(ZYNQ::shim* shim, Aie* aie_array) + : m_shim{shim}, + m_aie_array{aie_array}, + m_profile_id{invalid_profile_id} + {} + + int + profile_object:: + start(int option, const char* port1Name, const char* port2Name, uint32_t value) + { + 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_profile_id = m_aie_array->start_profiling(option, value_or_empty(port1Name), value_or_empty(port2Name), value); + return m_profile_id; + } + + uint64_t + profile_object:: + read() + { + 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); + } + return m_aie_array->read_profiling(m_profile_id); + } + + void + profile_object:: + stop() + { + 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->stop_profiling(m_profile_id); + } +} //namespace zynqaie diff --git a/src/runtime_src/core/edge/user/aie/profile_object.h b/src/runtime_src/core/edge/user/aie/profile_object.h new file mode 100644 index 00000000000..e04c7f64cb1 --- /dev/null +++ b/src/runtime_src/core/edge/user/aie/profile_object.h @@ -0,0 +1,37 @@ +// SPDX-License-Identifier: Apache-2.0 +// Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved. +#ifndef _ZYNQ_PROFILE_OBJECT_H_ +#define _ZYNQ_PROFILE_OBJECT_H_ + +#include "core/common/shim/profile_handle.h" +#include + +namespace ZYNQ { + class shim; +} + +namespace zynqaie { + class Aie; + + class profile_object : public xrt_core::profile_handle + { + public: + static constexpr int invalid_profile_id = -1; + ZYNQ::shim* m_shim{nullptr}; + Aie* m_aie_array{nullptr}; + int m_profile_id; + + profile_object(ZYNQ::shim* shim, Aie* aie_array); + + int + start(int option, const char* port1Name, const char* port2Name, uint32_t value) override; + + uint64_t + read() override; + + void + stop() override; + + }; //profile_object +} // namespace zynqaie +#endif diff --git a/src/runtime_src/core/edge/user/device_linux.cpp b/src/runtime_src/core/edge/user/device_linux.cpp index 6395eb6de72..ce0de6edc46 100644 --- a/src/runtime_src/core/edge/user/device_linux.cpp +++ b/src/runtime_src/core/edge/user/device_linux.cpp @@ -13,6 +13,7 @@ #ifdef XRT_ENABLE_AIE #include "core/edge/user/aie/graph_object.h" #endif +#include "core/edge/user/aie/profile_object.h" #include #include #include @@ -1142,6 +1143,26 @@ open_graph_handle(const xrt::uuid& xclbin_id, const char* name, xrt::graph::acce #endif } +std::unique_ptr +device_linux:: +open_profile_handle() +{ +#ifdef XRT_ENABLE_AIE + + auto drv = ZYNQ::shim::handleCheck(get_device_handle()); + + if (not drv->isAieRegistered()) + throw xrt_core::error(-EINVAL, "No AIE presented"); + + auto aie_array = drv->getAieArray(); + + return std::make_unique(static_cast(get_device_handle()), aie_array); + +#else + return nullptr; +#endif +} + std::unique_ptr device_linux:: import_bo(pid_t pid, shared_handle::export_handle ehdl) diff --git a/src/runtime_src/core/edge/user/device_linux.h b/src/runtime_src/core/edge/user/device_linux.h index 2d47bcf9b35..88df54f0c31 100644 --- a/src/runtime_src/core/edge/user/device_linux.h +++ b/src/runtime_src/core/edge/user/device_linux.h @@ -11,6 +11,7 @@ #include "core/common/shim/shared_handle.h" #include "core/edge/common/device_edge.h" #include "core/common/shim/graph_handle.h" +#include "core/common/shim/profile_handle.h" namespace xrt_core { @@ -39,6 +40,9 @@ class device_linux : public shim std::unique_ptr open_graph_handle(const xrt::uuid& xclbin_id, const char* name, xrt::graph::access_mode am) override; + std::unique_ptr + open_profile_handle() override; + void get_device_info(xclDeviceInfo2 *info) override; diff --git a/src/runtime_src/core/edge/user/hwctx_object.cpp b/src/runtime_src/core/edge/user/hwctx_object.cpp index 7c367972979..4588e0a8473 100644 --- a/src/runtime_src/core/edge/user/hwctx_object.cpp +++ b/src/runtime_src/core/edge/user/hwctx_object.cpp @@ -1,8 +1,10 @@ // SPDX-License-Identifier: Apache-2.0 // Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved. #include "hwctx_object.h" +#include "core/edge/user/aie/profile_object.h" #ifdef XRT_ENABLE_AIE #include "core/edge/user/aie/graph_object.h" +#include "core/edge/user/aie/aie.h" #endif #include "core/edge/user/shim.h" @@ -17,20 +19,39 @@ namespace zynqaie { , m_uuid(std::move(uuid)) , m_slotidx(slotidx) , m_mode(mode) - {} + { +#ifdef XRT_ENABLE_AIE + auto device{xrt_core::get_userpf_device(m_shim)}; + m_aie_array = std::make_unique(device); +#endif + } + +#ifdef XRT_ENABLE_AIE + Aie* + hwctx_object::get_aie_array_from_hwctx() + { + return m_aie_array.get(); + } + + bool + hwctx_object::is_aie_registered() + { + return (nullptr != m_aie_array); + } +#endif std::unique_ptr hwctx_object::alloc_bo(void* userptr, size_t size, uint64_t flags) { // The hwctx is embedded in the flags, use regular shim path - return m_shim->xclAllocUserPtrBO(userptr, size, xcl_bo_flags{flags}.flags); + return m_shim->xclAllocUserPtrBO(userptr, size, xcl_bo_flags{flags}.flags, this); } std::unique_ptr hwctx_object::alloc_bo(size_t size, uint64_t flags) { // The hwctx is embedded in the flags, use regular shim path - return m_shim->xclAllocBO(size, xcl_bo_flags{flags}.flags); + return m_shim->xclAllocBO(size, xcl_bo_flags{flags}.flags, this); } xrt_core::cuidx_type @@ -60,4 +81,15 @@ namespace zynqaie { return nullptr; #endif } + + std::unique_ptr + hwctx_object::open_profile_handle() + { +#ifdef XRT_ENABLE_AIE + return std::make_unique(m_shim, m_aie_array.get()); +#else + return nullptr; +#endif + } + } diff --git a/src/runtime_src/core/edge/user/hwctx_object.h b/src/runtime_src/core/edge/user/hwctx_object.h index 2b8bb26756c..a554d0d3f43 100644 --- a/src/runtime_src/core/edge/user/hwctx_object.h +++ b/src/runtime_src/core/edge/user/hwctx_object.h @@ -6,6 +6,7 @@ #include "core/common/shim/hwctx_handle.h" #include "core/common/shim/shared_handle.h" #include "core/common/shim/graph_handle.h" +#include "core/common/shim/profile_handle.h" // Shim handle for hardware context Even as hw_emu does not // support hardware context, it still must implement a shim @@ -15,12 +16,17 @@ namespace ZYNQ { } namespace zynqaie { + class Aie; + class hwctx_object : public xrt_core::hwctx_handle { ZYNQ::shim* m_shim; xrt::uuid m_uuid; slot_id m_slotidx; xrt::hw_context::access_mode m_mode; +#ifdef XRT_ENABLE_AIE + std::unique_ptr m_aie_array; +#endif public: hwctx_object(ZYNQ::shim* shim, slot_id slotidx, xrt::uuid uuid, xrt::hw_context::access_mode mode); @@ -72,6 +78,18 @@ namespace zynqaie { std::unique_ptr open_graph_handle(const char* name, xrt::graph::access_mode am) override; + + std::unique_ptr + open_profile_handle() override; + +#ifdef XRT_ENABLE_AIE + Aie* + get_aie_array_from_hwctx(); + + bool + is_aie_registered(); +#endif + }; // class hwctx_object } #endif diff --git a/src/runtime_src/core/edge/user/shim.cpp b/src/runtime_src/core/edge/user/shim.cpp index 7a574dbf0ec..94ccd8c7cb6 100644 --- a/src/runtime_src/core/edge/user/shim.cpp +++ b/src/runtime_src/core/edge/user/shim.cpp @@ -284,7 +284,7 @@ xclRead(xclAddressSpace space, uint64_t offset, void *hostBuf, size_t size) std::unique_ptr shim:: -xclAllocBO(size_t size, unsigned flags) +xclAllocBO(size_t size, unsigned flags, xrt_core::hwctx_handle* hwctx_hdl) { drm_zocl_create_bo info = { size, 0xffffffff, flags}; int result = ioctl(mKernelFD, DRM_IOCTL_ZOCL_CREATE_BO, &info); @@ -295,12 +295,12 @@ xclAllocBO(size_t size, unsigned flags) xclLog(XRT_DEBUG, "%s: size %ld, flags 0x%x", __func__, size, flags); xclLog(XRT_INFO, "%s: ioctl return %d, bo handle %d", __func__, result, info.handle); - return std::make_unique(this, info.handle); + return std::make_unique(this, info.handle, hwctx_hdl); } std::unique_ptr shim:: -xclAllocUserPtrBO(void *userptr, size_t size, unsigned flags) +xclAllocUserPtrBO(void *userptr, size_t size, unsigned flags, xrt_core::hwctx_handle* hwctx_hdl) { flags |= DRM_ZOCL_BO_FLAGS_USERPTR; drm_zocl_userptr_bo info = {reinterpret_cast(userptr), size, 0xffffffff, flags}; @@ -312,7 +312,7 @@ xclAllocUserPtrBO(void *userptr, size_t size, unsigned flags) xclLog(XRT_DEBUG, "%s: userptr %p size %ld, flags 0x%x", __func__, userptr, size, flags); xclLog(XRT_INFO, "%s: ioctl return %d, bo handle %d", __func__, result, info.handle); - return std::make_unique(this, info.handle); + return std::make_unique(this, info.handle, hwctx_hdl); } unsigned int diff --git a/src/runtime_src/core/edge/user/shim.h b/src/runtime_src/core/edge/user/shim.h index 425129054f0..164d6ac5581 100644 --- a/src/runtime_src/core/edge/user/shim.h +++ b/src/runtime_src/core/edge/user/shim.h @@ -75,11 +75,33 @@ class shim { shim* m_shim; xclBufferHandle m_hdl; +#ifdef XRT_ENABLE_AIE + zynqaie::Aie* m_aie_array{nullptr}; +#endif + public: - buffer_object(shim* shim, xclBufferHandle hdl) - : m_shim(shim) - , m_hdl(hdl) - {} + buffer_object(shim* shim, xclBufferHandle hdl, xrt_core::hwctx_handle* hwctx_hdl = nullptr) + : m_shim{shim} + , m_hdl{hdl} + { +#ifdef XRT_ENABLE_AIE + if (nullptr != hwctx_hdl) { // hwctx specific + auto hwctx_obj = dynamic_cast(hwctx_hdl); + if (nullptr != hwctx_obj) { + if (!hwctx_obj->is_aie_registered()) + throw xrt_core::error(-EINVAL, "No AIE presented"); + m_aie_array = hwctx_obj->get_aie_array_from_hwctx(); + } + } + else { + auto device = xrt_core::get_userpf_device(m_shim); + auto drv = ZYNQ::shim::handleCheck(device->get_device_handle()); + if (!drv->isAieRegistered()) + throw xrt_core::error(-EINVAL, "No AIE presented"); + m_aie_array = drv->getAieArray(); + } +#endif + } ~buffer_object() { @@ -152,6 +174,43 @@ class shim { { return m_hdl; } + + void + sync_aie_bo(xrt::bo& bo, const char *gmioName, xclBOSyncDirection dir, size_t size, size_t offset) override + { +#ifdef XRT_ENABLE_AIE + if (!m_aie_array->is_context_set()) { + auto device = xrt_core::get_userpf_device(m_shim); + m_aie_array->open_context(device.get(), xrt::aie::access_mode::primary); + } + + auto bosize = bo.size(); + + if (offset + size > bosize) + throw xrt_core::error(-EINVAL, "Sync AIE BO fails: exceed BO boundary."); + + m_aie_array->sync_bo(bo, gmioName, dir, size, offset); +#endif + } + + void + sync_aie_bo_nb(xrt::bo& bo, const char *gmioName, xclBOSyncDirection dir, size_t size, size_t offset) override + { +#ifdef XRT_ENABLE_AIE + if (!m_aie_array->is_context_set()) { + auto device = xrt_core::get_userpf_device(m_shim); + m_aie_array->open_context(device.get(), xrt::aie::access_mode::primary); + } + + auto bosize = bo.size(); + + if (offset + size > bosize) + throw xrt_core::error(-EINVAL, "Sync AIE NBO fails: exceed BO boundary."); + + m_aie_array->sync_bo_nb(bo, gmioName, dir, size, offset); +#endif + } + }; // buffer_object ~shim(); @@ -170,10 +229,10 @@ class shim { int xclRegRead(uint32_t ipIndex, uint32_t offset, uint32_t *datap); std::unique_ptr - xclAllocBO(size_t size, unsigned flags); + xclAllocBO(size_t size, unsigned flags, xrt_core::hwctx_handle* hwctx_hdl = nullptr); std::unique_ptr - xclAllocUserPtrBO(void *userptr, size_t size, unsigned int flags); + xclAllocUserPtrBO(void *userptr, size_t size, unsigned int flags, xrt_core::hwctx_handle* hwctx_hdl = nullptr); std::unique_ptr xclExportBO(unsigned int boHandle); diff --git a/src/runtime_src/core/include/xrt/xrt_aie.h b/src/runtime_src/core/include/xrt/xrt_aie.h index 1aa80b833aa..efec605b613 100644 --- a/src/runtime_src/core/include/xrt/xrt_aie.h +++ b/src/runtime_src/core/include/xrt/xrt_aie.h @@ -298,6 +298,9 @@ class profiling : public detail::pimpl explicit profiling(const xrt::device& device); + explicit + profiling(const xrt::hw_context& hwctx); + /** * start() - Start AIE performance profiling *