gpu-compute: stop decoding instructions after stopFetch - #1
Open
Basemism wants to merge 1 commit into
Open
Conversation
Honor Wavefront::stopFetch() before decoding either a split instruction or additional instructions from the fetch buffer. This prevents the decoder from continuing to populate the instruction buffer after the wavefront has entered a state that blocks further fetch and decode work.
There was a problem hiding this comment.
🔵 Needs a closer look
The new stopFetch() usage in the while condition can introduce avoidable O(n²) behavior in a hot decode loop due to repeated full scans of the instruction buffer.
Pull request overview
This PR fixes a GPU fetch/decode boundary bug in the shader instruction fetch unit: once a wavefront has buffered a control-flow/end-of-kernel instruction (e.g., s_endpgm), decoding now stops immediately instead of continuing to consume already-fetched bytes and populating the instruction buffer with instructions that should never execute.
Changes:
- Gate
FetchBufDesc::decodeInsts()so it does not decode split or subsequent instructions afterWavefront::stopFetch()becomes true. - Prevent decoding of post-
s_endpgmbytes that can incorrectly map operands and trigger false panics.
File summaries
| File | Description |
|---|---|
src/gpu-compute/fetch_unit.cc |
Stops decode from consuming buffered bytes past branch/return/end-of-kernel boundaries by honoring Wavefront::stopFetch() during decode. |
Review details
Suppressed comments (1)
src/gpu-compute/fetch_unit.cc:597
wavefront->stopFetch()is an O(n) scan overinstructionBuffer(seeWavefront::stopFetch()), and calling it in thewhilecondition can makedecodeInsts()potentially O(n^2) per buffer fill (one full scan per decoded instruction). You can keep the same correctness behavior while avoiding repeated scans by checkingstopFetch()once up-front, then breaking based on the newly-decoded instruction being a branch/return/end-of-kernel.
hasFetchDataToProcess() && !wavefront->stopFetch()) {
if (splitDecode()) {
decodeSplitInst();
} else {
TheGpuISA::MachInst mach_inst =
- Files reviewed: 1/1 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fetch has two steps: request/cache instruction bytes, then decode buffered bytes into the wavefront instruction buffer.
Wavefront::stopFetch()already treated branches, returns, ands_endpgmas boundaries, butdecodeInsts()checked itonly when scheduling future fetch requests. Its inner loop continued consuming bytes already buffered after a boundary.
When
s_endpgmand following bytes occupied the same fetched region, gem5 decoded those following bytes under the ending kernel's wavefront. Constructing the following instruction immediately mapped its operands against that kernel'svalid reservation and produced a false panic. The instruction would never have executed:
s_endpgmerases later buffered instructions and terminates the wave.Fix:
Honor
Wavefront::stopFetch()before decoding either a split instruction or additional instructions from the fetch buffer. This prevents the decoder from continuing to populate the instruction buffer after the wavefront has entered a state that blocks further fetch and decode work.