-
Notifications
You must be signed in to change notification settings - Fork 8
Kernel overlap verification stage, initial version #124
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ffcc5ba
allow a derived overlap class to override and record detailed warning…
lasch f0ddfeb
parameterize the event keys used to group events for overlap detection
lasch c831e9c
implementation of kernel-overlap verification stage
lasch 029c074
move overlap verification into its own file
lasch d58e8ab
move verification imports to their own __init__.py
lasch f939cd7
implement strict-mode to detect fn-call-type overlaps
lasch c3900e0
adding missing __init__.py file
lasch 2c1890e
Merge branch 'main' into overlap_verify
lasch 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,10 @@ | ||
| { | ||
| "stages": [ | ||
| {"sort_events": true}, | ||
| {"verify_kernel_overlap": true}, | ||
| {"kernel_parent_collect": true}, | ||
| {"pipeline_barrier": true}, | ||
| {"kernel_parent_verify": true}, | ||
| {"verify_cleanup": true}, | ||
| {"verification_result_filter": true} | ||
| ] | ||
| } |
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,28 @@ | ||
| # Copyright 2024-2026 IBM Corporation | ||
|
|
||
| ''' | ||
| Verification pipeline stages and contexts. | ||
|
|
||
| The stages of the verification pipeline are collected here, separate from the regular processing | ||
| pipeline of aiu_trace_analyzer.pipeline. The dependency between the two is one-directional: | ||
| verification stages build on the pipeline infrastructure (contexts, detection algorithms), the | ||
| regular pipeline never imports anything from here. | ||
|
|
||
| A verification stage consists of a context derived from AbstractVerificationContext (which emits | ||
| the accumulated findings as verification meta-data events at drain time) plus one or more callback | ||
| functions. For a minimal example of both, see verify.py. | ||
| ''' | ||
|
|
||
| # import the verification contexts: | ||
| from aiu_trace_analyzer.verification.verify import VerificationContext | ||
| from aiu_trace_analyzer.verification.kernel_parent_verify import KernelParentVerificationContext | ||
| from aiu_trace_analyzer.verification.overlap_verify import OverlapVerificationContext | ||
|
|
||
| # import the verification stage callbacks: | ||
| from aiu_trace_analyzer.verification.verify import verify, verify_cleanup | ||
| from aiu_trace_analyzer.verification.kernel_parent_verify import ( | ||
| kernel_parent_collect, | ||
| kernel_parent_verify | ||
| ) | ||
| from aiu_trace_analyzer.verification.overlap_verify import verify_kernel_overlap | ||
| from aiu_trace_analyzer.verification.report import verification_result_filter |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| # Copyright 2024-2026 IBM Corporation | ||
|
|
||
| """ | ||
| Overlap verification for accelerator compute events. | ||
|
|
||
| Compute events of the same stream cannot overlap in time: the stream processes them one after | ||
| another. Any detected overlap therefore indicates a data problem (e.g. inaccurate timestamps) | ||
| and is reported as an error-level finding of the verification report. | ||
|
|
||
| This module reuses the overlap detection of the regular processing pipeline | ||
| (OverlapDetectionContext) and only replaces the parts that differ in verification mode: | ||
| * overlaps are reported, never resolved | ||
| * the finding is error-level and records each offending event as an instance | ||
| * the streams are identified per input dialect instead of by pid+tid | ||
| """ | ||
|
|
||
| from aiu_trace_analyzer.types import TraceEvent, TraceWarning | ||
| from aiu_trace_analyzer.pipeline.context import AbstractContext, AbstractVerificationContext | ||
| from aiu_trace_analyzer.pipeline.overlap import OverlapDetectionContext | ||
| from aiu_trace_analyzer.pipeline.tools import PipelineContextTool | ||
|
|
||
|
|
||
| class OverlapVerificationContext(OverlapDetectionContext, AbstractVerificationContext): | ||
| ''' | ||
| Verification-mode variant of the overlap detection: it only reports overlapping compute | ||
| events, it never resolves them (always OVERLAP_RESOLVE_WARN). Every detected overlap is | ||
| recorded as an instance of an error-level finding and the accumulated findings are emitted | ||
| as verification meta-data events by AbstractVerificationContext.drain() (reached via the MRO, | ||
| the parent drain chains up to it; no two-phase barrier required for this context). | ||
|
|
||
| Compute streams are identified per dialect: FLEX events have a single stream per pid, while | ||
| TORCH events separate the streams within a pid by their 'args.stream' entry. | ||
| ''' | ||
| test_name = "Compute Overlap Check" | ||
|
|
||
| _OVERLAP_WARNING = "overlaps" | ||
| _STREAM_KEY = "stream" | ||
| _STREAM_ARG = "args." + _STREAM_KEY | ||
| _DEFAULT_STREAM = 0 # convention: actual stream numbers start at 1, 0 means 'no stream entry' | ||
|
ppnaik1890 marked this conversation as resolved.
|
||
|
|
||
| def __init__(self, strict=False) -> None: | ||
| super().__init__(self.OVERLAP_RESOLVE_WARN, strict=strict) | ||
| # replace the resolution-oriented warning of the parent: in verification mode nothing is | ||
| # resolved, a detected overlap is a finding that has to fail the test | ||
| self.add_warning( | ||
| TraceWarning( | ||
| name=self._OVERLAP_WARNING, | ||
| text="Overlapping accelerator events detected: {d[count]}", | ||
| data={"count": 0}, | ||
| is_error=True, | ||
| ) | ||
| ) | ||
|
|
||
| def _select_queue_id_keys(self, event: TraceEvent) -> list[str]: | ||
| dialect = PipelineContextTool.get_dialect_of_event(event) | ||
| assert dialect is not None, \ | ||
| "OVL: cannot determine the dialect of the first event." \ | ||
| " Register this stage before any stage that removes the jobhash." | ||
| if dialect.get("NAME") == "TORCH": | ||
| return ["pid", self._STREAM_ARG] | ||
| return ["pid"] | ||
|
|
||
| def _record_overlap(self, oevent: TraceEvent) -> None: | ||
| super()._record_overlap(oevent) | ||
| self.warnings[self._OVERLAP_WARNING].add_instance({ | ||
| "name": oevent["name"], | ||
| "pid": oevent["pid"], | ||
| "tid": oevent["tid"], | ||
| "stream": oevent["args"].get(self._STREAM_KEY), | ||
| "ts": oevent["ts"], | ||
| "dur": oevent["dur"], | ||
| }) | ||
|
|
||
| def add_default_stream(self, event: TraceEvent) -> bool: | ||
| ''' | ||
| the stream-based separation of queues requires the stream entry to exist. Events without | ||
| one are all attributed to the same default stream. Returns whether a default was added. | ||
| ''' | ||
| if self._STREAM_KEY in event["args"]: | ||
| return False | ||
| event["args"][self._STREAM_KEY] = self._DEFAULT_STREAM | ||
| return True | ||
|
|
||
| def remove_default_stream(self, event: TraceEvent) -> None: | ||
| del event["args"][self._STREAM_KEY] | ||
|
|
||
|
|
||
| def verify_kernel_overlap(event: TraceEvent, context: AbstractContext) -> list[TraceEvent]: | ||
| assert isinstance(context, OverlapVerificationContext) | ||
|
|
||
| # only compute events are checked; anything else just passes through | ||
| if event["ph"] not in "X" or not PipelineContextTool.is_acc_event(event): | ||
| return [event] | ||
|
|
||
| # the default is only required to determine the queue/stream of this event: drop it again to | ||
| # keep the event unchanged for any downstream stage | ||
| default_added = context.add_default_stream(event) | ||
| revents = context.overlap_detection(event) | ||
| if default_added: | ||
| context.remove_default_stream(event) | ||
| return revents | ||
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.