Skip to content

Generate trace events enum package with CMake instead of manual generation#2696

Merged
fifield merged 16 commits intomainfrom
events_enum
Jan 5, 2026
Merged

Generate trace events enum package with CMake instead of manual generation#2696
fifield merged 16 commits intomainfrom
events_enum

Conversation

@fifield
Copy link
Collaborator

@fifield fifield commented Nov 10, 2025

Summary

Automates the generation of trace event enumerations during the build process and adds support for multiple AIE architectures (AIE1, AIE2/AIEML, AIE2P) instead of only AIE2.

Changes

  • Package structure: Renamed trace_events_enum.py to trace_events package with per-architecture modules (aie, aie2, aie2p)
  • Import pattern: Changed from from aie.utils.trace_events_enum import ... to from aie.utils.trace_events.aie2 import ... for explicit architecture selection
  • Class naming: Renamed PLEvent to ShimTileEvent to match expected usage in trace utilities
  • Build integration:
    • Generate Python enum files and JSON database during CMake build into build/regdb/ directory
    • Copy generated files to Python package directory with POST_BUILD commands
    • Install generated files alongside checked-in __init__.py
  • Generator improvements:
    • Map aieml architecture to aie2 Python module name
    • Conditionally emit UCEvent enum only when events are defined
    • Generate unified events.json database for future compiler integration
  • Updated imports: Modified trace.py, parse_trace.py, and parse_eventIR.py to use new package structure

Benefits

  • Multi-architecture support: Trace utilities now work with AIE1, AIE2/AIEML, and AIE2P instead of only AIE2
  • Trace events automatically stay in sync with aie-rt header files
  • No manual regeneration needed when aie-rt is updated
  • Architecture-specific imports make code more explicit and maintainable
  • Reduced git repository size (generated files no longer checked in)

Testing

  • All existing Python tests pass
  • Verified import compatibility across all architectures (AIE1: 123 events, AIE2: 127 events, AIE2P: 127 events)
  • Confirmed JSON database generation

@fifield
Copy link
Collaborator Author

fifield commented Nov 10, 2025

Summary

Automates the generation of trace event enumerations during the build process and adds support for multiple AIE architectures (AIE1, AIE2/AIEML, AIE2P) instead of only AIE2.

There's only one minor difference between aie2 and aie2p, so the differences don't matter in practice. The main goal here is to enable aie1 and aie2ps/aie4 in future.

@jackl-xilinx
Copy link
Collaborator

jackl-xilinx commented Nov 10, 2025

@fifield Can you do a diff between the generated events and the previous list of events in trace_events_enum.py. There are gaps where some values are not defined and this causes an issue with the numbering so I jut want to make sure all values are defined in the enum list.

@fifield
Copy link
Collaborator Author

fifield commented Nov 10, 2025

@fifield Can you do a diff between the generated events and the list of events. There are gaps where some values are not defined and this causes an issue with the numbering so I jut want to make sure all values are defined in the enum list.

You're right there were gaps. I didn't check vs. the original file. Fixed in 113327f

Copy link
Collaborator

@andrej andrej left a comment

Choose a reason for hiding this comment

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

Nice improvement to the trace infrastructure

Copy link
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

This PR automates the generation of trace event enumerations during the CMake build process and extends support from AIE2-only to multiple AIE architectures (AIE1, AIE2/AIEML, AIE2P).

Key changes:

  • Refactored generator script to support multiple architectures and output both Python enums and a unified JSON database
  • Restructured trace_events from a single file to a package with per-architecture modules (aie.py, aie2.py, aie2p.py)
  • Integrated generation into CMake build with automatic copying and installation of generated files

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
utils/generate_events_enum.py Extended to process multiple architecture headers, generate JSON database, and output per-architecture Python modules with configurable naming
python/utils/trace_events/init.py New package initialization file documenting available architecture modules
python/utils/trace.py Updated import to use new package structure (aie.utils.trace_events.aie2)
python/utils/parse_trace.py Updated import to use new package structure and renamed PLEvent to ShimTileEvent
python/utils/parse_eventIR.py Updated import to use new package structure and renamed PLEvent to ShimTileEvent
python/CMakeLists.txt Added CMake custom commands to generate trace event files, copy to build directory, and install them as a package

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

Copy link
Contributor

Copilot AI commented Nov 11, 2025

@fifield I've opened a new pull request, #2697, to work on those changes. Once the pull request is ready, I'll request review from you.

@fifield fifield force-pushed the events_enum branch 2 times, most recently from acb18cc to ee47a25 Compare November 14, 2025 21:03
@fifield fifield requested a review from hunhoffe as a code owner November 14, 2025 21:03
@fifield fifield force-pushed the events_enum branch 2 times, most recently from 9d79c16 to 353e830 Compare December 16, 2025 23:02
@fifield fifield requested a review from jsetoain as a code owner December 16, 2025 23:52
@fifield fifield requested a review from Copilot December 17, 2025 00:18
Copy link
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

Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.


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

fifield and others added 16 commits January 5, 2026 14:36
- Renamed trace_events_enum.py to trace_events package with per-architecture modules
- Changed from single file to package: aie.utils.trace_events.{aie,aie2,aie2p}
- Renamed PLEvent to ShimTileEvent to match expected usage
- Generate files during build into build/regdb/ directory instead of manually generating
- Copy generated files to Python package directory during build
- Install generated files along with checked-in __init__.py
- Update all imports to use new package structure
- Conditionally emit UCEvent enum only when events are defined (e.g. aie2ps in future)
- Emit unified events.json into build/regdb for compiler ingest (for future work)
- Map aieml architecture to aie2 for Python module naming

Fill enum value gaps with reserved placeholders

The generator now fills gaps in enum values with rsvd_XX placeholders
to ensure continuous numbering from min to max value. This matches the
behavior of the original manually-generated file and ensures that all
hardware event codes are represented in the enum, even if they are
reserved or undefined.

Example: If events 0-53 and 55-127 are defined, value 54 gets
placeholder rsvd_54 to maintain continuity.

Fixes comparison with original trace_events_enum.py file.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: fifield <800843+fifield@users.noreply.github.com>
Co-authored-by: Jeff Fifield <jeff.fifield@amd.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
- Add generate_events_tablegen.py to create TableGen enum definitions
  from aie-rt event headers
- Update AIE dialect CMakeLists to generate AIEEvents*.td.inc files
  during build process
- Include generated event enums in AIEAttrs.td
- Add proper CMake dependencies to ensure enums are generated before
  they are needed by tablegen

This allows the AIE dialect to emit C++ enum classes for all event
types (CoreEvent, MemEvent, ShimTileEvent, MemTileEvent) across all
AIE architectures (AIE, AIE2, AIE2P).
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@fifield fifield added this pull request to the merge queue Jan 5, 2026
Merged via the queue into main with commit 4e1f699 Jan 5, 2026
60 checks passed
@fifield fifield deleted the events_enum branch January 5, 2026 23:48
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.

7 participants