Skip to content

Commit

Permalink
CR-1142089 - Improvements to AIE graph hierarchy and channel support (X…
Browse files Browse the repository at this point in the history
  • Loading branch information
pgschuey authored Aug 14, 2023
1 parent 3d1df80 commit 7c01ed1
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 107 deletions.
36 changes: 18 additions & 18 deletions src/runtime_src/xdp/profile/database/static_info/aie_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ namespace aie {
auto currPort = name.substr(namePos+1);

// Make sure this matches what we're looking for
if ((channelId >= 0) && (channelId != streamId))
continue;
//if ((channelId >= 0) && (channelId != streamId))
// continue;
if ((portName.compare("all") != 0)
&& (portName.compare(currPort) != 0)
&& (portName.compare(logicalName) != 0))
Expand All @@ -253,13 +253,18 @@ 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))
|| (!isMaster && (metricStr.find("output") != 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)))
continue;

if ((channelId >= 0) && (channelId != io.second.channelNum))
continue;

tile_type tile = {0};
tile.col = shimCol;
tile.row = 0;
Expand All @@ -281,11 +286,11 @@ namespace aie {
// Memory Tiles
// **************************************************************************

// Find all memory tiles associated with a graph and kernel
// kernel_name = all : all tiles in graph
// kernel_name = <kernel> : only tiles used by that specific kernel
// Find all memory tiles associated with a graph and buffer
// buffer_name = all : all tiles in graph
// buffer_name = <buffer> : only tiles used by that specific buffer
std::vector<tile_type> getMemoryTiles(const boost::property_tree::ptree& aie_meta, const std::string& graph_name,
const std::string& kernel_name)
const std::string& buffer_name)
{
if (getHardwareGeneration(aie_meta) == 1)
return {};
Expand All @@ -306,13 +311,10 @@ namespace aie {
if ((currGraph.find(graph_name) == std::string::npos)
&& (graph_name.compare("all") != 0))
continue;
if (kernel_name.compare("all") != 0) {
std::vector<std::string> names;
std::string functionStr = shared_buffer.second.get<std::string>("function");
boost::split(names, functionStr, boost::is_any_of("."));
if (std::find(names.begin(), names.end(), kernel_name) == names.end())
continue;
}
auto currBuffer = shared_buffer.second.get<std::string>("bufferName");
if ((currBuffer.find(buffer_name) == std::string::npos)
&& (buffer_name.compare("all") != 0))
continue;

tile_type tile;
tile.col = shared_buffer.second.get<uint16_t>("column");
Expand Down Expand Up @@ -411,16 +413,14 @@ namespace aie {
return tiles;
}

// Find all AIE or memory tiles associated with a graph and kernel
// Find all AIE or memory tiles associated with a graph and kernel/buffer
// kernel_name = all : all tiles in graph
// kernel_name = <kernel> : only tiles used by that specific kernel
std::vector<tile_type> getTiles(const boost::property_tree::ptree& aie_meta, const std::string& graph_name,
module_type type, const std::string& kernel_name)
{
if (type == module_type::mem_tile)
return getMemoryTiles(aie_meta, graph_name, kernel_name);
if (kernel_name.compare("all") == 0)
return getAIETiles(aie_meta, graph_name);

// Now search by graph-kernel pairs
auto kernelToTileMapping = aie_meta.get_child_optional("aie_metadata.TileMapping.AIEKernelToTileMapping");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace aie {

std::vector<tile_type> getMemoryTiles(const boost::property_tree::ptree& aie_meta,
const std::string& graph_name,
const std::string& kernel_name = "all");
const std::string& buffer_name = "all");

std::vector<tile_type> getAIETiles(const boost::property_tree::ptree& aie_meta,
const std::string& graph_name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,6 @@ namespace xdp {
{
if (type == module_type::mem_tile)
return get_mem_tiles(device, graph_name, kernel_name);
if (kernel_name.compare("all") == 0)
return get_aie_tiles(device, graph_name, type);

// Now search by graph-kernel pairs
auto data = device->get_axlf_section(AIE_METADATA);
Expand Down Expand Up @@ -359,13 +357,18 @@ namespace xdp {

// STEP 1 : Parse per-graph or per-kernel settings

/* AIE_profile_settings config format ; Multiple values can be specified for
* a metric separated with ';' AI Engine Tiles graph_based_aie_metrics = <graph name|all>:<kernel
* name|all>:<off|heat_map|stalls|execution|floating_point|write_throughputs|read_throughputs|aie_trace>
* graph_based_aie_memory_metrics = <graph name|all>:<kernel
* name|all>:<off|conflicts|dma_locks|dma_stalls_s2mm|dma_stalls_mm2s|write_throughputs|read_throughputs> MEM Tiles
* graph_based_memory_tile_metrics = <graph name|all>:<kernel
* name|all>:<off|input_channels|output_channels|memory_stats>[:<channel>]
/* AIE_profile_settings config format
* Multiple values can be specified separated with ';'
*
* AI Engine Tiles
* graph_based_aie_metrics = <graph name|all>:<kernel name|all>
* :<off|heat_map|stalls|execution|floating_point|write_throughputs|read_throughputs|aie_trace>
* graph_based_aie_memory_metrics = <graph name|all>:<kernel name|all>
* :<off|conflicts|dma_locks|dma_stalls_s2mm|dma_stalls_mm2s|write_throughputs|read_throughputs> MEM Tiles
*
* Memory tiles (AIE2 and beyond)
* graph_based_memory_tile_metrics = <graph name|all>:<buffer name|all>
* :<off|input_channels|input_channels_details|output_channels|output_channels_details|memory_stats|mem_trace>[:<channel>]
*/

std::vector<std::vector<std::string>> graphMetrics(graphMetricsSettings.size());
Expand Down Expand Up @@ -416,16 +419,6 @@ namespace xdp {
// Check if already processed or if invalid
if (graphMetrics[i][0].compare("all") == 0)
continue;
if (std::find(allValidGraphs.begin(), allValidGraphs.end(), graphMetrics[i][0]) == allValidGraphs.end()) {
std::stringstream msg;
msg << "Could not find graph " << graphMetrics[i][0]
<< " as specified in graph_based_" << modName << "_metrics setting."
<< " The following graphs are valid : " << allValidGraphs[0];
for (size_t j = 1; j < allValidGraphs.size(); j++)
msg << ", " << allValidGraphs[j];
xrt_core::message::send(severity_level::warning, "XRT", msg.str());
continue;
}
if ((graphMetrics[i][1].compare("all") != 0) &&
(std::find(allValidKernels.begin(), allValidKernels.end(), graphMetrics[i][1]) == allValidKernels.end())) {
std::stringstream msg;
Expand Down Expand Up @@ -462,25 +455,28 @@ namespace xdp {

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

/* AIE_profile_settings config format ; Multiple values can be specified for
* a metric separated with ';' AI Engine Tiles Single or all tiles
* tile_based_aie_metrics =
* [[{<column>,<row>}|all>:<off|heat_map|stalls|execution|floating_point|write_throughputs|read_throughputs|aie_trace>]
* tile_based_aie_memory_metrics =
* [[<{<column>,<row>}|all>:<off|conflicts|dma_locks|dma_stalls_s2mm|dma_stalls_mm2s|write_throughputs|read_throughputs>]
/* AIE_profile_settings config format
* Multiple values can be specified separated with ';'
*
* AI Engine Tiles
* Single or all tiles
* tile_based_aie_metrics = [[{<column>,<row>}|all>
* :<off|heat_map|stalls|execution|floating_point|write_throughputs|read_throughputs|aie_trace>]
* tile_based_aie_memory_metrics = [[<{<column>,<row>}|all>
* :<off|conflicts|dma_locks|dma_stalls_s2mm|dma_stalls_mm2s|write_throughputs|read_throughputs>]
* Range of tiles
* tile_based_aie_metrics =
* [{<mincolumn,<minrow>}:{<maxcolumn>,<maxrow>}:<off|heat_map|stalls|execution|floating_point|write_throughputs|read_throughputs|aie_trace>]]
* tile_based_aie_memory_metrics =
* [{<mincolumn,<minrow>}:{<maxcolumn>,<maxrow>}:<off|conflicts|dma_locks|dma_stalls_s2mm|dma_stalls_mm2s|write_throughputs|read_throughputs>]]
* tile_based_aie_metrics = [{<mincolumn,<minrow>}:{<maxcolumn>,<maxrow>}
* :<off|heat_map|stalls|execution|floating_point|write_throughputs|read_throughputs|aie_trace>]]
* tile_based_aie_memory_metrics = [{<mincolumn,<minrow>}:{<maxcolumn>,<maxrow>}
* :<off|conflicts|dma_locks|dma_stalls_s2mm|dma_stalls_mm2s|write_throughputs|read_throughputs>]]
*
* MEM Tiles (AIE2 and beyond)
* Memory Tiles (AIE2 and beyond)
* Single or all tiles
* tile_based_memory_tile_metrics =
* [[<{<column>,<row>}|all>:<off|input_channels|input_channels_details|output_channels|output_channels_details|memory_stats>[:<channel>]]
* tile_based_memory_tile_metrics = [[<{<column>,<row>}|all>
* :<off|input_channels|input_channels_details|output_channels|output_channels_details|memory_stats|mem_trace>[:<channel>]]
* Range of tiles
* tile_based_memory_tile_metrics =
* [{<mincolumn,<minrow>}:{<maxcolumn>,<maxrow>}:<off|input_channels|output_channels|memory_stats>[:<channel>]]]
* tile_based_memory_tile_metrics = [{<mincolumn,<minrow>}:{<maxcolumn>,<maxrow>}
* :<off|input_channels|input_channels_details|output_channels|output_channels_details|memory_stats|mem_trace>[:<channel>]]]
*/

std::vector<std::vector<std::string>> metrics(metricsSettings.size());
Expand Down Expand Up @@ -816,11 +812,12 @@ namespace xdp {
if (metrics[i][0].compare("all") != 0)
continue;

int16_t channelId = (metrics[i].size() < 3) ? -1 : static_cast<uint16_t>(std::stoul(metrics[i][2]));
uint8_t channelId = (metrics[i].size() < 3) ? 0 : static_cast<uint8_t>(std::stoul(metrics[i][2]));
auto tiles = aie::getInterfaceTiles(aie_meta, "all", "all", metrics[i][1], channelId);

for (auto& e : tiles) {
configMetrics[moduleIdx][e] = metrics[i][1];
for (auto& t : tiles) {
configMetrics[moduleIdx][t] = metrics[i][1];
configChannel0[t] = channelId;
}
} // Pass 1

Expand Down Expand Up @@ -850,18 +847,17 @@ namespace xdp {
continue;
}

int16_t channelId = 0;
uint8_t channelId = 0;
if (metrics[i].size() == 4) {
try {
channelId = static_cast<uint16_t>(std::stoul(metrics[i][3]));
channelId = static_cast<uint8_t>(std::stoul(metrics[i][3]));
}
catch (std::invalid_argument const&) {
// Expected channel Id is not an integer, give warning and ignore channelId
// Expected channel Id is not an integer, give warning and ignore
xrt_core::message::send(severity_level::warning, "XRT",
"Channel ID specification in "
"tile_based_interface_tile_metrics is "
"not an integer and hence ignored.");
channelId = -1;
}
}

Expand All @@ -870,6 +866,7 @@ namespace xdp {

for (auto& t : tiles) {
configMetrics[moduleIdx][t] = metrics[i][2];
configChannel0[t] = channelId;
}
} // Pass 2

Expand All @@ -896,19 +893,17 @@ namespace xdp {
continue;
}

int16_t channelId = -1;
uint8_t channelId = 0;
if (metrics[i].size() == 3) {
try {
channelId = static_cast<uint16_t>(std::stoul(metrics[i][2]));
channelId = static_cast<uint8_t>(std::stoul(metrics[i][2]));
}
catch (std::invalid_argument const&) {
// Expected channel Id is not an integer, give warning and
// ignore channelId
// Expected channel Id is not an integer, give warning and ignore
xrt_core::message::send(severity_level::warning, "XRT",
"Channel ID specification in "
"tile_based_interface_tile_metrics is not an integer "
"and hence ignored.");
channelId = -1;
}
}

Expand All @@ -917,6 +912,7 @@ namespace xdp {

for (auto& t : tiles) {
configMetrics[moduleIdx][t] = metrics[i][1];
configChannel0[t] = channelId;
}
}
} // Pass 3
Expand Down
Loading

0 comments on commit 7c01ed1

Please sign in to comment.