Skip to content

Use tablegen Python bindings for trace events instead of separate generation#3038

Merged
hunhoffe merged 4 commits into
mainfrom
remove-python-event-enum
May 11, 2026
Merged

Use tablegen Python bindings for trace events instead of separate generation#3038
hunhoffe merged 4 commits into
mainfrom
remove-python-event-enum

Conversation

@yenjames
Copy link
Copy Markdown
Collaborator

@yenjames yenjames commented Apr 24, 2026

Summary

Trace event enums were duplicated across two generation pipelines that both parsed the same aie-rt C headers. We remove the redundant Python enum generation.

Changes

  • python/utils/trace/events/__init__.py: Import event enums from aie.dialects._aie_enum_gen instead of generated per-arch modules. Use SimpleNamespace for get_events_for_device(). Fix GenericEvent.init to check Enum before int since IntEnum is a subclass of both.
  • python/CMakeLists.txt: Remove Python enum generation, GenerateTraceEventsEnum target, and associated copy/install steps.
  • include/aie/Dialect/AIE/IR/CMakeLists.txt: Fold events_database.json generation into the existing GenerateAIEEventsTD target alongside the tablegen files, sharing the same aie-rt header inputs.
  • utils/generate_events_json.py: Renamed from generate_events_enum.py, stripped of Python enum generation. Now JSON-only, invoked at build time by GenerateAIEEventsTD.
  • test/python/trace_events.py: Updated to assert MemTileEvent is None for AIE1 instead of iterating an empty enum.

…se pattern; remove generate_events_enum.py and use events generated through tablegen.
@yenjames yenjames marked this pull request as ready for review April 29, 2026 15:52
Copilot AI review requested due to automatic review settings April 29, 2026 15:52
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Removes the redundant Python trace-event enum generation pipeline and switches Python trace utilities to consume TableGen-generated enum bindings, while checking in a unified JSON event database for C++ lookups.

Changes:

  • Switch aie.utils.trace.events to import architecture event enums from aie.dialects._aie_enum_gen and provide get_events_for_device() via SimpleNamespace.
  • Remove Python CMake targets/steps that generated and installed per-arch Python enum modules and the events JSON.
  • Add events_database.json to the regdb resources and provide an offline generator utils/generate_events_json.py.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
utils/generate_events_json.py Drops Python enum generation and emits JSON-only event database from aie-rt headers.
python/utils/trace/events/init.py Uses TableGen Python enums and updates device→arch selection + GenericEvent int/enum handling.
python/CMakeLists.txt Removes build/install steps for generated Python trace-event enums/JSON.
lib/Dialect/AIE/Util/events_database.json Checks in the unified event database JSON used by the C++ register database.
lib/Dialect/AIE/Util/CMakeLists.txt Copies/installs events_database.json as part of regdb resources.
test/python/trace_events.py Updates tests to use get_events_for_device() instead of importing per-arch enum modules.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread python/utils/trace/events/__init__.py
Copy link
Copy Markdown
Collaborator

@hunhoffe hunhoffe left a comment

Choose a reason for hiding this comment

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

Looks like a clean improvement! I had some questions, but overall, I like it!

@hunhoffe
Copy link
Copy Markdown
Collaborator

hunhoffe commented May 6, 2026

Does this PR address this issue? #3012

@hunhoffe hunhoffe added this to the IRON 1.3.2 milestone May 6, 2026
@yenjames yenjames linked an issue May 6, 2026 that may be closed by this pull request
@yenjames
Copy link
Copy Markdown
Collaborator Author

yenjames commented May 6, 2026

Does this PR address this issue? #3012

Yes, just linked it to that issue.


from aie.dialects.aie import WireBundle, DMAChannelDir

# Default to AIE2 for backwards compatibility
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm a little confused abut why we set defaults when there's a function below that does more correct conditional sets? Can you clarify a bit?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes this is a part where I don't have a clear solution. The issue is the tablegen events suffixes the event names with the architecture (CoreEventAIE2.), but I still wanted to keep the aliases CoreEvent etc to paper over this name. The backwards compatibility comment is not very correct.

The get_events_for_device is more correct but it will require changing all examples to first acquire events with it.

Comment thread python/utils/trace/events/__init__.py Outdated
):
# For backwards compatibility, allow integer as event
if isinstance(code, int):
# For backwards compatibility, allow plain integer as event.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Honestly curious: do we need backwards compatibility here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I think not really needed, we should use events by the enum type and error for other types.

def main():
argparser = argparse.ArgumentParser(
description="Generate Python enums and JSON database from AIE event headers"
description="Generate JSON event database from AIE event headers"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Just to double check -- the JSON file is checked in in GitHub on this PR. In the past, I thought this was generated at compile time, and not checked in. I don't feel strongly about which one is best, but just to check -- was that purposeful?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

As pointed out by Jeff, this was a mistake on my end.

Copy link
Copy Markdown
Collaborator

@fifield fifield left a comment

Choose a reason for hiding this comment

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

This PR goes farther than removing the duplicated event enums by also removing the generated events_database.json. Generating the events_database.json is intended and not duplication. Can we restore that part, or fold the generation of the json into the cmake rules for generating the tablegen files (if reducing lines of cmake is also a goal of the PR)?

@yenjames
Copy link
Copy Markdown
Collaborator Author

yenjames commented May 8, 2026

This PR goes farther than removing the duplicated event enums by also removing the generated events_database.json. Generating the events_database.json is intended and not duplication. Can we restore that part, or fold the generation of the json into the cmake rules for generating the tablegen files (if reducing lines of cmake is also a goal of the PR)?

Reverted, this was overdone and a mistake on my end. Thank you for catching this!

@hunhoffe hunhoffe added this pull request to the merge queue May 10, 2026
Merged via the queue into main with commit 7fd5c8e May 11, 2026
71 checks passed
@hunhoffe hunhoffe deleted the remove-python-event-enum branch May 11, 2026 00:04
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.

Use MLIR Python binding enums for trace events

4 participants