-
Notifications
You must be signed in to change notification settings - Fork 99
[ROCDL] Add arch-aware universal s_waitcnt #915
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
3 commits
Select commit
Hold shift + click to select a range
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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # Copyright (c) 2026 FlyDSL Project Contributors | ||
|
|
||
| from ..._mlir.dialects import rocdl as mlir_rocdl | ||
| from .utils import normalize_s_waitcnt_field | ||
|
|
||
|
|
||
| def s_waitcnt(vmcnt=None, lgkmcnt=None, expcnt=None): | ||
| """ | ||
| Emit a CDNA3/GFX942-encoded s_waitcnt operation. | ||
|
|
||
| vmcnt: split across [3:0] and [15:14] | ||
| expcnt: [6:4] | ||
| lgkmcnt: [11:8] | ||
| """ | ||
| vmcnt = normalize_s_waitcnt_field("vmcnt", vmcnt, 63) | ||
| expcnt = normalize_s_waitcnt_field("expcnt", expcnt, 7) | ||
| lgkmcnt = normalize_s_waitcnt_field("lgkmcnt", lgkmcnt, 15) | ||
| encoded_vmcnt = (vmcnt & 0xF) | ((vmcnt & 0x30) << 10) | ||
| return mlir_rocdl.s_waitcnt(encoded_vmcnt | (lgkmcnt << 8) | (expcnt << 4)) |
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,20 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # Copyright (c) 2026 FlyDSL Project Contributors | ||
|
|
||
| from ..._mlir.dialects import rocdl as mlir_rocdl | ||
| from .utils import normalize_s_waitcnt_field | ||
|
|
||
|
|
||
| def s_waitcnt(vmcnt=None, lgkmcnt=None, expcnt=None): | ||
| """ | ||
| Emit a RDNA3/GFX11-encoded s_waitcnt operation. | ||
|
|
||
| expcnt: [2:0] | ||
| unused: [3:3] | ||
| lgkmcnt: [9:4] | ||
| vmcnt: [15:10] | ||
| """ | ||
| vmcnt = normalize_s_waitcnt_field("vmcnt", vmcnt, 63) | ||
| lgkmcnt = normalize_s_waitcnt_field("lgkmcnt", lgkmcnt, 63) | ||
| expcnt = normalize_s_waitcnt_field("expcnt", expcnt, 7) | ||
| return mlir_rocdl.s_waitcnt((vmcnt << 10) | (lgkmcnt << 4) | expcnt) |
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,18 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # Copyright (c) 2026 FlyDSL Project Contributors | ||
|
|
||
| from ..._mlir.dialects import rocdl as mlir_rocdl | ||
| from .utils import normalize_s_waitcnt_field | ||
|
|
||
|
|
||
| def s_waitcnt(vmcnt=None, lgkmcnt=None, expcnt=None): | ||
| """Emit a RDNA4/GFX120-encoded s_waitcnt operation. | ||
|
|
||
| expcnt: [2:0] | ||
| lgkmcnt: [9:4] | ||
| vmcnt: [15:10] | ||
| """ | ||
| vmcnt = normalize_s_waitcnt_field("vmcnt", vmcnt, 63) | ||
| lgkmcnt = normalize_s_waitcnt_field("lgkmcnt", lgkmcnt, 63) | ||
| expcnt = normalize_s_waitcnt_field("expcnt", expcnt, 7) | ||
| return mlir_rocdl.s_waitcnt(vmcnt << 10 | lgkmcnt << 4 | expcnt) |
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,31 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # Copyright (c) 2026 FlyDSL Project Contributors | ||
|
|
||
| from ..numeric import Numeric | ||
|
|
||
|
|
||
| def normalize_s_waitcnt_field(name, value, maximum): | ||
| """Coerce a wait-counter argument to a static Python ``int``. | ||
|
|
||
| ``None`` means "do not wait on this counter" and maps to ``maximum``, | ||
| which is the encoding the hardware reads as "already satisfied". | ||
|
|
||
| Wait counters are encoded into an instruction's immediate field, so the | ||
| value has to be known at compile time; a run-time ``Integer`` is rejected | ||
| rather than silently materialised as a constant. | ||
| """ | ||
| if value is None: | ||
| return maximum | ||
|
|
||
| if isinstance(value, Numeric): | ||
| if not value.is_static(): | ||
| raise TypeError(f"{name} must be a static Python int or Integer, got a run-time value") | ||
| value = value.value | ||
|
|
||
| if not isinstance(value, int): | ||
| raise TypeError(f"{name} must be a static Python int or Integer, got {type(value).__name__}") | ||
|
|
||
| if not 0 <= value <= maximum: | ||
| raise ValueError(f"{name} must be in [0, {maximum}] on this target, got {value}") | ||
|
|
||
| return int(value) |
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.