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

AIE Halt Plugin for VE2 #8808

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions src/runtime_src/core/common/config_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,13 @@ get_aie_halt()
return value;
}

inline std::string
get_aie_halt_settings_control_code()
{
static std::string value = detail::get_string_value("AIE_halt_settings.control_code", "");
return value;
}

inline bool
get_profile_api()
{
Expand Down
20 changes: 17 additions & 3 deletions src/runtime_src/core/common/xdp/profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ 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)
update_device_cb = reinterpret_cast<void (*)(void*)>(xrt_core::dlsym(handle, "updateDeviceAIEHalt"));
finish_flush_device_cb = reinterpret_cast<void (*)(void*)>(xrt_core::dlsym(handle, "finishFlushDeviceAIEHalt"));
#else
Expand Down Expand Up @@ -473,11 +473,23 @@ update_device(void* handle)
if (xrt_core::config::get_ml_timeline()) {
try {
xrt_core::xdp::ml_timeline::load();
xrt_core::xdp::ml_timeline::update_device(handle);
}
catch (...) {
return;
xrt_core::message::send(xrt_core::message::severity_level::debug, "XRT",
"Failed to load ML Timeline library.");
}
}

if (xrt_core::config::get_aie_halt()) {
try {
xrt_core::xdp::aie::halt::load();
xrt_core::xdp::aie::halt::update_device(handle);
}
xrt_core::xdp::ml_timeline::update_device(handle);
catch (...) {
xrt_core::message::send(xrt_core::message::severity_level::debug, "XRT",
"Failed to load AIE Halt library.");
}
}

#else
Expand Down Expand Up @@ -518,6 +530,8 @@ finish_flush_device(void* handle)

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

#else

Expand Down
1 change: 1 addition & 0 deletions src/runtime_src/xdp/profile/plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ if (XDP_VE2_BUILD_CMAKE STREQUAL "yes")
add_subdirectory(aie_trace)
add_subdirectory(aie_debug)
add_subdirectory(ml_timeline)
add_subdirectory(aie_halt)
add_subdirectory(native)
add_subdirectory(user)

Expand Down
24 changes: 21 additions & 3 deletions src/runtime_src/xdp/profile/plugin/aie_halt/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
# Copyright (C) 2024-2025 Advanced Micro Devices, Inc. All rights reserved.
#

# =======================================================================
# This builds the AIE Halt Plugin to add Debug Halts for all AIE Cores at
# the start. It is currently built on Client Windows Only.
# the start. It is currently built on Client and VE2
# =========================================================================

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

elseif (XDP_VE2_BUILD_CMAKE STREQUAL "yes")
set(IMPL_DIR "${PROFILE_DIR}/plugin/aie_halt/ve2")

endif()

file(GLOB XDP_AIE_HALT_PLUGIN_FILES
"${PROFILE_DIR}/plugin/aie_halt/*.h"
Expand All @@ -36,6 +39,21 @@ if (XDP_CLIENT_BUILD_CMAKE STREQUAL "yes")
LIBRARY DESTINATION ${XDP_PLUGIN_INSTALL_DIR} COMPONENT ${XRT_COMPONENT}
)

elseif (XDP_VE2_BUILD_CMAKE STREQUAL "yes")
add_library(xdp_aie_halt_plugin MODULE ${XDP_AIE_HALT_PLUGIN_FILES})
add_dependencies(xdp_aie_halt_plugin xdp_core xrt_coreutil)

#target_include_directories(xdp_aie_halt_plugin PRIVATE ${AIERT_DIR}/include)
#target_link_libraries(xdp_aie_halt_plugin PRIVATE xdp_core xrt_coreutil xaiengine)
target_link_libraries(xdp_aie_halt_plugin PRIVATE xdp_core xrt_coreutil)
target_compile_definitions(xdp_aie_halt_plugin PRIVATE XDP_VE2_BUILD=1)

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

install (TARGETS xdp_aie_halt_plugin
LIBRARY DESTINATION ${XDP_PLUGIN_INSTALL_DIR} COMPONENT ${XRT_COMPONENT}
)

# Else, on edge-aarch64 don't build at all

endif()
28 changes: 25 additions & 3 deletions src/runtime_src/xdp/profile/plugin/aie_halt/aie_halt_plugin.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2024 Advanced Micro Devices, Inc. - All rights reserved
* Copyright (C) 2024-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/aie_halt/clientDev/aie_halt.h"
#elif defined (XDP_VE2_BUILD)
#include "xdp/profile/plugin/aie_halt/ve2/aie_halt.h"
#endif

namespace xdp {
Expand Down Expand Up @@ -85,12 +87,32 @@ namespace xdp {
DeviceDataEntry.implementation = std::make_unique<AIEHaltClientDevImpl>(db);
DeviceDataEntry.implementation->setHwContext(hwContext);
DeviceDataEntry.implementation->updateDevice(mHwCtxImpl);

#elif defined (XDP_VE2_BUILD)
if (mHwCtxImpl) {
// For VE2 device flow, only 1 device and xclbin is supported now.
return;
}
mHwCtxImpl = hwCtxImpl;

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

// Only one device for VE2 Device flow
uint64_t deviceId = db->addDevice("ve2_device");
(db->getStaticInfo()).updateDeviceClient(deviceId, coreDevice, false);
(db->getStaticInfo()).setDeviceName(deviceId, "ve2_device");

DeviceDataEntry.valid = true;
DeviceDataEntry.implementation = std::make_unique<AIEHaltVE2Impl>(db);
DeviceDataEntry.implementation->setHwContext(hwContext);
DeviceDataEntry.implementation->updateDevice(mHwCtxImpl);
#endif
}

void AIEHaltPlugin::finishflushDevice(void* hwCtxImpl)
{
#ifdef XDP_CLIENT_BUILD
#if defined(XDP_CLIENT_BUILD) || defined(XDP_VE2_BUILD)
if (!mHwCtxImpl || !DeviceDataEntry.valid) {
return;
}
Expand All @@ -108,7 +130,7 @@ namespace xdp {

void AIEHaltPlugin::writeAll(bool /*openNewFiles*/)
{
#ifdef XDP_CLIENT_BUILD
#if defined(XDP_CLIENT_BUILD) || defined(XDP_VE2_BUILD)

if (!mHwCtxImpl || !DeviceDataEntry.valid) {
return;
Expand Down
86 changes: 86 additions & 0 deletions src/runtime_src/xdp/profile/plugin/aie_halt/ve2/aie_halt.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/**
* Copyright (C) 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
* License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

#define XDP_PLUGIN_SOURCE

#include "core/common/api/hw_context_int.h"
#include "core/common/device.h"
#include "core/common/message.h"

#include "core/include/xrt/experimental/xrt_elf.h"
#include "core/include/xrt/experimental/xrt_ext.h"
#include "core/include/xrt/experimental/xrt_module.h"

#include "core/include/xrt/xrt_kernel.h"

#include "xdp/profile/plugin/aie_halt/ve2/aie_halt.h"
#include "xdp/profile/plugin/vp_base/utility.h"

namespace xdp {

AIEHaltVE2Impl::AIEHaltVE2Impl(VPDatabase*dB)
: AIEHaltImpl(dB)
{
}

void AIEHaltVE2Impl::updateDevice(void* hwCtxImpl)
{
xrt_core::message::send(xrt_core::message::severity_level::debug, "XRT",
"In AIEHaltVE2Impl::updateDevice");

std::string inputCtrlCode = xrt_core::config::get_aie_halt_settings_control_code();
if (inputCtrlCode.empty()) {
xrt_core::message::send(xrt_core::message::severity_level::debug, "XRT",
"No input control code file for AIE Halt provided. Defaulting to \"aieHalt4x4.elf\".");
inputCtrlCode = "aieHalt4x4.elf";
}

xrt::hw_context hwContext = xrt_core::hw_context_int::create_hw_context_from_implementation(hwCtxImpl);

xrt::elf haltElf;
try {
haltElf = xrt::elf(inputCtrlCode);
} catch (...) {
std::string msg = "Failed to load " + inputCtrlCode + ". Cannot configure AIE to halt.";
xrt_core::message::send(xrt_core::message::severity_level::warning, "XRT", msg);
return;
}

xrt::module mod{haltElf};
xrt::kernel krnl;
try {
krnl = xrt::ext::kernel{hwContext, mod, "XDP_KERNEL:{IPUV1CNN}"};
} catch (...) {
xrt_core::message::send(xrt_core::message::severity_level::warning, "XRT",
"XDP_KERNEL not found in HW Context. Cannot configure AIE to halt.");
return;
}

xrt_core::message::send(xrt_core::message::severity_level::debug, "XRT",
"In AIEHaltVE2Impl New Kernel Object for XDP_KERNEL created for running control code Elf");

xrt::run rn{krnl};
rn.start();
xrt_core::message::send(xrt_core::message::severity_level::debug, "XRT",
"In AIEHaltVE2Impl run start, going to wait");

rn.wait2();
}

void AIEHaltVE2Impl::finishflushDevice(void* /*hwCtxImpl*/)
{
}
}
39 changes: 39 additions & 0 deletions src/runtime_src/xdp/profile/plugin/aie_halt/ve2/aie_halt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Copyright (C) 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
* License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

#ifndef XDP_PLUGIN_AIE_HALT_VE2_IMPL_H
#define XDP_PLUGIN_AIE_HALT_VE2_IMPL_H

#include "xdp/config.h"
#include "xdp/profile/plugin/aie_halt/aie_halt_impl.h"

namespace xdp {

class AIEHaltVE2Impl : public AIEHaltImpl
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: class 'AIEHaltVE2Impl' defines a default destructor but does not define a copy constructor, a copy assignment operator, a move constructor or a move assignment operator [cppcoreguidelines-special-member-functions]

  class AIEHaltVE2Impl : public AIEHaltImpl
        ^

{

public :
AIEHaltVE2Impl(VPDatabase* dB);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: single-argument constructors must be marked explicit to avoid unintentional implicit conversions [hicpp-explicit-conversions]

Suggested change
AIEHaltVE2Impl(VPDatabase* dB);
explicit AIEHaltVE2Impl(VPDatabase* dB);


~AIEHaltVE2Impl() = default;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: annotate this function with 'override' or (rarely) 'final' [hicpp-use-override]

Suggested change
~AIEHaltVE2Impl() = default;
~AIEHaltVE2Impl() override = default;


virtual void updateDevice(void* hwCtxImpl);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: prefer using 'override' or (rarely) 'final' instead of 'virtual' [cppcoreguidelines-explicit-virtual-functions]

Suggested change
virtual void updateDevice(void* hwCtxImpl);
void updateDevice(void* hwCtxImpl) override;

virtual void finishflushDevice(void* hwCtxImpl);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: prefer using 'override' or (rarely) 'final' instead of 'virtual' [cppcoreguidelines-explicit-virtual-functions]

Suggested change
virtual void finishflushDevice(void* hwCtxImpl);
void finishflushDevice(void* hwCtxImpl) override;

};

}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
#include <fstream>
#include <regex>

#include "shim/shim.h"

#include "core/common/api/bo_int.h"
#include "core/common/api/hw_context_int.h"
#include "core/common/device.h"
Expand Down
Loading