Skip to content

Commit

Permalink
ML Timeline Plugin for VE2 (#8683)
Browse files Browse the repository at this point in the history
* Add ML Timeline for VE2

Signed-off-by: Ishita Ghosh <[email protected]>

* Add ML Timeline for VE2

Signed-off-by: Ishita Ghosh <[email protected]>

* Add ML Timeline for VE2

Signed-off-by: Ishita Ghosh <[email protected]>

* Add ML Timeline for VE2

Signed-off-by: Ishita Ghosh <[email protected]>

* Add ML Timeline for VE2

Signed-off-by: Ishita Ghosh <[email protected]>

* Add ML Timeline for VE2

Signed-off-by: Ishita Ghosh <[email protected]>

---------

Signed-off-by: Ishita Ghosh <[email protected]>
Co-authored-by: Ishita Ghosh <[email protected]>
  • Loading branch information
IshitaGhosh and Ishita Ghosh authored Jan 7, 2025
1 parent acc1449 commit 4da01b6
Show file tree
Hide file tree
Showing 7 changed files with 362 additions and 12 deletions.
8 changes: 7 additions & 1 deletion src/runtime_src/core/common/xdp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (C) 2022 Advanced Micro Devices, Inc. All rights reserved.
# Copyright (C) 2022-2025 Advanced Micro Devices, Inc. All rights reserved.
add_library(core_common_xdp_profile_objects OBJECT
profile.cpp
)
Expand All @@ -14,4 +14,10 @@ if (XDP_CLIENT_BUILD_CMAKE STREQUAL "yes")
PRIVATE
XDP_CLIENT_BUILD=1
)

elseif (XDP_VE2_BUILD_CMAKE STREQUAL "yes")
target_compile_definitions(core_common_xdp_profile_objects
PRIVATE
XDP_VE2_BUILD=1
)
endif()
22 changes: 20 additions & 2 deletions src/runtime_src/core/common/xdp/profile.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2023-2024 Advanced Micro Devices, Inc. - All rights reserved
// Copyright (C) 2023-2025 Advanced Micro Devices, Inc. - All rights reserved
#define XRT_CORE_COMMON_SOURCE
#include "core/common/xdp/profile.h"

Expand Down Expand Up @@ -140,11 +140,12 @@ std::function<void (void*)> finish_flush_device_cb;
void
register_callbacks(void* handle)
{
#ifdef XDP_CLIENT_BUILD
#if defined(XDP_CLIENT_BUILD) || defined(XDP_VE2_BUILD)
using ftype = void (*)(void*);

update_device_cb = reinterpret_cast<ftype>(xrt_core::dlsym(handle, "updateDeviceMLTmln"));
finish_flush_device_cb = reinterpret_cast<ftype>(xrt_core::dlsym(handle, "finishflushDeviceMLTmln"));

#else
(void)handle;
#endif
Expand Down Expand Up @@ -461,6 +462,18 @@ update_device(void* handle)
xrt_core::xdp::aie_pc::update_device(handle);
}

#elif defined(XDP_VE2_BUILD)

if (xrt_core::config::get_ml_timeline()) {
try {
xrt_core::xdp::ml_timeline::load();
}
catch (...) {
return;
}
xrt_core::xdp::ml_timeline::update_device(handle);
}

#else

if (xrt_core::config::get_pl_deadlock_detection()
Expand Down Expand Up @@ -495,6 +508,11 @@ finish_flush_device(void* handle)
if (xrt_core::config::get_aie_pc())
xrt_core::xdp::aie_pc::finish_flush_device(handle);

#elif defined(XDP_VE2_BUILD)

if (xrt_core::config::get_ml_timeline())
xrt_core::xdp::ml_timeline::finish_flush_device(handle);

#else

if (xrt_core::config::get_pl_deadlock_detection()
Expand Down
3 changes: 2 additions & 1 deletion src/runtime_src/xdp/profile/plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (C) 2022-2023 Advanced Micro Devices, Inc. All rights reserved.
# Copyright (C) 2022-2025 Advanced Micro Devices, Inc. All rights reserved.
#

if(XDP_VE2_BUILD_CMAKE STREQUAL "yes")
add_subdirectory(aie_profile)
add_subdirectory(aie_trace)
add_subdirectory(ml_timeline)

elseif (XDP_CLIENT_BUILD_CMAKE STREQUAL "yes")

Expand Down
30 changes: 26 additions & 4 deletions src/runtime_src/xdp/profile/plugin/ml_timeline/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
# Copyright (C) 2023-2025 Advanced Micro Devices, Inc. All rights reserved.
#

# ===========================================================================
# This builds the ML Timeline plugin. It is currently built on Windows Only.
# ===========================================================================
# ========================================================================================
# This builds the ML Timeline plugin.
# It is currently built for Client on Windows and Linux, and also for VE2 Device on Linux.
# ========================================================================================

if (XDP_CLIENT_BUILD_CMAKE STREQUAL "yes")
set(IMPL_DIR "${PROFILE_DIR}/plugin/ml_timeline/clientDev")
endif()

if (XDP_VE2_BUILD_CMAKE STREQUAL "yes")
set(IMPL_DIR "${PROFILE_DIR}/plugin/ml_timeline/ve2")
endif()

file(GLOB ML_TIMELINE_PLUGIN_FILES
"${PROFILE_DIR}/plugin/ml_timeline/*.h"
"${PROFILE_DIR}/plugin/ml_timeline/*.cpp"
Expand All @@ -31,4 +36,21 @@ if (XDP_CLIENT_BUILD_CMAKE STREQUAL "yes")
LIBRARY DESTINATION ${XDP_PLUGIN_INSTALL_DIR}
)

elseif (XDP_VE2_BUILD_CMAKE STREQUAL "yes")

add_library(xdp_ml_timeline_plugin MODULE ${ML_TIMELINE_PLUGIN_FILES})
add_dependencies(xdp_ml_timeline_plugin xdp_core xrt_coreutil)

target_include_directories(xdp_ml_timeline_plugin PRIVATE ${CMAKE_SOURCE_DIR}/src)

target_link_libraries(xdp_ml_timeline_plugin PRIVATE xdp_core xrt_coreutil)

target_compile_definitions(xdp_ml_timeline_plugin PRIVATE XDP_VE2_BUILD=1)

set_target_properties(xdp_ml_timeline_plugin PROPERTIES VERSION ${XRT_VERSION_STRING} SOVERSION ${XRT_SOVERSION})

install (TARGETS xdp_ml_timeline_plugin
LIBRARY DESTINATION ${XDP_PLUGIN_INSTALL_DIR}
)

endif()
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2023-2024 Advanced Micro Devices, Inc. - All rights reserved
* Copyright (C) 2023-2025 Advanced Micro Devices, Inc. - All rights reserved
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may
* not use this file except in compliance with the License. A copy of the
Expand Down Expand Up @@ -30,6 +30,8 @@

#ifdef XDP_CLIENT_BUILD
#include "xdp/profile/plugin/ml_timeline/clientDev/ml_timeline.h"
#elif defined (XDP_VE2_BUILD)
#include "xdp/profile/plugin/ml_timeline/ve2/ml_timeline.h"
#endif

namespace xdp {
Expand Down Expand Up @@ -114,6 +116,9 @@ namespace xdp {

void MLTimelinePlugin::updateDevice(void* hwCtxImpl)
{
xrt_core::message::send(xrt_core::message::severity_level::info, "XRT",
"In ML Timeline Plugin : updateDevice.");

#ifdef XDP_CLIENT_BUILD

if (mMultiImpl.find(hwCtxImpl) != mMultiImpl.end()) {
Expand All @@ -138,12 +143,47 @@ namespace xdp {
auto mlImpl = mMultiImpl[hwCtxImpl].second.get();
mlImpl->updateDevice(hwCtxImpl);

#endif
#elif defined (XDP_VE2_BUILD)

if (mMultiImpl.find(hwCtxImpl) != mMultiImpl.end()) {
// Same Hardware Context Implementation uses the same impl and buffer
return;
}

if (0 == mBufSz)
mBufSz = ParseMLTimelineBufferSizeConfig();

xrt::hw_context hwContext = xrt_core::hw_context_int::create_hw_context_from_implementation(hwCtxImpl);
std::shared_ptr<xrt_core::device> coreDevice = xrt_core::hw_context_int::get_core_device(hwContext);

xclDeviceHandle h = coreDevice->get_device_handle();
if (nullptr == h) {
xrt_core::message::send(xrt_core::message::severity_level::debug, "XRT",
"In ML Timeline Plugin for VE2 Device : Devicehandle is NULL");
return;
}

uint64_t implId = mMultiImpl.size();

std::string deviceName = "ve2_device" + std::to_string(implId);
uint64_t deviceId = db->addDevice(deviceName);
(db->getStaticInfo()).updateDeviceClient(deviceId, coreDevice, false);
(db->getStaticInfo()).setDeviceName(deviceId, deviceName);

mMultiImpl[hwCtxImpl] = std::make_pair(implId, std::make_unique<MLTimelineVE2Impl>(db, mBufSz));
auto mlImpl = mMultiImpl[hwCtxImpl].second.get();
mlImpl->updateDevice(h);

#endif

}

void MLTimelinePlugin::finishflushDevice(void* hwCtxImpl)
{
#ifdef XDP_CLIENT_BUILD
xrt_core::message::send(xrt_core::message::severity_level::info, "XRT",
"In ML Timeline Plugin : finish flush Device.");

#if defined(XDP_CLIENT_BUILD) || defined(XDP_VE2_BUILD)
if (mMultiImpl.empty()) {
xrt_core::message::send(xrt_core::message::severity_level::debug, "XRT",
"In ML Timeline Plugin : No active HW Context found. So no data flush done.");
Expand All @@ -167,7 +207,7 @@ namespace xdp {

void MLTimelinePlugin::writeAll(bool /*openNewFiles*/)
{
#ifdef XDP_CLIENT_BUILD
#if defined(XDP_CLIENT_BUILD) || defined(XDP_VE2_BUILD)
for (auto &e : mMultiImpl) {
if (nullptr == e.second.second)
continue;
Expand Down
Loading

0 comments on commit 4da01b6

Please sign in to comment.