Skip to content

Commit

Permalink
AIE trace/profile improvements for 2023.2 (#7633)
Browse files Browse the repository at this point in the history
  • Loading branch information
pgschuey authored Jul 19, 2023
1 parent e67fab6 commit ce6ee4a
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,16 @@ enum class module_type {
class aie_cfg_peripheral_tile : public aie_cfg_base
{
public:
bool port_trace_is_master[NUM_SWITCH_MONITOR_PORTS] = {};
uint8_t port_trace_ids[NUM_SWITCH_MONITOR_PORTS] = {};
bool port_trace_is_master[NUM_SWITCH_MONITOR_PORTS];
int8_t port_trace_ids[NUM_SWITCH_MONITOR_PORTS];
int8_t s2mm_channels[NUM_CHANNEL_SELECTS] = {-1, -1};
int8_t mm2s_channels[NUM_CHANNEL_SELECTS] = {-1, -1};
aie_cfg_peripheral_tile() : aie_cfg_base(4) {}
aie_cfg_peripheral_tile() : aie_cfg_base(4) {
for (uint32_t i=0; i < NUM_SWITCH_MONITOR_PORTS; ++i) {
port_trace_is_master[i] = false;
port_trace_ids[i] = -1;
}
}
};

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,6 @@ namespace xdp {
if (settingsString.empty())
return {};

// For 2023.1 only: support both *_bandwidths and *_throughputs
if (settingsString.find("bandwidths") != std::string::npos) {
xrt_core::message::send(severity_level::warning, "XRT",
"All metric sets named *_bandwidths will be renamed *_throughputs "
"in 2023.2. Please use the new settings.");
boost::replace_all(settingsString, "bandwidths", "throughputs");
}

// Each of the metrics can have ; separated multiple values. Process and save all
std::vector<std::string> settingsVector;
boost::replace_all(settingsString, " ", "");
Expand Down
127 changes: 76 additions & 51 deletions src/runtime_src/xdp/profile/plugin/aie_profile/edge/aie_profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@

#define XDP_SOURCE

#include "xdp/profile/plugin/aie_profile/edge/aie_profile.h"
#include "xdp/profile/database/static_info/aie_util.h"

#include <boost/algorithm/string.hpp>
#include <cmath>
#include <memory>
#include <cstring>

#include "aie_profile.h"

#include "core/common/message.h"
#include "core/common/time.h"
#include "core/common/xrt_profiling.h"
Expand Down Expand Up @@ -250,63 +251,80 @@ namespace xdp {
return false;
}

bool AieProfile_EdgeImpl::isPortRunningEvent(const XAie_Events event)
{
std::set<XAie_Events> runningEvents = {
XAIE_EVENT_PORT_RUNNING_0_CORE, XAIE_EVENT_PORT_RUNNING_1_CORE,
XAIE_EVENT_PORT_RUNNING_2_CORE, XAIE_EVENT_PORT_RUNNING_3_CORE,
XAIE_EVENT_PORT_RUNNING_4_CORE, XAIE_EVENT_PORT_RUNNING_5_CORE,
XAIE_EVENT_PORT_RUNNING_6_CORE, XAIE_EVENT_PORT_RUNNING_7_CORE,
XAIE_EVENT_PORT_RUNNING_0_PL, XAIE_EVENT_PORT_RUNNING_1_PL,
XAIE_EVENT_PORT_RUNNING_2_PL, XAIE_EVENT_PORT_RUNNING_3_PL,
XAIE_EVENT_PORT_RUNNING_4_PL, XAIE_EVENT_PORT_RUNNING_5_PL,
XAIE_EVENT_PORT_RUNNING_6_PL, XAIE_EVENT_PORT_RUNNING_7_PL,
XAIE_EVENT_PORT_RUNNING_0_MEM_TILE, XAIE_EVENT_PORT_RUNNING_1_MEM_TILE,
XAIE_EVENT_PORT_RUNNING_2_MEM_TILE, XAIE_EVENT_PORT_RUNNING_3_MEM_TILE,
XAIE_EVENT_PORT_RUNNING_4_MEM_TILE, XAIE_EVENT_PORT_RUNNING_5_MEM_TILE,
XAIE_EVENT_PORT_RUNNING_6_MEM_TILE, XAIE_EVENT_PORT_RUNNING_7_MEM_TILE
};

return (runningEvents.find(event) != runningEvents.end());
}

// Configure stream switch ports for monitoring purposes
// NOTE: Used to monitor streams: trace, interfaces, and memory tiles
void AieProfile_EdgeImpl::configStreamSwitchPorts(XAie_DevInst* aieDevInst,
const tile_type& tile,
xaiefal::XAieTile& xaieTile,
const XAie_LocType loc,
const module_type type,
const XAie_Events event,
const int countnum,
const std::string metricSet,
const uint8_t channel)
XAie_Events
AieProfile_EdgeImpl::configStreamSwitchPorts(XAie_DevInst* aieDevInst, const tile_type& tile,
xaiefal::XAieTile& xaieTile, const XAie_LocType loc,
const module_type type, const XAie_Events event,
const std::string metricSet, const uint8_t channel)
{
// Only configure as needed: must be applicable event and only need at most two
if (!isStreamSwitchPortEvent(event) || (countnum > 1))
return;
if (!isStreamSwitchPortEvent(event))
return event;

auto switchPortRsc = xaieTile.sswitchPort();
auto ret = switchPortRsc->reserve();
if (ret != AieRC::XAIE_OK)
return;
return event;

uint32_t rscId = 0;
XAie_LocType tmpLoc;
XAie_ModuleType tmpMod;
switchPortRsc->getRscId(tmpLoc, tmpMod, rscId);

// AIE Tiles (e.g., trace streams)
if (type == module_type::core) {
// AIE Tiles (e.g., trace streams)
// Define stream switch port to monitor core or memory trace
uint8_t traceSelect = (event == XAIE_EVENT_PORT_RUNNING_0_CORE) ? 0 : 1;
XAie_EventSelectStrmPort(aieDevInst, loc, rscId, XAIE_STRMSW_SLAVE, TRACE, traceSelect);
return;
switchPortRsc->setPortToSelect(XAIE_STRMSW_SLAVE, TRACE, traceSelect);
}

// Interface tiles (e.g., PLIO, GMIO)
if (type == module_type::shim) {
else if (type == module_type::shim) {
// Interface tiles (e.g., PLIO, GMIO)
// Grab slave/master and stream ID
// NOTE: stored in getTilesForProfiling() above
auto slaveOrMaster = (tile.itr_mem_col == 0) ? XAIE_STRMSW_SLAVE : XAIE_STRMSW_MASTER;
auto streamPortId = static_cast<uint8_t>(tile.itr_mem_row);

// Define stream switch port to monitor interface
XAie_EventSelectStrmPort(aieDevInst, loc, rscId, slaveOrMaster, SOUTH, streamPortId);
return;
}

// Memory tiles
if (metricSet.find("trace") != std::string::npos) {
XAie_EventSelectStrmPort(aieDevInst, loc, rscId, XAIE_STRMSW_SLAVE, TRACE, 0);
switchPortRsc->setPortToSelect(slaveOrMaster, SOUTH, streamPortId);
}
else {
auto slaveOrMaster = (metricSet.find("output") != std::string::npos) ?
XAIE_STRMSW_SLAVE : XAIE_STRMSW_MASTER;
XAie_EventSelectStrmPort(aieDevInst, loc, rscId, slaveOrMaster, DMA, channel);
// Memory tiles
if (metricSet.find("trace") != std::string::npos) {
switchPortRsc->setPortToSelect(XAIE_STRMSW_SLAVE, TRACE, 0);
}
else {
auto slaveOrMaster = (metricSet.find("output") != std::string::npos) ?
XAIE_STRMSW_SLAVE : XAIE_STRMSW_MASTER;
switchPortRsc->setPortToSelect(slaveOrMaster, DMA, channel);
}
}

// Event options:
// getSSIdleEvent, getSSRunningEvent, getSSStalledEvent, & getSSTlastEvent
XAie_Events ssEvent;
if (isPortRunningEvent(event))
switchPortRsc->getSSRunningEvent(ssEvent);
else
switchPortRsc->getSSStalledEvent(ssEvent);

switchPortRsc->start();
mStreamPorts.push_back(switchPortRsc);
return ssEvent;
}

void
Expand Down Expand Up @@ -472,11 +490,15 @@ namespace xdp {
auto configChannel1 = metadata->getConfigChannel1();

for (int module = 0; module < metadata->getNumModules(); ++module) {
auto configMetrics = metadata->getConfigMetrics(module);
if (configMetrics.empty())
continue;

int numTileCounters[metadata->getNumCountersMod(module)+1] = {0};
XAie_ModuleType mod = falModuleTypes[module];

// Iterate over tiles and metrics to configure all desired counters
for (auto& tileMetric : metadata->getConfigMetrics(module)) {
for (auto& tileMetric : configMetrics) {
auto tile = tileMetric.first;
auto col = tile.col;
auto row = tile.row;
Expand Down Expand Up @@ -516,20 +538,24 @@ namespace xdp {
auto endEvent = endEvents.at(i);
uint8_t resetEvent = 0;

// Channel number is based on monitoring port 0 or 1
auto channel = (startEvent <= XAIE_EVENT_PORT_TLAST_0_MEM_TILE) ? channel0 : channel1;

configGroupEvents(aieDevInst, loc, mod, startEvent, metricSet);
auto event = configStreamSwitchPorts(aieDevInst, tileMetric.first, xaieTile, loc, type,
startEvent, metricSet, channel);
if (event != startEvent) {
endEvent = (endEvent == startEvent) ? event : endEvent;
startEvent = event;
}

// Request counter from resource manager
auto perfCounter = xaieModule.perfCounter();
auto ret = perfCounter->initialize(mod, startEvent, mod, endEvent);
if (ret != XAIE_OK) break;
ret = perfCounter->reserve();
if (ret != XAIE_OK) break;

// Channel number is based on monitoring port 0 or 1
auto channel = (startEvent <= XAIE_EVENT_PORT_TLAST_0_MEM_TILE) ? channel0 : channel1;

configGroupEvents(aieDevInst, loc, mod, startEvent, metricSet);
configStreamSwitchPorts(aieDevInst, tileMetric.first, xaieTile, loc, type,
startEvent, i, metricSet, channel);

// Start the counters after group events have been configured
ret = perfCounter->start();
if (ret != XAIE_OK) break;
Expand Down Expand Up @@ -566,13 +592,12 @@ namespace xdp {
std::stringstream msg;
msg << "AIE profile counters reserved in " << metadata->getModuleName(module) << " - ";
for (int n=0; n <= metadata->getNumCountersMod(module); ++n) {
if (numTileCounters[n] == 0) continue;
msg << n << ": " << numTileCounters[n] << " tiles";
if (n != metadata->getNumCountersMod(module)) msg << ", ";

if (numTileCounters[n] == 0)
continue;
msg << n << ": " << numTileCounters[n] << " tiles, ";
(db->getStaticInfo()).addAIECounterResources(deviceId, n, numTileCounters[n], module);
}
xrt_core::message::send(severity_level::info, "XRT", msg.str());
xrt_core::message::send(severity_level::info, "XRT", msg.str().substr(0, msg.str().size()-2));
}

runtimeCounters = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ namespace xdp {
module_type getModuleType(uint16_t absRow, XAie_ModuleType mod);
bool isValidType(module_type type, XAie_ModuleType mod);
bool isStreamSwitchPortEvent(const XAie_Events event);
bool isPortRunningEvent(const XAie_Events event);
void printTileModStats(xaiefal::XAieDev* aieDevice,
const tile_type& tile,
const XAie_ModuleType mod);
Expand All @@ -57,15 +58,14 @@ namespace xdp {
const XAie_ModuleType mod,
const XAie_Events event,
const std::string metricSet);
void configStreamSwitchPorts(XAie_DevInst* aieDevInst,
const tile_type& tile,
xaiefal::XAieTile& xaieTile,
const XAie_LocType loc,
const module_type type,
const XAie_Events event,
const int countnum,
const std::string metricSet,
const uint8_t channel);
XAie_Events configStreamSwitchPorts(XAie_DevInst* aieDevInst,
const tile_type& tile,
xaiefal::XAieTile& xaieTile,
const XAie_LocType loc,
const module_type type,
const XAie_Events event,
const std::string metricSet,
const uint8_t channel);
void configEventSelections(XAie_DevInst* aieDevInst,
const XAie_LocType loc,
const XAie_ModuleType mod,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,15 @@ class AieTraceMetadata {
std::map<module_type, std::string> defaultSets {
{ module_type::core, "functions"},
{ module_type::mem_tile, "input_channels"},
{ module_type::shim, "ports"}
{ module_type::shim, "input_ports"}
};

std::map <module_type, std::vector<std::string>> metricSets {
{ module_type::core, {"functions", "functions_partial_stalls",
"functions_all_stalls", "all"} },
{ module_type::mem_tile, {"input_channels", "input_channels_stalls",
"output_channels", "output_channels_stalls"} },
{ module_type::shim, {"ports", "input_ports", "output_ports",
{ module_type::shim, {"input_ports", "output_ports",
"input_ports_stalls", "output_ports_stalls",
"input_ports_details", "output_ports_details"} }
};
Expand Down
Loading

0 comments on commit ce6ee4a

Please sign in to comment.