-
Notifications
You must be signed in to change notification settings - Fork 53
gemm: check tile sizes against the kernel's divisibility rule, not a bound #189
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
+89
−8
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
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,69 @@ | ||
| #!/usr/bin/env python3 | ||
| # SPDX-FileCopyrightText: Copyright (C) 2026 Advanced Micro Devices, Inc. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """GEMM.__post_init__ must reject tile sizes the kernel cannot build. | ||
|
|
||
| aie_kernels/aie2p/mm.cc's matmul_vectorized_*x*x*_bf16_* wrappers static_assert | ||
| m % (2*r) == 0, k % s == 0 and n % (2*t) == 0 for the (r, s, t) triple selected | ||
| by emulate_bf16_mmul_with_bfp16 (r=t=8 when enabled, the default; r=4, t=8 | ||
| otherwise). A tile size that meets a lower bound without dividing evenly | ||
| constructs here without error and then fails that static_assert at kernel | ||
| compile time, from a file this class never names. | ||
| """ | ||
|
|
||
| import pytest | ||
|
|
||
| from iron.operators.gemm.op import GEMM | ||
|
|
||
|
|
||
| def _construct(tile_m=64, tile_k=64, tile_n=64, emulate_bf16_mmul_with_bfp16=True): | ||
| return GEMM( | ||
| M=512, | ||
| K=512, | ||
| N=512, | ||
| tile_m=tile_m, | ||
| tile_k=tile_k, | ||
| tile_n=tile_n, | ||
| emulate_bf16_mmul_with_bfp16=emulate_bf16_mmul_with_bfp16, | ||
| context=None, | ||
| ) | ||
|
|
||
|
|
||
| def test_tile_m_not_a_multiple_of_16_is_rejected_under_emulation(): | ||
| """mm.cc needs m % 16 == 0 under the default emulate_bf16_mmul_with_bfp16 | ||
| (r=8), which tile_m=8 satisfies as a bound but not as a divisor.""" | ||
| with pytest.raises(ValueError, match="tile_m .* multiple of 16"): | ||
| _construct(tile_m=8) | ||
|
|
||
|
|
||
| def test_tile_m_multiple_of_16_is_accepted_under_emulation(): | ||
| _construct(tile_m=16) | ||
| _construct(tile_m=64) | ||
|
|
||
|
|
||
| def test_tile_m_multiple_of_8_is_accepted_without_emulation(): | ||
| """r=4 without emulation, so the requirement relaxes to a multiple of 8.""" | ||
| _construct(tile_m=8, emulate_bf16_mmul_with_bfp16=False) | ||
|
|
||
|
|
||
| def test_tile_n_not_a_multiple_of_16_is_rejected_regardless_of_emulation(): | ||
| """t=8 for both emulation settings, so n % 16 == 0 always.""" | ||
| with pytest.raises(ValueError, match="tile_n .* multiple of 16"): | ||
| _construct(tile_n=8, emulate_bf16_mmul_with_bfp16=False) | ||
| with pytest.raises(ValueError, match="tile_n .* multiple of 16"): | ||
| _construct(tile_n=8, emulate_bf16_mmul_with_bfp16=True) | ||
|
|
||
|
|
||
| def test_tile_m_not_a_multiple_of_8_is_rejected_without_emulation(): | ||
| """mm.cc needs m % 8 == 0 without emulation (r=4), which tile_m=4 | ||
| satisfies as a bound but not as a divisor.""" | ||
| with pytest.raises(ValueError, match="tile_m .* multiple of 8"): | ||
| _construct(tile_m=4, emulate_bf16_mmul_with_bfp16=False) | ||
|
|
||
|
|
||
| def test_tile_k_not_a_multiple_of_8_is_rejected(): | ||
| # tile_k=4 still divides K=512 evenly (the outer K % tile_k check), so | ||
| # this exercises the s-divisibility check rather than that one. | ||
| with pytest.raises(ValueError, match="tile_k .* multiple of 8"): | ||
| _construct(tile_k=4) | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we please stop documenting code changes in comments?