Repository navigation
feat: [rocjitsu] Adding EXEC state tracking for liveness #7470
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 6 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
2470f72
[rocjitsu] Add EXEC state tracking for liveness (PR #7470)
theSK2005 2c5125b
adjusted pytests that were failing after merge
theSK2005 293c1d7
fixed exec state tracking distinguishing between exec_lo vs exec_hi
theSK2005 073ed47
addressed Jakub's comments, exec_hi badly narrowing on Wave32 and som…
theSK2005 ec96c3f
pre-commit fix
theSK2005 4d297fa
fixing liveness_test after rebase
theSK2005 d73c1b3
addressed Tony's comments, allow kernel entry to be an explicit param…
theSK2005 947a147
handing kernel entries to BasicBlock::build so that kernel entries al…
theSK2005 6d51887
passing kernarg_preload_firmware_entry_text_offset as a kernel entry …
theSK2005 18f9271
Merge remote-tracking branch 'origin/develop' into users/skushwah/exe…
theSK2005 01ceed3
addrsesed Jakub's comments, regression test fails instead of skips, e…
theSK2005 0c4d924
add translate() preload fixture that shows firmware-entry vector def …
theSK2005 9831e5b
Merge remote-tracking branch 'origin/develop' into users/skushwah/exe…
theSK2005 4846f99
pre-commit fix
theSK2005 8a28f62
Merge branch 'develop' into users/skushwah/exec-def-kill
theSK2005 513c4f8
Merge branch 'develop' into users/skushwah/exec-def-kill
theSK2005 df118ed
made EXEC state tracking toggleable
theSK2005 206d791
added EXEC state optimizations and clarified what is preventing DBT f…
theSK2005 6db4ad7
added reference to github issue
theSK2005 f7d6397
pre-commit fixes
theSK2005 4cc3f37
added Jakub's perf improvements
theSK2005 fb2e77a
Merge branch 'develop' into users/skushwah/exec-def-kill
theSK2005 0370672
Merge branch 'develop' into users/skushwah/exec-def-kill
theSK2005 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
471 changes: 183 additions & 288 deletions
471
emulation/rocjitsu/lib/python/amdisa/codegen/_generator.py
Large diffs are not rendered by default.
Oops, something went wrong.
180 changes: 180 additions & 0 deletions
180
emulation/rocjitsu/lib/python/amdisa/tests/test_exec_mask_flags.py
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,180 @@ | ||
| # Copyright (c) 2025-2026 Advanced Micro Devices, Inc. | ||
| # SPDX-License-Identifier: MIT | ||
|
|
||
| """Tests for EXEC-mask instruction flag emission.""" | ||
|
|
||
| import pytest | ||
|
|
||
| from amdisa.codegen._generator import ( | ||
| _exec_mask_flag_stmts, | ||
| _result_combinator_flag_stmts, | ||
| ) | ||
| from amdisa.semantics import InstructionSemantics | ||
|
|
||
| # Flag names emitted for EXEC tracking. | ||
| ALL = {'IGNORES_EXEC', 'WRITES_EXEC'} | ||
|
|
||
|
|
||
| def _flags(sem): | ||
| """Run the generator helper and return the set of emitted flag names.""" | ||
| return {s[len('flags_ |= ') : -1] for s in _exec_mask_flag_stmts(sem)} | ||
|
|
||
|
|
||
| # (InstructionSemantics, expected-present flags, id). Anything in ALL but not in | ||
| # the expected set must be ABSENT — see the test below. | ||
| _CASES = [ | ||
| # Scalar EXEC writers: write EXEC, but are not themselves EXEC-masked. | ||
| pytest.param( | ||
| InstructionSemantics( | ||
| 'S_AND_SAVEEXEC_B64', | ||
| 'scalar_saveexec', | ||
| operation='and', | ||
| data_type='b64', | ||
| sets_scc='nonzero', | ||
| ), | ||
| {'WRITES_EXEC'}, | ||
| id='scalar_saveexec', | ||
| ), | ||
| pytest.param( | ||
| InstructionSemantics( | ||
| 'S_ANDN2_WREXEC_B64', | ||
| 'scalar_wrexec', | ||
| operation='andn2', | ||
| data_type='b64', | ||
| sets_scc='nonzero', | ||
| ), | ||
| {'WRITES_EXEC'}, | ||
| id='scalar_wrexec', | ||
| ), | ||
| # Vector ALU: no EXEC interaction flags. | ||
| pytest.param( | ||
| InstructionSemantics( | ||
| 'V_ADD_F32', 'vector_binop', operation='add', data_type='f32' | ||
| ), | ||
| set(), | ||
| id='vector_binop', | ||
| ), | ||
| pytest.param( | ||
| InstructionSemantics('V_MOV_B32', 'vector_mov', data_type='b32'), | ||
| set(), | ||
| id='vector_mov', | ||
| ), | ||
| pytest.param( | ||
| InstructionSemantics('V_CNDMASK_B32', 'vector_cndmask', data_type='b32'), | ||
| set(), | ||
| id='vector_cndmask', | ||
| ), | ||
| # Vector compare-and-set-exec: writes EXEC. | ||
| pytest.param( | ||
| InstructionSemantics( | ||
| 'V_CMPX_LT_F32', 'vector_cmpx', operation='lt', data_type='f32' | ||
| ), | ||
| {'WRITES_EXEC'}, | ||
| id='vector_cmpx', | ||
| ), | ||
| # Branches: ignore EXEC, never EXEC-masked. | ||
| pytest.param( | ||
| InstructionSemantics('S_BRANCH', 'branch'), | ||
| {'IGNORES_EXEC'}, | ||
| id='branch', | ||
| ), | ||
| pytest.param( | ||
| InstructionSemantics('S_CBRANCH_SCC1', 'cbranch', branch_condition='scc1'), | ||
| {'IGNORES_EXEC'}, | ||
| id='cbranch', | ||
| ), | ||
| # Plain scalar op: no EXEC interaction at all. | ||
| pytest.param( | ||
| InstructionSemantics('S_MOV_B32', 'scalar_mov', data_type='b32'), | ||
| set(), | ||
| id='scalar_mov', | ||
| ), | ||
| ] | ||
|
|
||
|
|
||
| class TestExecMaskFlagStmts: | ||
| def test_none_semantics_yields_no_flags(self): | ||
| assert _exec_mask_flag_stmts(None) == [] | ||
|
|
||
| def test_unsupported_class_yields_no_flags(self): | ||
| # A semantic class with no registered deriver -> derive_sema_block | ||
| # returns None -> conservatively no flags. | ||
| sem = InstructionSemantics('NOT_A_REAL_INST', 'no_such_class') | ||
| assert _exec_mask_flag_stmts(sem) == [] | ||
|
|
||
| @pytest.mark.parametrize('sem, expected', _CASES) | ||
| def test_flags_per_instruction_kind(self, sem, expected): | ||
| flags = _flags(sem) | ||
| assert expected <= flags, f'{sem.name}: missing {expected - flags}' | ||
| unexpected = (ALL - expected) & flags | ||
| assert not unexpected, f'{sem.name}: unexpected {unexpected}' | ||
|
|
||
| def test_flag_statement_format(self): | ||
| sem = InstructionSemantics( | ||
| 'S_OR_SAVEEXEC_B64', | ||
| 'scalar_saveexec', | ||
| operation='or', | ||
| data_type='b64', | ||
| sets_scc='nonzero', | ||
| ) | ||
| stmts = _exec_mask_flag_stmts(sem) | ||
| assert stmts | ||
| for s in stmts: | ||
| assert s.startswith('flags_ |= ') | ||
| assert s.endswith(';') | ||
|
|
||
|
|
||
| class TestResultCombinatorFlagStmts: | ||
| """RESULT_COPY / RESULT_OR drive EXEC-state all-ones reasoning.""" | ||
|
|
||
| def _combinator(self, sem): | ||
| return {s[len('flags_ |= ') : -1] for s in _result_combinator_flag_stmts(sem)} | ||
|
|
||
| def test_scalar_mov_is_copy(self): | ||
| sem = InstructionSemantics('S_MOV_B64', 'scalar_mov', data_type='b64') | ||
| assert self._combinator(sem) == {'RESULT_COPY'} | ||
|
|
||
| def test_binop_or_is_or(self): | ||
| sem = InstructionSemantics( | ||
| 'S_OR_B64', 'scalar_binop', operation='or', data_type='b64' | ||
| ) | ||
| assert self._combinator(sem) == {'RESULT_OR'} | ||
|
|
||
| def test_saveexec_or_is_or(self): | ||
| sem = InstructionSemantics( | ||
| 'S_OR_SAVEEXEC_B64', 'scalar_saveexec', operation='or', data_type='b64' | ||
| ) | ||
| assert self._combinator(sem) == {'RESULT_OR'} | ||
|
|
||
| def test_saveexec_and_is_other(self): | ||
| # exec = exec & src -> not provably all-ones; no combinator flag. | ||
| sem = InstructionSemantics( | ||
| 'S_AND_SAVEEXEC_B64', 'scalar_saveexec', operation='and', data_type='b64' | ||
| ) | ||
| assert _result_combinator_flag_stmts(sem) == [] | ||
|
|
||
| def test_binop_and_is_other(self): | ||
| sem = InstructionSemantics( | ||
| 'S_AND_B64', 'scalar_binop', operation='and', data_type='b64' | ||
| ) | ||
| assert _result_combinator_flag_stmts(sem) == [] | ||
|
|
||
| def test_vector_mov_is_not_copy(self): | ||
| # RESULT_COPY is scalar-only; a vector mov must not emit it. | ||
| sem = InstructionSemantics('V_MOV_B32', 'vector_mov', data_type='b32') | ||
| assert _result_combinator_flag_stmts(sem) == [] | ||
|
|
||
| def test_vector_binop_or_is_not_or(self): | ||
| # RESULT_OR is scalar-only; a vector bitwise-or must not emit it. | ||
| sem = InstructionSemantics( | ||
| 'V_OR_B32', 'vector_binop', operation='or', data_type='b32' | ||
| ) | ||
| assert _result_combinator_flag_stmts(sem) == [] | ||
|
|
||
| def test_vector_cndmask_is_not_copy(self): | ||
| # A non-scalar select is not a plain copy. | ||
| sem = InstructionSemantics('V_CNDMASK_B32', 'vector_cndmask', data_type='b32') | ||
| assert _result_combinator_flag_stmts(sem) == [] | ||
|
|
||
| def test_none_is_empty(self): | ||
| assert _result_combinator_flag_stmts(None) == [] | ||
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.
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.