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

[XDP] fixes to recent VE2 profiling #8702

Merged
merged 7 commits into from
Jan 24, 2025
Merged
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
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# 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.
#

# ====================================================================
# This builds the AIE Profile plugin. It is currently built
# on both Edge, x86, client and ve2 platforms that support AIE.
# ====================================================================

if(XDP_VE2_BUILD_CMAKE STREQUAL "yes")
if (XDP_VE2_BUILD_CMAKE STREQUAL "yes")
set(IMPL_DIR "${PROFILE_DIR}/plugin/aie_profile/ve2")
elseif (XDP_CLIENT_BUILD_CMAKE STREQUAL "yes")
set(IMPL_DIR "${PROFILE_DIR}/plugin/aie_profile/client")
Expand Down Expand Up @@ -38,7 +38,7 @@ file(GLOB AIE_DRIVER_COMMON_UTIL_FILES
"${PROFILE_DIR}/device/common/*.cpp"
)

if(XDP_VE2_BUILD_CMAKE STREQUAL "yes")
if (XDP_VE2_BUILD_CMAKE STREQUAL "yes")
add_library(xdp_aie_profile_plugin MODULE ${AIE_PROFILE_PLUGIN_FILES} ${AIE_PROFILE_UTIL_FILES} ${AIE_PROFILE_CONFIG_FILES})
add_dependencies(xdp_aie_profile_plugin xdp_core xrt_coreutil)
target_link_libraries(xdp_aie_profile_plugin PRIVATE xdp_core xrt_coreutil xaiengine)
Expand All @@ -62,8 +62,7 @@ elseif (XDP_CLIENT_BUILD_CMAKE STREQUAL "yes")
LIBRARY DESTINATION ${XDP_PLUGIN_INSTALL_DIR} COMPONENT ${XRT_COMPONENT}
)


elseif (${XRT_NATIVE_BUILD} STREQUAL "yes")
elseif (DEFINED XRT_AIE_BUILD AND ${XRT_NATIVE_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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
constexpr uint16_t BASE_MEMORY_COUNTER = 1000;
constexpr uint16_t BASE_SHIM_COUNTER = 2000;
constexpr uint16_t BASE_MEM_TILE_COUNTER = 3000;
constexpr uint16_t BASE_UC_MDM_COUNTER = 4000;

constexpr uint32_t PAYLOAD_IS_CHANNEL_SHIFT = 7;
constexpr uint32_t PAYLOAD_IS_MASTER_SHIFT = 8;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2022-2023 Advanced Micro Devices, Inc. - All rights reserved
* Copyright (C) 2022-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 @@ -121,7 +121,8 @@ namespace xdp {
"graph_based_memory_tile_metrics", "graph_based_interface_tile_metrics",
"tile_based_aie_metrics", "tile_based_aie_memory_metrics",
"tile_based_memory_tile_metrics", "tile_based_interface_tile_metrics",
"interval_us", "interface_tile_latency", "start_type", "start_iteration"};
"interval_us", "interface_tile_latency", "start_type", "start_iteration",
"tile_based_microcontroller_metrics"};
const std::map<std::string, std::string> deprecatedSettings {
{"aie_profile_core_metrics", "AIE_profile_settings.graph_based_aie_metrics or tile_based_aie_metrics"},
{"aie_profile_memory_metrics", "AIE_profile_settings.graph_based_aie_memory_metrics or tile_based_aie_memory_metrics"},
Expand Down Expand Up @@ -1044,6 +1045,7 @@ namespace xdp {
auto defaultSet = defaultSets[moduleIdx];
bool showWarning = true;
std::vector<tile_type> offTiles;
auto metricVec = metricStrings.at(module_type::shim);

for (auto& tileMetric : configMetrics[moduleIdx]) {
// Save list of "off" tiles
Expand All @@ -1053,8 +1055,6 @@ namespace xdp {
}

// Ensure requested metric set is supported (if not, use default)
auto metricVec = metricStrings.at(module_type::shim);

if (std::find(metricVec.begin(), metricVec.end(), tileMetric.second) == metricVec.end()) {
if (showWarning) {
std::string msg = "Unable to find interface_tile metric set " + tileMetric.second
Expand Down Expand Up @@ -1087,7 +1087,7 @@ namespace xdp {
auto allValidPorts = metadataReader->getValidPorts();

// STEP 1 : Parse per-graph or per-kernel settings
// NOTE: graph settings not yet
// NOTE: graph settings not supported yet

// STEP 2 : Parse per-tile settings: all, bounding box, and/or single tiles

Expand Down Expand Up @@ -1186,6 +1186,7 @@ namespace xdp {
auto defaultSet = defaultSets[moduleIdx];
bool showWarning = true;
std::vector<tile_type> offTiles;
auto metricVec = metricStrings.at(module_type::uc);

for (auto& tileMetric : configMetrics[moduleIdx]) {
// Save list of "off" tiles
Expand All @@ -1195,8 +1196,6 @@ namespace xdp {
}

// Ensure requested metric set is supported (if not, use default)
auto metricVec = metricStrings.at(module_type::shim);

if (std::find(metricVec.begin(), metricVec.end(), tileMetric.second) == metricVec.end()) {
if (showWarning) {
std::string msg = "Unable to find microcontroller metric set " + tileMetric.second
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -607,87 +607,4 @@ namespace xdp::aie::profile {
bcChannelEvent = channelEvent;
}





/****************************************************************************
* Configure counters in Microblaze Debug Module (MDM)
* TODO: convert to using XAie_Events once support is available from driver
***************************************************************************/
void configMDMCounters(XAie_DevInst* aieDevInst, uint8_t col, uint8_t row,
const std::vector<uint32_t> events)
{
auto tileOffset = XAie_GetTileAddr(aieDevInst, row, col);

// Use MDM protocol to program counters
// 1. Reset to first counter
XAie_Write32(aieDevInst, tileOffset + UC_MDM_PCCMDR, 1 << UC_MDM_PCCMDR_RESET_BIT);

// 2. Write events for all counters
for (auto event : events)
XAie_Write32(aieDevInst, tileOffset + UC_MDM_PCCTRLR, event);

// 3. Clear and start counters
XAie_Write32(aieDevInst, tileOffset + UC_MDM_PCCMDR, 1 << UC_MDM_PCCMDR_CLEAR_BIT);
XAie_Write32(aieDevInst, tileOffset + UC_MDM_PCCMDR, 1 << UC_MDM_PCCMDR_START_BIT);
}

/****************************************************************************
* Read counters in Microblaze Debug Module (MDM)
***************************************************************************/
void readMDMCounters(XAie_DevInst* aieDevInst, uint8_t col, uint8_t row,
std::vector<uint64_t>& values)
{
auto tileOffset = XAie_GetTileAddr(aieDevInst, row, col);

// Use MDM protocol to program counters
// 1. Reset to first counter
XAie_Write32(aieDevInst, tileOffset + UC_MDM_PCCMDR, 1 << UC_MDM_PCCMDR_RESET_BIT);

// 2. Read status of all counters
std::vector<bool> overflows;
uint32_t numCounters = UC_NUM_EVENT_COUNTERS + UC_NUM_LATENCY_COUNTERS;
for (uint32_t c=0; c < numCounters; ++c) {
uint32_t val;
XAie_Read32(aieDevInst, tileOffset + UC_MDM_PCSR, &val);
bool overflow = (((val >> UC_MDM_PCSR_OVERFLOW_BIT) & 0x1) == 1);
overflows.push_back(overflow);

if ((val >> UC_MDM_PCSR_FULL_BIT) & 0x1) {
std::cout << "Full bit of tile " << col << "," << row << " microcontroller counter "
<< c << " is high" << std::endl;
}
}

// 3. Read values of event counters
for (uint32_t c=0; c < UC_NUM_EVENT_COUNTERS; ++c) {
uint32_t val;
XAie_Read32(aieDevInst, tileOffset + UC_MDM_PCDRR, &val);
uint64_t val2 = (overflows.at(c)) ? (val + OVERFLOW_32BIT) : val;
values.push_back(val2);
}

// 4. Read four values from latency counter
// Read 1 - The number of times the event occurred
// Read 2 - The sum of each event latency
// Read 3 - The sum of each event latency squared
// Read 4 - 31:16 Minimum measured latency, 16 bits
// 15:0 Maximum measured latency, 16 bits
std::vector<uint32_t> latencyValues;
for (uint32_t c=0; c < UC_MDM_PCDRR_LATENCY_READS; ++c) {
uint32_t val;
XAie_Read32(aieDevInst, tileOffset + UC_MDM_PCDRR, &val);
uint64_t val2 = (overflows.at(UC_NUM_EVENT_COUNTERS)) ? (val + OVERFLOW_32BIT) : val;
latencyValues.push_back(val2);
}

// 5. Calculate average latency
// NOTE: for now, only report average (we also have min and max; see above)
uint32_t numValues = latencyValues.at(0);
uint32_t totalLatency = latencyValues.at(1);
uint64_t avgLatency = (numValues == 0) ? 0 : (totalLatency / numValues);
values.push_back(avgLatency);
}

} // namespace xdp
Original file line number Diff line number Diff line change
Expand Up @@ -223,28 +223,6 @@ namespace xdp::aie::profile {
const XAie_Events bcEvent, XAie_Events& bcChannelEvent,
std::vector<std::shared_ptr<xaiefal::XAieBroadcast>>& bcResourcesBytesTx);



/**
* @brief Configure counters in Microblaze Debug Module (MDM)
* @param aieDevInst AIE device instance
* @param col tile column
* @param row tile row
* @param events vector of events to use in counters
*/
void configMDMCounters(XAie_DevInst* aieDevInst, uint8_t col, uint8_t row,
const std::vector<uint32_t> events);

/**
* @brief Read counters in Microblaze Debug Module (MDM)
* @param aieDevInst AIE device instance
* @param col tile column
* @param row tile row
* @param values vector of values from counters
*/
void readMDMCounters(XAie_DevInst* aieDevInst, uint8_t col, uint8_t row,
std::vector<uint64_t>& values);

} // namespace xdp::aie::profile

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ namespace xdp::aie::profile {
eventSets = {
{"execution", {16, 17, 18, 19, 20, 62}},
{"interrupt_stalls", {23, 24, 25, 26, 27, 57}},
{"mmu_activity", {43, 48, 49, 50, 53, 61}}
{"mmu_activity", {43, 48, 49, 50, 53, 61}},
{"test", { 0, 0, 0, 0, 0, 0}}
};

return eventSets;
Expand Down Expand Up @@ -635,18 +636,14 @@ namespace xdp::aie::profile {
return std::make_pair(eventId, eventId);
}

#ifdef XDP_CLIENT_BUILD
uint16_t tmpStart;
uint16_t tmpEnd;
#ifdef XDP_CLIENT_BUILD
XAie_EventLogicalToPhysicalConv(aieDevInst, tileLoc, xaieModType, startEvent, &tmpStart);
XAie_EventLogicalToPhysicalConv(aieDevInst, tileLoc, xaieModType, endEvent, &tmpEnd);
#else
uint8_t tmpStart;
uint8_t tmpEnd;
//XAie_EventLogicalToPhysicalConv_16(aieDevInst, tileLoc, xaieModType, startEvent, &tmpStart);
//XAie_EventLogicalToPhysicalConv_16(aieDevInst, tileLoc, xaieModType, endEvent, &tmpEnd);
XAie_EventLogicalToPhysicalConv(aieDevInst, tileLoc, xaieModType, startEvent, &tmpStart);
XAie_EventLogicalToPhysicalConv(aieDevInst, tileLoc, xaieModType, endEvent, &tmpEnd);
XAie_EventLogicalToPhysicalConv_16(aieDevInst, tileLoc, xaieModType, startEvent, &tmpStart);
XAie_EventLogicalToPhysicalConv_16(aieDevInst, tileLoc, xaieModType, endEvent, &tmpEnd);
#endif
uint16_t phyStartEvent = tmpStart + getCounterBase(xdpModType);
uint16_t phyEndEvent = tmpEnd + getCounterBase(xdpModType);
Expand Down Expand Up @@ -696,4 +693,88 @@ namespace xdp::aie::profile {
return total_beats;
}

/****************************************************************************
* Configure counters in Microblaze Debug Module (MDM)
* TODO: convert to using XAie_Events once support is available from driver
***************************************************************************/
void configMDMCounters(XAie_DevInst* aieDevInst, uint8_t col, uint8_t row,
const std::vector<uint32_t> events)
{
auto tileOffset = XAie_GetTileAddr(aieDevInst, row, col);

// Use MDM protocol to configure counters
// 1. Reset to first counter
XAie_Write32(aieDevInst, tileOffset + UC_MDM_PCCMDR, 1 << UC_MDM_PCCMDR_RESET_BIT);

// 2. Write events for all counters
for (auto event : events)
XAie_Write32(aieDevInst, tileOffset + UC_MDM_PCCTRLR, event);

// 3. Clear and start counters
XAie_Write32(aieDevInst, tileOffset + UC_MDM_PCCMDR, 1 << UC_MDM_PCCMDR_CLEAR_BIT);
XAie_Write32(aieDevInst, tileOffset + UC_MDM_PCCMDR, 1 << UC_MDM_PCCMDR_START_BIT);
}

/****************************************************************************
* Read counters in Microblaze Debug Module (MDM)
***************************************************************************/
void readMDMCounters(XAie_DevInst* aieDevInst, uint8_t col, uint8_t row,
std::vector<uint64_t>& values)
{
auto tileOffset = XAie_GetTileAddr(aieDevInst, row, col);

// Use MDM protocol to read counters
// 1. Sample and stop counters
XAie_Write32(aieDevInst, tileOffset + UC_MDM_PCCMDR, 1 << UC_MDM_PCCMDR_SAMPLE_BIT);
// NOTE: Do counters need to be stopped before reading? If so, uncomment line below.
//XAie_Write32(aieDevInst, tileOffset + UC_MDM_PCCMDR, 1 << UC_MDM_PCCMDR_STOP_BIT);

// 2. Reset to first counter
XAie_Write32(aieDevInst, tileOffset + UC_MDM_PCCMDR, 1 << UC_MDM_PCCMDR_RESET_BIT);

// 3. Read status of all counters
std::vector<bool> overflows;
uint32_t numCounters = UC_NUM_EVENT_COUNTERS + UC_NUM_LATENCY_COUNTERS;
for (uint32_t c=0; c < numCounters; ++c) {
uint32_t val;
XAie_Read32(aieDevInst, tileOffset + UC_MDM_PCSR, &val);
bool overflow = (((val >> UC_MDM_PCSR_OVERFLOW_BIT) & 0x1) == 1);
overflows.push_back(overflow);

if ((val >> UC_MDM_PCSR_FULL_BIT) & 0x1) {
std::cout << "Full bit of tile " << col << "," << row << " microcontroller counter "
<< c << " is high" << std::endl;
}
}

// 4. Read values of event counters
for (uint32_t c=0; c < UC_NUM_EVENT_COUNTERS; ++c) {
uint32_t val;
XAie_Read32(aieDevInst, tileOffset + UC_MDM_PCDRR, &val);
uint64_t val2 = (overflows.at(c)) ? (val + OVERFLOW_32BIT) : val;
values.push_back(val2);
}

// 5. Read four values from latency counter
// Read 1 - The number of times the event occurred
// Read 2 - The sum of each event latency
// Read 3 - The sum of each event latency squared
// Read 4 - 31:16 Minimum measured latency, 16 bits
// 15:0 Maximum measured latency, 16 bits
std::vector<uint32_t> latencyValues;
for (uint32_t c=0; c < UC_MDM_PCDRR_LATENCY_READS; ++c) {
uint32_t val;
XAie_Read32(aieDevInst, tileOffset + UC_MDM_PCDRR, &val);
uint64_t val2 = (overflows.at(UC_NUM_EVENT_COUNTERS)) ? (val + OVERFLOW_32BIT) : val;
latencyValues.push_back(val2);
}

// 6. Calculate average latency
// NOTE: for now, only report average (we also have min and max; see above)
uint32_t numValues = latencyValues.at(0);
uint32_t totalLatency = latencyValues.at(1);
uint64_t avgLatency = (numValues == 0) ? 0 : (totalLatency / numValues);
values.push_back(avgLatency);
}

} // namespace xdp::aie
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,16 @@ namespace xdp::aie::profile {
{module_type::core, static_cast<uint16_t>(0)},
{module_type::dma, BASE_MEMORY_COUNTER},
{module_type::shim, BASE_SHIM_COUNTER},
{module_type::mem_tile, BASE_MEM_TILE_COUNTER}
{module_type::mem_tile, BASE_MEM_TILE_COUNTER},
{module_type::uc, BASE_UC_MDM_COUNTER}
};

const std::vector<XAie_ModuleType> falModuleTypes = {
XAIE_CORE_MOD,
XAIE_MEM_MOD,
XAIE_PL_MOD,
XAIE_MEM_MOD,
XAIE_PL_MOD // TODO: if needed, replace with module type for uCs
XAIE_PL_MOD // TODO: replace if/when there is an uC module type
};

enum adfAPI {
Expand Down Expand Up @@ -225,6 +226,26 @@ namespace xdp::aie::profile {

uint32_t convertToBeats(const std::string& metricSet, uint32_t bytes, uint8_t hwGen);

/**
* @brief Configure counters in Microblaze Debug Module (MDM)
* @param aieDevInst AIE device instance
* @param col tile column
* @param row tile row
* @param events vector of events to use in counters
*/
void configMDMCounters(XAie_DevInst* aieDevInst, uint8_t col, uint8_t row,
const std::vector<uint32_t> events);

/**
* @brief Read counters in Microblaze Debug Module (MDM)
* @param aieDevInst AIE device instance
* @param col tile column
* @param row tile row
* @param values vector of values from counters
*/
void readMDMCounters(XAie_DevInst* aieDevInst, uint8_t col, uint8_t row,
std::vector<uint64_t>& values);

} // namespace xdp::aie::profile

#endif
Loading
Loading