-
Notifications
You must be signed in to change notification settings - Fork 46
operators: emit trace configuration when trace_size is set #142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
atassis
wants to merge
3
commits into
amd:devel
Choose a base branch
from
atassis:feat/iron-trace-parity-devel
base: devel
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| # SPDX-FileCopyrightText: Copyright (C) 2026 Advanced Micro Devices, Inc. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """Shared per-op NPU hardware-trace wiring for the iron/operators designs. | ||
|
|
||
| Semantics: | ||
| * explicit ``trace_size`` wins; otherwise fall back to ``IRON_TRACE_SIZE`` | ||
| * ``IRON_TRACE_NTILES`` (default 1) caps how many workers get traced; 0 traces none | ||
| * no-op when neither is set, so production paths are unaffected | ||
| """ | ||
|
|
||
| import os | ||
|
|
||
| __all__ = ["maybe_enable_trace", "resolve_trace_size"] | ||
|
|
||
|
|
||
| def resolve_trace_size(trace_size=None): | ||
| """Effective trace size: explicit argument first, then ``IRON_TRACE_SIZE``, else 0.""" | ||
| if trace_size and trace_size > 0: | ||
| return int(trace_size) | ||
| # Deliberately unguarded: a malformed IRON_TRACE_SIZE should raise rather than | ||
| # silently disable tracing. | ||
| return int(os.environ.get("IRON_TRACE_SIZE", "0")) | ||
|
|
||
|
|
||
| def _default_coretile_events(): | ||
| import aie.utils.trace as trace_utils | ||
|
|
||
| ev = trace_utils.events | ||
| return [ | ||
| ev.PortEvent(ev.CoreEvent.PORT_RUNNING_0, ev.WireBundle.DMA, 0, True), | ||
| ev.PortEvent(ev.CoreEvent.PORT_RUNNING_1, ev.WireBundle.DMA, 1, True), | ||
| ev.PortEvent(ev.CoreEvent.PORT_RUNNING_2, ev.WireBundle.DMA, 0, False), | ||
| ev.CoreEvent.INSTR_EVENT_0, | ||
| ev.CoreEvent.INSTR_EVENT_1, | ||
| ev.CoreEvent.MEMORY_STALL, | ||
| ev.CoreEvent.LOCK_STALL, | ||
| ev.CoreEvent.INSTR_VECTOR, | ||
| ] | ||
|
|
||
|
|
||
| def maybe_enable_trace(rt, trace_size, workers, coretile_events=None): | ||
| """Configure per-op hardware trace on ``rt`` if tracing is requested. | ||
|
|
||
| Call inside the ``rt.sequence(...)`` block, before ``rt.start(...)``. | ||
|
|
||
| Args: | ||
| rt: the ``Runtime`` being built. | ||
| trace_size: the design's ``trace_size`` argument (may be None/0). | ||
| workers: the design's workers; the first ``IRON_TRACE_NTILES`` are traced. | ||
| coretile_events: override the default core-tile event set. | ||
|
|
||
| Returns: | ||
| The effective trace size (0 when tracing is off and nothing was configured). | ||
| """ | ||
| ts = resolve_trace_size(trace_size) | ||
| if ts <= 0: | ||
| return 0 | ||
|
|
||
| # A count, so 0 legitimately means "trace no tiles"; only negatives are | ||
| # meaningless (a negative slice index would silently drop the LAST worker). | ||
| ntiles = max(0, int(os.environ.get("IRON_TRACE_NTILES", "1"))) | ||
|
|
||
| rt.enable_trace( | ||
| ts, | ||
| workers=list(workers)[:ntiles], | ||
| coretile_events=( | ||
| coretile_events | ||
| if coretile_events is not None | ||
| else _default_coretile_events() | ||
| ), | ||
| ) | ||
| return ts | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.