51 std::map<TileID, int> sourceCounts;
52 std::map<TileID, int> destinationCounts;
53 for (FlowOp flowOp : targetOp.getOps<FlowOp>()) {
54 TileOp source = cast<TileOp>(flowOp.getSource().getDefiningOp());
55 TileOp dest = cast<TileOp>(flowOp.getDest().getDefiningOp());
56 TileID srcID = {source.colIndex(), source.rowIndex()};
57 TileID dstID = {dest.colIndex(), dest.rowIndex()};
58 sourceCounts[srcID]++;
59 destinationCounts[dstID]++;
61 for (PacketFlowOp pktFlowOp : targetOp.getOps<PacketFlowOp>()) {
62 Region &r = pktFlowOp.getPorts();
64 for (Operation &Op : b.getOperations()) {
65 if (
auto pktSource = dyn_cast<PacketSourceOp>(Op)) {
66 TileOp source = dyn_cast<TileOp>(pktSource.getTile().getDefiningOp());
67 TileID srcID = {source.colIndex(), source.rowIndex()};
68 sourceCounts[srcID]++;
69 }
else if (
auto pktDest = dyn_cast<PacketDestOp>(Op)) {
70 TileOp dest = dyn_cast<TileOp>(pktDest.getTile().getDefiningOp());
71 TileID dstID = {dest.colIndex(), dest.rowIndex()};
72 destinationCounts[dstID]++;
77 std::map<TileID, ShimMuxOp> shimMuxes;
78 for (ShimMuxOp shimMuxOp : targetOp.getOps<ShimMuxOp>()) {
79 shimMuxes[{shimMuxOp.colIndex(), shimMuxOp.rowIndex()}] = shimMuxOp;
82 int totalPathLength = 0;
84 for (SwitchboxOp switchboxOp : targetOp.getOps<SwitchboxOp>()) {
85 int col = switchboxOp.colIndex();
86 int row = switchboxOp.rowIndex();
87 std::string switchString =
"\"switchbox" + std::to_string(
col) +
88 std::to_string(
row) +
"\": {\n" +
89 "\"col\": " + std::to_string(
col) +
",\n" +
90 "\"row\": " + std::to_string(
row) +
",\n";
94 "\"source_count\": " + std::to_string(sourceCounts[{
col,
row}]) +
",\n";
95 switchString +=
"\"destination_count\": " +
96 std::to_string(destinationCounts[{
col,
row}]) +
",\n";
99 uint32_t connectCounts[10];
100 for (
auto &connectCount : connectCounts)
103 std::set<Port> ports;
104 for (ConnectOp connectOp : switchboxOp.getOps<ConnectOp>())
105 ports.insert(connectOp.destPort());
106 for (MasterSetOp masterSetOp : switchboxOp.getOps<MasterSetOp>())
107 ports.insert(masterSetOp.destPort());
109 connectCounts[int(
port.bundle)]++;
112 switchString +=
"\"northbound\": " +
113 std::to_string(connectCounts[
int(WireBundle::North)]) +
115 switchString +=
"\"eastbound\": " +
116 std::to_string(connectCounts[
int(WireBundle::East)]) +
118 switchString +=
"\"southbound\": " +
119 std::to_string(connectCounts[
int(WireBundle::South)]) +
121 switchString +=
"\"westbound\": " +
122 std::to_string(connectCounts[
int(WireBundle::West)]) +
"\n";
123 switchString +=
"},\n";
124 output << switchString;
127 totalPathLength += connectCounts[int(WireBundle::North)];
128 totalPathLength += connectCounts[int(WireBundle::East)];
129 totalPathLength += connectCounts[int(WireBundle::South)];
130 totalPathLength += connectCounts[int(WireBundle::West)];
133 if (shimMuxes.count({col, row})) {
134 auto shimMuxOp = shimMuxes[{
col,
row}];
135 std::set<Port> ports;
136 for (ConnectOp connectOp : shimMuxOp.getOps<ConnectOp>()) {
138 if (
port.bundle == WireBundle::North) {
142 for (PacketRulesOp packetRulesOp : shimMuxOp.getOps<PacketRulesOp>()) {
143 Port port = packetRulesOp.sourcePort();
144 if (
port.bundle == WireBundle::North) {
148 totalPathLength -= ports.size();
153 output <<
"\"total_path_length\": " << totalPathLength <<
",\n";
157 raw_ostream &output) {
159 std::set<std::pair<TileOp, Port>> flowSources;
160 for (FlowOp flowOp : targetOp.getOps<FlowOp>()) {
162 Port currPort = {flowOp.getSourceBundle(), flowOp.getSourceChannel()};
163 SwitchboxOp currSwitchbox;
165 TileOp source = cast<TileOp>(flowOp.getSource().getDefiningOp());
169 std::pair<TileOp, Port> flowSource = {source, currPort};
170 if (flowSources.count(flowSource)) {
173 flowSources.insert(flowSource);
175 std::string routeString =
176 "\"route" + std::to_string(flowCount++) +
"\": [ ";
179 std::queue<Port> nextPorts;
180 std::queue<SwitchboxOp> nextSwitches;
183 for (SwitchboxOp switchboxOp : targetOp.getOps<SwitchboxOp>()) {
184 if (switchboxOp.colIndex() == source.colIndex() &&
185 switchboxOp.rowIndex() == source.rowIndex()) {
186 currSwitchbox = switchboxOp;
192 for (ShimMuxOp shimMuxOp : targetOp.getOps<ShimMuxOp>()) {
193 if (shimMuxOp.colIndex() == source.colIndex() &&
194 shimMuxOp.rowIndex() == source.rowIndex()) {
195 for (ConnectOp connectOp : shimMuxOp.getOps<ConnectOp>()) {
196 if (connectOp.getSourceBundle() == currPort.bundle &&
197 connectOp.getSourceChannel() == currPort.channel) {
199 currPort.channel = connectOp.getDestChannel();
211 for (ConnectOp connectOp : currSwitchbox.getOps<ConnectOp>()) {
213 if ((currSwitchbox.rowIndex() == 0 &&
214 connectOp.getDestBundle() == WireBundle::South) ||
215 connectOp.getDestBundle() == WireBundle::DMA ||
216 connectOp.getDestBundle() == WireBundle::Core)
219 if (connectOp.getSourceBundle() == currPort.bundle &&
220 connectOp.getSourceChannel() == currPort.channel) {
222 connectOp.getDestChannel()});
225 getNextCoords(currSwitchbox.colIndex(), currSwitchbox.rowIndex(),
226 connectOp.getDestBundle());
229 for (SwitchboxOp switchboxOp : targetOp.getOps<SwitchboxOp>()) {
230 if (switchboxOp.colIndex() == nextCoords.col &&
231 switchboxOp.rowIndex() == nextCoords.row) {
232 nextSwitches.push(switchboxOp);
240 std::string dirString = std::string(
"[[") +
241 std::to_string(currSwitchbox.colIndex()) +
", " +
242 std::to_string(currSwitchbox.rowIndex()) +
"], [";
243 int opCount = 0, dirCount = 0;
244 for (ConnectOp connectOp : currSwitchbox.getOps<ConnectOp>()) {
245 if (connectOp.getSourceBundle() == currPort.bundle &&
246 connectOp.getSourceChannel() == currPort.channel) {
252 (std::string)stringifyWireBundle(connectOp.getDestBundle()) +
258 routeString += dirString;
260 if (nextPorts.empty() || nextSwitches.empty()) {
264 currPort = nextPorts.front();
265 currSwitchbox = nextSwitches.front();
271 routeString += std::string(
" ],\n");
272 output << routeString;
277 raw_ostream &output) {
279 std::set<std::pair<TileOp, Port>> flowSources;
280 for (PacketFlowOp pktFlowOp : targetOp.getOps<PacketFlowOp>()) {
281 Region &r = pktFlowOp.getPorts();
282 Block &b = r.front();
283 Port sourcePort, destPort;
285 for (Operation &Op : b.getOperations()) {
286 if (
auto pktSource = dyn_cast<PacketSourceOp>(Op)) {
287 source = dyn_cast<TileOp>(pktSource.getTile().getDefiningOp());
288 sourcePort = pktSource.port();
289 }
else if (
auto pktDest = dyn_cast<PacketDestOp>(Op)) {
290 dest = dyn_cast<TileOp>(pktDest.getTile().getDefiningOp());
291 destPort = pktDest.port();
296 Port currPort = sourcePort;
297 SwitchboxOp currSwitchbox;
300 std::pair<TileOp, Port> flowSource = {source, currPort};
301 if (flowSources.count(flowSource)) {
304 flowSources.insert(flowSource);
306 std::string routeString =
307 "\"route" + std::to_string(flowCount++) +
"\": [ ";
310 std::queue<Port> nextPorts;
311 std::queue<SwitchboxOp> nextSwitches;
314 for (SwitchboxOp switchboxOp : targetOp.getOps<SwitchboxOp>()) {
315 if (switchboxOp.colIndex() == source.colIndex() &&
316 switchboxOp.rowIndex() == source.rowIndex()) {
317 currSwitchbox = switchboxOp;
323 for (ShimMuxOp shimMuxOp : targetOp.getOps<ShimMuxOp>()) {
324 if (shimMuxOp.colIndex() == source.colIndex() &&
325 shimMuxOp.rowIndex() == source.rowIndex()) {
326 for (ConnectOp connectOp : shimMuxOp.getOps<ConnectOp>()) {
327 if (connectOp.getSourceBundle() == currPort.bundle &&
328 connectOp.getSourceChannel() == currPort.channel) {
330 currPort.channel = connectOp.getDestChannel();
341 for (
auto packetRulesOp : currSwitchbox.getOps<PacketRulesOp>()) {
343 for (
auto masterSetOp : currSwitchbox.getOps<MasterSetOp>()) {
344 for (Value amsel : masterSetOp.getAmsels()) {
346 packetRulesOp.getRules().front().getOps<PacketRuleOp>()) {
347 if (ruleOp.getAmsel() == amsel) {
348 destPort = masterSetOp.destPort();
355 if ((currSwitchbox.rowIndex() == 0 &&
356 destPort.bundle == WireBundle::South) ||
357 destPort.bundle == WireBundle::DMA ||
358 destPort.bundle == WireBundle::Core)
361 if (packetRulesOp.sourcePort() == currPort) {
366 getNextCoords(currSwitchbox.colIndex(), currSwitchbox.rowIndex(),
370 for (SwitchboxOp switchboxOp : targetOp.getOps<SwitchboxOp>()) {
371 if (switchboxOp.colIndex() == nextCoords.col &&
372 switchboxOp.rowIndex() == nextCoords.row) {
373 nextSwitches.push(switchboxOp);
381 std::string dirString = std::string(
"[[") +
382 std::to_string(currSwitchbox.colIndex()) +
", " +
383 std::to_string(currSwitchbox.rowIndex()) +
"], [";
384 int opCount = 0, dirCount = 0;
385 for (
auto packetRulesOp : currSwitchbox.getOps<PacketRulesOp>()) {
386 if (packetRulesOp.sourcePort() == currPort) {
388 for (
auto masterSetOp : currSwitchbox.getOps<MasterSetOp>()) {
389 for (Value amsel : masterSetOp.getAmsels()) {
391 packetRulesOp.getRules().front().getOps<PacketRuleOp>()) {
392 if (ruleOp.getAmsel() == amsel) {
393 destPort = masterSetOp.destPort();
402 "\"" + (std::string)stringifyWireBundle(destPort.bundle) +
"\"";
407 routeString += dirString;
409 if (nextPorts.empty() || nextSwitches.empty()) {
413 currPort = nextPorts.front();
414 currSwitchbox = nextSwitches.front();
420 routeString += std::string(
" ],\n");
421 output << routeString;