Skip to content

Add aie-insert-trace-flows pass#19

Draft
fifield wants to merge 3 commits intoevents_proposalfrom
insert-trace-flows
Draft

Add aie-insert-trace-flows pass#19
fifield wants to merge 3 commits intoevents_proposalfrom
insert-trace-flows

Conversation

@fifield
Copy link
Copy Markdown
Owner

@fifield fifield commented Mar 4, 2026

Add aie-insert-trace-flows pass

Implement new MLIR pass to automatically insert trace packet flows and runtime sequence configuration for AIE trace operations.

@fifield
Copy link
Copy Markdown
Owner Author

fifield commented Mar 4, 2026

depends on Xilinx#2705

Comment on lines +67 to +68
std::unique_ptr<mlir::OperationPass<DeviceOp>>
createAIEInsertTraceFlowsPass();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[clang-format] reported by reviewdog 🐶

Suggested change
std::unique_ptr<mlir::OperationPass<DeviceOp>>
createAIEInsertTraceFlowsPass();
std::unique_ptr<mlir::OperationPass<DeviceOp>> createAIEInsertTraceFlowsPass();

if (eventNum) {
startEvent = *eventNum;
} else {
startOp.emitError("unknown broadcast event '") << eventName << "'";
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[clang-format] reported by reviewdog 🐶

Suggested change
startOp.emitError("unknown broadcast event '") << eventName << "'";
startOp.emitError("unknown broadcast event '")
<< eventName << "'";

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit

black

[black] reported by reviewdog 🐶

interval['start'] + interval['duration'] / 2,


[black] reported by reviewdog 🐶

event_name.replace('INSTR_', '').replace('DMA_', '').replace('_', ' '),
ha='center',
va='center',


[black] reported by reviewdog 🐶

weight='bold',
clip_on=True


[black] reported by reviewdog 🐶


[black] reported by reviewdog 🐶


[black] reported by reviewdog 🐶


[black] reported by reviewdog 🐶

ax.set_xlabel('Time (cycles)', fontsize=10)
ax.set_title(title, fontsize=12, weight='bold')
ax.grid(True, axis='x', alpha=0.3)


[black] reported by reviewdog 🐶

event_counts[interval['name']] += 1


[black] reported by reviewdog 🐶


[black] reported by reviewdog 🐶


[black] reported by reviewdog 🐶


[black] reported by reviewdog 🐶


[black] reported by reviewdog 🐶


[black] reported by reviewdog 🐶

plt.savefig(output_file, dpi=150, bbox_inches='tight')


[black] reported by reviewdog 🐶


[black] reported by reviewdog 🐶

print(f" Time range: {min(i['start'] for i in intervals)} - {max(i['end'] for i in intervals)} cycles")
print(f" Duration: {max(i['end'] for i in intervals) - min(i['start'] for i in intervals)} cycles")


[black] reported by reviewdog 🐶


[black] reported by reviewdog 🐶

description='Visualize trace JSON data as a PNG timeline'


[black] reported by reviewdog 🐶

'-i', '--input',
default='trace_mlir.json',
help='Input trace JSON file (default: trace_mlir.json)'


[black] reported by reviewdog 🐶

'-o', '--output',
default='trace_timeline.png',
help='Output PNG file (default: trace_timeline.png)'


[black] reported by reviewdog 🐶

'-t', '--title',
default='MLIR Trace Timeline',
help='Chart title (default: MLIR Trace Timeline)'


[black] reported by reviewdog 🐶


[black] reported by reviewdog 🐶


[black] reported by reviewdog 🐶

print(f"Found {len(processes)} processes, {len(threads)} threads, {len(events)} events")


[black] reported by reviewdog 🐶

if __name__ == '__main__':

@@ -0,0 +1,225 @@
#!/usr/bin/env python3
##===- visualize_trace.py -----------------------------------------------===##
#
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[black] reported by reviewdog 🐶

Suggested change
#
#

# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
# Copyright (C) 2025, Advanced Micro Devices, Inc.
#
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[black] reported by reviewdog 🐶

Suggested change
#
#

import matplotlib.patches as mpatches
from collections import defaultdict

def parse_trace_json(trace_file):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[black] reported by reviewdog 🐶

Suggested change
def parse_trace_json(trace_file):
def parse_trace_json(trace_file):


def parse_trace_json(trace_file):
"""Parse the trace JSON file and extract events."""
with open(trace_file, 'r') as f:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[black] reported by reviewdog 🐶

Suggested change
with open(trace_file, 'r') as f:
with open(trace_file, "r") as f:

"""Parse the trace JSON file and extract events."""
with open(trace_file, 'r') as f:
data = json.load(f)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[black] reported by reviewdog 🐶

Suggested change

Comment on lines +115 to +116
(interval['start'], lane - 0.4),
interval['duration'],
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[black] reported by reviewdog 🐶

Suggested change
(interval['start'], lane - 0.4),
interval['duration'],
(interval["start"], lane - 0.4),
interval["duration"],

interval['duration'],
0.8,
facecolor=color,
edgecolor='black',
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[black] reported by reviewdog 🐶

Suggested change
edgecolor='black',
edgecolor="black",

facecolor=color,
edgecolor='black',
linewidth=0.5,
alpha=0.7
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[black] reported by reviewdog 🐶

Suggested change
alpha=0.7
alpha=0.7,

alpha=0.7
)
ax.add_patch(rect)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[black] reported by reviewdog 🐶

Suggested change


# Add text label if duration is large enough (relative to visible range)
label_threshold = time_range / 100 # Show label if event is > 1% of total time
if interval['duration'] > label_threshold:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[black] reported by reviewdog 🐶

Suggested change
if interval['duration'] > label_threshold:
if interval["duration"] > label_threshold:

label_threshold = time_range / 100 # Show label if event is > 1% of total time
if interval['duration'] > label_threshold:
ax.text(
interval['start'] + interval['duration'] / 2,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[black] reported by reviewdog 🐶

Suggested change
interval['start'] + interval['duration'] / 2,
interval["start"] + interval["duration"] / 2,

Comment on lines +131 to +133
event_name.replace('INSTR_', '').replace('DMA_', '').replace('_', ' '),
ha='center',
va='center',
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[black] reported by reviewdog 🐶

Suggested change
event_name.replace('INSTR_', '').replace('DMA_', '').replace('_', ' '),
ha='center',
va='center',
event_name.replace("INSTR_", "").replace("DMA_", "").replace("_", " "),
ha="center",
va="center",

Comment on lines +135 to +136
weight='bold',
clip_on=True
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[black] reported by reviewdog 🐶

Suggested change
weight='bold',
clip_on=True
weight="bold",
clip_on=True,

weight='bold',
clip_on=True
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[black] reported by reviewdog 🐶

Suggested change

# Set up axes
ax.set_ylim(-0.5, lane_idx - 0.5)
ax.set_yticks(range(lane_idx))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[black] reported by reviewdog 🐶

Suggested change

Comment on lines +210 to +212
'-t', '--title',
default='MLIR Trace Timeline',
help='Chart title (default: MLIR Trace Timeline)'
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[black] reported by reviewdog 🐶

Suggested change
'-t', '--title',
default='MLIR Trace Timeline',
help='Chart title (default: MLIR Trace Timeline)'
"-t",
"--title",
default="MLIR Trace Timeline",
help="Chart title (default: MLIR Trace Timeline)",

default='MLIR Trace Timeline',
help='Chart title (default: MLIR Trace Timeline)'
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[black] reported by reviewdog 🐶

Suggested change

)

args = parser.parse_args()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[black] reported by reviewdog 🐶

Suggested change

Comment on lines +219 to +221

print(f"Found {len(processes)} processes, {len(threads)} threads, {len(events)} events")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[black] reported by reviewdog 🐶

Suggested change
print(f"Found {len(processes)} processes, {len(threads)} threads, {len(events)} events")
print(
f"Found {len(processes)} processes, {len(threads)} threads, {len(events)} events"
)


create_timeline(processes, threads, events, args.output, args.title)

if __name__ == '__main__':
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[black] reported by reviewdog 🐶

Suggested change
if __name__ == '__main__':
if __name__ == "__main__":

@fifield fifield force-pushed the insert-trace-flows branch from 7fcea46 to d580aba Compare March 4, 2026 21:21
fifield added 3 commits March 4, 2026 14:27
Implement new MLIR pass to automatically insert trace packet flows and
runtime sequence configuration for AIE trace operations.

Features:
- Creates packet flows from trace ports to shim DMA channels
- Supports core and mem trace types with correct port assignment
- Minimizes shim tile usage by routing multiple traces to same shim
- Allocates packet IDs automatically if not specified
- Inserts runtime sequence operations for trace setup (timer control,
  BD config, DMA setup, broadcast generation)
- Configurable options for shim channel, BD ID, packet ID, buffer size

Tests:
- test_insert_trace_flows_simple.mlir: Single core trace
- test_insert_trace_flows_multiple.mlir: Multiple traces (core + mem)
  from different tiles routing to one shim
@fifield fifield force-pushed the insert-trace-flows branch from d580aba to a2748ea Compare March 4, 2026 21:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant