Skip to content

Commit

Permalink
XDP AIE PC Plugin to capture total execution cycles of specified func…
Browse files Browse the repository at this point in the history
…tions (#8439)
  • Loading branch information
IshitaGhosh authored Oct 8, 2024
1 parent ab21783 commit 36c792b
Show file tree
Hide file tree
Showing 12 changed files with 892 additions and 17 deletions.
14 changes: 14 additions & 0 deletions src/runtime_src/core/common/config_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,20 @@ get_ml_timeline_buffer_size()
return value;
}

inline bool
get_aie_pc()
{
static bool value = detail::get_bool_value("Debug.aie_pc",false);
return value;
}

inline std::string
get_aie_pc_settings()
{
static std::string value = detail::get_string_value("AIE_pc_settings.addresses", "");
return value;
}

inline bool
get_aie_halt()
{
Expand Down
64 changes: 63 additions & 1 deletion src/runtime_src/core/common/xdp/profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,55 @@ finish_flush_device(void* handle)

} // end namespace xrt_core::xdp::ml_timeline

namespace xrt_core::xdp::aie_pc {

std::function<void (void*)> update_device_cb;
std::function<void (void*)> finish_flush_device_cb;

void
register_callbacks(void* handle)
{
#ifdef XDP_CLIENT_BUILD
using ftype = void (*)(void*);

update_device_cb = reinterpret_cast<ftype>(xrt_core::dlsym(handle, "updateDeviceAIEPC"));
finish_flush_device_cb = reinterpret_cast<ftype>(xrt_core::dlsym(handle, "finishflushDeviceAIEPC"));
#else
(void)handle;
#endif

}

void
warning_callbacks()
{
}

void
load()
{
static xrt_core::module_loader xdp_loader("xdp_aie_pc_plugin",
register_callbacks,
warning_callbacks);
}

// Make connections
void
update_device(void* handle)
{
if (update_device_cb)
update_device_cb(handle);
}

void
finish_flush_device(void* handle)
{
if (finish_flush_device_cb)
finish_flush_device_cb(handle);
}

} // end namespace xrt_core::xdp::aie_pc

namespace xrt_core::xdp::pl_deadlock {

std::function<void (void*)> update_device_cb;
Expand Down Expand Up @@ -338,7 +387,8 @@ update_device(void* handle)
|| xrt_core::config::get_aie_profile()
|| xrt_core::config::get_aie_trace()
|| xrt_core::config::get_aie_debug()
|| xrt_core::config::get_aie_halt()) {
|| xrt_core::config::get_aie_halt()
|| xrt_core::config::get_aie_pc()) {
/* All the above plugins are dependent on xdp_core library. So,
* explicitly load it to avoid library search issue in implicit loading.
*/
Expand Down Expand Up @@ -400,6 +450,16 @@ update_device(void* handle)
xrt_core::xdp::ml_timeline::update_device(handle);
}

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

#else

if (xrt_core::config::get_pl_deadlock_detection()
Expand Down Expand Up @@ -431,6 +491,8 @@ finish_flush_device(void* handle)
xrt_core::xdp::aie::debug::end_debug(handle);
if (xrt_core::config::get_ml_timeline())
xrt_core::xdp::ml_timeline::finish_flush_device(handle);
if (xrt_core::config::get_aie_pc())
xrt_core::xdp::aie_pc::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 @@ -12,6 +12,7 @@ if (XDP_CLIENT_BUILD_CMAKE STREQUAL "yes")
add_subdirectory(aie_trace)
add_subdirectory(aie_debug)
add_subdirectory(aie_halt)
add_subdirectory(aie_pc)
add_subdirectory(ml_timeline)
endif()
else()
Expand Down
42 changes: 42 additions & 0 deletions src/runtime_src/xdp/profile/plugin/aie_pc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
#

# ========================================================================
# This builds the AIE PC Plugin which can configure Perf Counter registers
# to count cycles between core function start and end.
# It is currently built on Client Windows Only.
# =========================================================================

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


file(GLOB XDP_AIE_PC_PLUGIN_FILES
"${PROFILE_DIR}/plugin/aie_pc/*.h"
"${PROFILE_DIR}/plugin/aie_pc/*.cpp"
"${IMPL_DIR}/*.h"
"${IMPL_DIR}/*.cpp"
)

file(GLOB XDP_DEVICE_COMMON_FILES
"${PROFILE_DIR}/device/common/*.h"
"${PROFILE_DIR}/device/common/*.cpp"
)

if (XDP_CLIENT_BUILD_CMAKE STREQUAL "yes")
add_library(xdp_aie_pc_plugin MODULE ${XDP_AIE_PC_PLUGIN_FILES} ${XDP_DEVICE_COMMON_FILES})
add_dependencies(xdp_aie_pc_plugin xdp_core xrt_coreutil)
target_link_libraries(xdp_aie_pc_plugin PRIVATE xdp_core xrt_coreutil xaiengine)
target_compile_definitions(xdp_aie_pc_plugin PRIVATE XDP_CLIENT_BUILD=1 -DXAIE_FEATURE_MSVC)
target_include_directories(xdp_aie_pc_plugin PRIVATE ${AIERT_DIR}/include)
set_target_properties(xdp_aie_pc_plugin PROPERTIES VERSION ${XRT_VERSION_STRING} SOVERSION ${XRT_SOVERSION})

install (TARGETS xdp_aie_pc_plugin
LIBRARY DESTINATION ${XDP_PLUGIN_INSTALL_DIR}
)

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

endif()
52 changes: 52 additions & 0 deletions src/runtime_src/xdp/profile/plugin/aie_pc/aie_pc_cb.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Copyright (C) 2024 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 "xdp/profile/plugin/aie_pc/aie_pc_cb.h"
#include "xdp/profile/plugin/aie_pc/aie_pc_plugin.h"

namespace xdp {

static AIEPCPlugin aiePCPluginInstance;

static void updateDeviceAIEPC(void* hwCtxImpl)
{
if (AIEPCPlugin::alive()) {
aiePCPluginInstance.updateDevice(hwCtxImpl);
}
}

static void finishflushDeviceAIEPC(void* hwCtxImpl)
{
if (AIEPCPlugin::alive()) {
aiePCPluginInstance.finishflushDevice(hwCtxImpl);
}
}

} // end namespace xdp

extern "C"
void updateDeviceAIEPC(void* hwCtxImpl)
{
xdp::updateDeviceAIEPC(hwCtxImpl);
}

extern "C"
void finishflushDeviceAIEPC(void* hwCtxImpl)
{
xdp::finishflushDeviceAIEPC(hwCtxImpl);
}
28 changes: 28 additions & 0 deletions src/runtime_src/xdp/profile/plugin/aie_pc/aie_pc_cb.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* Copyright (C) 2024 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_PC_CB_H
#define XDP_PLUGIN_AIE_PC_CB_H

#include "xdp/config.h"

extern "C" {

XDP_PLUGIN_EXPORT void updateDeviceAIEPC(void* hwCtxImpl);
XDP_PLUGIN_EXPORT void finishflushDeviceAIEPC(void* hwCtxImpl);

}
#endif
51 changes: 51 additions & 0 deletions src/runtime_src/xdp/profile/plugin/aie_pc/aie_pc_impl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Copyright (C) 2024 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_PC_IMPL_H
#define XDP_PLUGIN_AIE_PC_IMPL_H

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

namespace xdp {

class VPDatabase;

class AIEPCImpl
{
protected :
VPDatabase* db = nullptr;
xrt::hw_context mHwContext;

public:
AIEPCImpl(VPDatabase* dB)
: db(dB)
{}

AIEPCImpl() = delete;

virtual ~AIEPCImpl() {}

virtual void updateDevice(void*) = 0;
virtual void finishflushDevice(void*) = 0;

void setHwContext(xrt::hw_context ctx)
{
mHwContext = std::move(ctx);
}
};

}
#endif
Loading

0 comments on commit 36c792b

Please sign in to comment.