Skip to content

Commit

Permalink
Added AIE Profiling on additional Windows Devices (Xilinx#7714)
Browse files Browse the repository at this point in the history
nishraptor authored Sep 22, 2023
1 parent f978a3c commit 0464b83
Showing 24 changed files with 1,165 additions and 186 deletions.
3 changes: 3 additions & 0 deletions src/runtime_src/core/common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@
# Copyright (C) 2019-2022 Xilinx, Inc. All rights reserved.
# Copyright (C) 2022 Advanced Micro Devices, Inc. All rights reserved.
add_subdirectory(api)
add_subdirectory(xdp)

add_library(core_common_library_objects OBJECT
asd_parser.cpp
@@ -50,11 +51,13 @@ target_include_directories(core_common_objects
add_library(xrt_coreutil SHARED
$<TARGET_OBJECTS:core_common_library_objects>
$<TARGET_OBJECTS:core_common_api_library_objects>
$<TARGET_OBJECTS:core_common_xdp_profile_objects>
)

add_library(xrt_coreutil_static STATIC
$<TARGET_OBJECTS:core_common_library_objects>
$<TARGET_OBJECTS:core_common_api_library_objects>
$<TARGET_OBJECTS:core_common_xdp_profile_objects>
)

set_target_properties(xrt_coreutil PROPERTIES
13 changes: 13 additions & 0 deletions src/runtime_src/core/common/api/hw_context_int.h
Original file line number Diff line number Diff line change
@@ -3,8 +3,10 @@
#ifndef XRT_COMMON_API_HW_CONTEXT_INT_H
#define XRT_COMMON_API_HW_CONTEXT_INT_H

#include "core/common/config.h"
// This file defines implementation extensions to the XRT XCLBIN APIs.
#include "core/include/experimental/xrt_hw_context.h"

#include <cstdint>

// Provide access to xrt::xclbin data that is not directly exposed
@@ -28,6 +30,17 @@ get_core_device_raw(const xrt::hw_context& ctx);
void
set_exclusive(xrt::hw_context& ctx);

// Allows the creation of the hardware context from a void pointer
// to the hardware context implementation. We use a void pointer
// because we need to dynamically link to the callbacks that exist in
// XDP with a C-style interface. Additionally, we do not want to
// expose the hardware_context implementation class. This is used by
// XDP plugins in order to initialize when the user creates
// a hardware context in their host
XRT_CORE_COMMON_EXPORT
xrt::hw_context
create_hw_context_from_implementation(void* hwctx_impl);

}} // hw_context_int, xrt_core

#endif
41 changes: 38 additions & 3 deletions src/runtime_src/core/common/api/xrt_hw_context.cpp
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@

#include "core/common/device.h"
#include "core/common/shim/hwctx_handle.h"
#include "core/common/xdp/profile.h"

#include <limits>
#include <memory>
@@ -19,7 +20,7 @@ namespace xrt {

// class hw_context_impl - insulated implemention of an xrt::hw_context
//
class hw_context_impl
class hw_context_impl : public std::enable_shared_from_this<hw_context_impl>
{
using cfg_param_type = xrt::hw_context::cfg_param_type;
using qos_type = cfg_param_type;
@@ -48,6 +49,22 @@ class hw_context_impl
, m_hdl{m_core_device->create_hw_context(xclbin_id, m_cfg_param, m_mode)}
{}

std::shared_ptr<hw_context_impl>
get_shared_ptr()
{
return shared_from_this();
}

~hw_context_impl()
{
// The end_poll plugin should only occur when the underlying
// hw_context_impl is destroyed. The xdp::update_device cannot exist
// in the hw_context_impl constructor because an existing
// shared pointer must already exist to call get_shared_ptr(),
// which is not true at that time.
xrt_core::xdp::end_poll(this);
}

void
update_qos(const qos_type& qos)
{
@@ -117,6 +134,16 @@ set_exclusive(xrt::hw_context& hwctx)
hwctx.get_handle()->set_exclusive();
}

xrt::hw_context
create_hw_context_from_implementation(void* hwctx_impl)
{
if (!hwctx_impl)
throw std::runtime_error("Invalid hardware context implementation.");

xrt::hw_context_impl* impl_ptr = static_cast<xrt::hw_context_impl*>(hwctx_impl);
return xrt::hw_context(impl_ptr->get_shared_ptr());
}

}} // hw_context_int, xrt_core

////////////////////////////////////////////////////////////////
@@ -127,13 +154,21 @@ namespace xrt {
hw_context::
hw_context(const xrt::device& device, const xrt::uuid& xclbin_id, const xrt::hw_context::cfg_param_type& cfg_param)
: detail::pimpl<hw_context_impl>(std::make_shared<hw_context_impl>(device.get_handle(), xclbin_id, cfg_param))
{}
{
// Update device is called with a raw pointer to dyanamically
// link to callbacks that exist in XDP via a C-style interface
// The create_hw_context_from_implementation function is then
// called in XDP create a hw_context to the underlying implementation
xrt_core::xdp::update_device(get_handle().get());
}


hw_context::
hw_context(const xrt::device& device, const xrt::uuid& xclbin_id, access_mode mode)
: detail::pimpl<hw_context_impl>(std::make_shared<hw_context_impl>(device.get_handle(), xclbin_id, mode))
{}
{
xrt_core::xdp::update_device(get_handle().get());
}

void
hw_context::
17 changes: 17 additions & 0 deletions src/runtime_src/core/common/xdp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright (C) 2022 Advanced Micro Devices, Inc. All rights reserved.
add_library(core_common_xdp_profile_objects OBJECT
profile.cpp
)

target_include_directories(core_common_xdp_profile_objects
PRIVATE
${XRT_SOURCE_DIR}/runtime_src
)

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

#include "core/common/config_reader.h"
#include "core/common/dlfcn.h"
#include "core/common/module_loader.h"

#include <functional>
// This file makes the connections between all xrt_coreutil level hooks
// to the corresponding xdp plugins. It is responsible for loading all of
// modules.

namespace xrt_core::xdp::aie::profile {


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

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

update_device_cb = reinterpret_cast<ftype>(xrt_core::dlsym(handle, "updateAIECtrDevice"));
end_poll_cb = reinterpret_cast<ftype>(xrt_core::dlsym(handle, "endAIECtrPoll"));
#else
(void)handle;
#endif


}

void
warning_callbacks()
{
}

void
load()
{
static xrt_core::module_loader xdp_aie_loader("xdp_aie_profile_plugin",
register_callbacks,
warning_callbacks);
}

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

void
end_poll(void* handle)
{
if (end_poll_cb)
end_poll_cb(handle);
}

} // end namespace xrt_core::xdp::aie::profile

namespace xrt_core::xdp {

void
update_device(void* handle)
{
if (xrt_core::config::get_aie_profile()) {
try {
xrt_core::xdp::aie::profile::load();
}
catch (...) {
return;
}
xrt_core::xdp::aie::profile::update_device(handle);
}
}

void
end_poll(void* handle)
{
if (xrt_core::config::get_aie_profile())
xrt_core::xdp::aie::profile::end_poll(handle);
}

} // end namespace xrt_core::xdp
26 changes: 26 additions & 0 deletions src/runtime_src/core/common/xdp/profile.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright (C) 2023 Advanced Micro Devices, Inc. - All rights reserved
#ifndef CORE_COMMON_PROFILE_DOT_H
#define CORE_COMMON_PROFILE_DOT_H

// The functions here are the general interfaces for the XDP hooks that are
// called from the common coreutil library and not the specific shims.
namespace xrt_core::xdp {

// update_device should be called whenever a user creates a hardware context.
// This hook will allow the XDP plugins to cache a reference to the user's
// hardware context so the plugin can configure and read performance counters
// that are used by the user's application.
void
update_device(void* handle);

// end_poll should be called when the application ends or a hardware context
// is destroyed. It is responsible for flushing out all of the device
// information from the device to host memory so it can be processed before
// the device is reset and the data is wiped.
void
end_poll(void* handle);

} // end namespace xrt_core::xdp

#endif
7 changes: 7 additions & 0 deletions src/runtime_src/core/include/xrt/xrt_hw_context.h
Original file line number Diff line number Diff line change
@@ -113,6 +113,13 @@ class hw_context : public detail::pimpl<hw_context_impl>
{}
/// @endcond

///@cond
// Undocumented construction using impl only
hw_context(std::shared_ptr<hw_context_impl> impl)
: detail::pimpl<hw_context_impl>(std::move(impl))
{}
/// @endcond

///@cond
// Undocument experimental API to change the QoS of a hardware context
// Subject to change or removal
17 changes: 12 additions & 5 deletions src/runtime_src/xdp/profile/database/static_info/aie_util.cpp
Original file line number Diff line number Diff line change
@@ -230,7 +230,12 @@ namespace aie {
{
std::vector<tile_type> tiles;

auto ios = getAllIOs(aie_meta);
#ifdef XDP_MINIMAL_BUILD
auto ios = getGMIOs(aie_meta);
#else
auto ios = getAllIOs(aie_meta);
#endif

for (auto& io : ios) {
auto isMaster = io.second.slaveOrMaster;
auto streamId = io.second.streamId;
@@ -257,10 +262,10 @@ namespace aie {
// NOTE: input = slave (data flowing from PLIO)
// output = master (data flowing to PLIO)
if ((metricStr != "ports")
&& ((isMaster && (metricStr.find("input") != std::string::npos)
&& (metricStr.find("mm2s") != std::string::npos))
|| (!isMaster && (metricStr.find("output") != std::string::npos)
&& (metricStr.find("s2mm") != std::string::npos))))
&& ((isMaster && (metricStr.find("input") != std::string::npos
|| metricStr.find("mm2s") != std::string::npos))
|| (!isMaster && (metricStr.find("output") != std::string::npos
|| metricStr.find("s2mm") != std::string::npos))))
continue;
// Make sure column is within specified range (if specified)
if (useColumn && !((minCol <= (uint32_t)shimCol) && ((uint32_t)shimCol <= maxCol)))
@@ -275,6 +280,7 @@ namespace aie {
// Grab stream ID and slave/master (used in configStreamSwitchPorts())
tile.itr_mem_col = isMaster;
tile.itr_mem_row = streamId;

tiles.emplace_back(std::move(tile));
}

@@ -283,6 +289,7 @@ namespace aie {
"No tiles used channel ID " + std::to_string(channelId) + ". Please specify a valid channel ID.";
xrt_core::message::send(severity_level::warning, "XRT", msg);
}

return tiles;
}

6 changes: 4 additions & 2 deletions src/runtime_src/xdp/profile/plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -6,8 +6,10 @@ if (XDP_MINIMAL_BUILD STREQUAL "yes")

add_subdirectory(native)
add_subdirectory(user)
add_subdirectory(aie_profile)


if (WIN32)
add_subdirectory(aie_profile)
endif()
else()

# =========================================================
5 changes: 3 additions & 2 deletions src/runtime_src/xdp/profile/plugin/aie_profile/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -27,9 +27,10 @@ file(GLOB AIE_PROFILE_PLUGIN_FILES
if (XDP_MINIMAL_BUILD STREQUAL "yes")
add_library(xdp_aie_profile_plugin MODULE ${AIE_PROFILE_PLUGIN_FILES})
add_dependencies(xdp_aie_profile_plugin xdp_core xrt_coreutil)
target_link_libraries(xdp_aie_profile_plugin PRIVATE xdp_core xrt_coreutil)
include_directories(xdp_aie_profile_plugin PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/win/transactions)
target_link_libraries(xdp_aie_profile_plugin PRIVATE xdp_core xrt_coreutil xaiengine)
target_compile_definitions(xdp_aie_profile_plugin PRIVATE XDP_MINIMAL_BUILD=1)

target_include_directories(xdp_aie_profile_plugin PRIVATE ${AIERT_DIR}/include)
set_target_properties(xdp_aie_profile_plugin PROPERTIES VERSION ${XRT_VERSION_STRING} SOVERSION ${XRT_SOVERSION})

install (TARGETS xdp_aie_profile_plugin
Original file line number Diff line number Diff line change
@@ -46,4 +46,4 @@ extern "C"
void endAIECtrPoll(void* handle)
{
xdp::endAIECtrPoll(handle);
}
}
Original file line number Diff line number Diff line change
@@ -17,9 +17,9 @@
#ifndef AIE_PROFILE_DEFS_H
#define AIE_PROFILE_DEFS_H

constexpr unsigned int BASE_MEMORY_COUNTER = 128;
constexpr unsigned int BASE_SHIM_COUNTER = 256;
constexpr unsigned int BASE_MEM_TILE_COUNTER = 384;
constexpr uint16_t BASE_MEMORY_COUNTER = 128;
constexpr uint16_t BASE_SHIM_COUNTER = 256;
constexpr uint16_t BASE_MEM_TILE_COUNTER = 384;

constexpr uint32_t GROUP_DMA_MASK = 0x0000f000;
constexpr uint32_t GROUP_LOCK_MASK = 0x55555555;
@@ -32,4 +32,9 @@ constexpr uint32_t GROUP_STREAM_SWITCH_TLAST_MASK = 0x88888888;
constexpr uint32_t GROUP_CORE_PROGRAM_FLOW_MASK = 0x00001FE0;
constexpr uint32_t GROUP_CORE_STALL_MASK = 0x0000000F;

constexpr uint32_t GROUP_SHIM_S2MM0_STALL_MASK = 0x41000;
constexpr uint32_t GROUP_SHIM_S2MM1_STALL_MASK = 0x82000;
constexpr uint32_t GROUP_SHIM_MM2S0_STALL_MASK = 0x500000;
constexpr uint32_t GROUP_SHIM_MM2S1_STALL_MASK = 0xA00000;

#endif
Loading

0 comments on commit 0464b83

Please sign in to comment.