-
Notifications
You must be signed in to change notification settings - Fork 32
GEMM support in waveasm LLVM path #1288
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
Open
Hardcode84
wants to merge
19
commits into
iree-org:main
Choose a base branch
from
Hardcode84:llvm-asm-backend-gemm-v2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
40eacb8
Fix emit_host_func stride arg mismatch and add wave_get_stride runtim…
Hardcode84 80add6d
Add GEMM op handlers to LLVM->WaveASM translation
Hardcode84 69f565a
Add lit tests for GEMM-related LLVM->WaveASM handlers
Hardcode84 7b864b2
Propagate correct register widths in LLVM->WaveASM translation
Hardcode84 78b1175
Restrict GEMM waveasm test to CDNA4
Hardcode84 05835d4
Drop isLDSBase tracking, check LLVM pointer address space directly
Hardcode84 71f2692
Remove incorrect multi-index GEP offset accumulation
Hardcode84 c36e56c
Fix computeGEPOffset: account for element type size, use proper types
Hardcode84 5145ebc
Add lit tests for unsupported GEP configurations
Hardcode84 593790f
Fix LLVM->WaveASM edge-case lowering semantics
Hardcode84 000a3ea
Tighten LLVM->WaveASM GEP byte-size handling
Hardcode84 ea6948a
Make LLVM->WaveASM translator types explicit
Hardcode84 86ff7ad
unicode
Hardcode84 4fbfae1
Harden WaveASM lowering and ABI handling
Hardcode84 4d11a22
cleanups
Hardcode84 6657aa1
cleanup
Hardcode84 7bcc50f
llvm::seq
Hardcode84 89a110b
cleanup
Hardcode84 aec6903
Fix SALU bitwise immediate operand ordering
Hardcode84 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,64 @@ | ||
| # Copyright 2026 The Wave Authors | ||
| # | ||
| # Licensed under the Apache License v2.0 with LLVM Exceptions. | ||
| # See https://llvm.org/LICENSE.txt for license information. | ||
| # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| """GEMM through the water+waveasm pipeline (LLVM dialect -> WaveASM -> binary).""" | ||
|
|
||
| import pytest | ||
| import torch | ||
| from torch.testing import assert_close | ||
|
|
||
| from wave_lang.kernel.wave.compile import WaveCompileOptions, wave_compile | ||
| from wave_lang.kernel.wave.constraints import MMAType | ||
| from wave_lang.kernel.wave.templates.gemm import get_gemm_kernel | ||
| from wave_lang.kernel.wave.utils.run_utils import set_default_run_config | ||
| from wave_lang.kernel.wave.utils.torch_utils import device_randn, device_zeros | ||
|
|
||
| from ..common.utils import require_cdna4, require_e2e | ||
|
|
||
|
|
||
| @require_e2e | ||
| @require_cdna4 | ||
| @pytest.mark.parametrize( | ||
| "shape,block_shape,waves_per_block", | ||
| [ | ||
| ((64, 64, 64), (32, 32, 16), (1, 1)), | ||
| ], | ||
| ids=["64x64x64"], | ||
| ) | ||
| def test_gemm_water_waveasm( | ||
| shape: tuple[int, int, int], | ||
| block_shape: tuple[int, int, int], | ||
| waves_per_block: tuple[int, int], | ||
| ) -> None: | ||
| """Test GEMM through the water+waveasm pipeline.""" | ||
| m, n, k = shape | ||
|
|
||
| gemm, hyperparams, _ = get_gemm_kernel( | ||
| shape=shape, | ||
| dynamic_dims=False, | ||
| mfma_variant=MMAType.F32_16x16x16_F16, | ||
| block_shape=block_shape, | ||
| waves_per_block=waves_per_block, | ||
| ) | ||
|
|
||
| options = WaveCompileOptions( | ||
| subs=hyperparams, | ||
| canonicalize=True, | ||
| use_water_backend=True, | ||
| use_buffer_ops=True, | ||
| backend="asm", | ||
| wave_runtime=True, | ||
| ) | ||
| options = set_default_run_config(options) | ||
| compiled = wave_compile(options, gemm) | ||
|
|
||
| a = device_randn((m, k), dtype=torch.float16) | ||
| b = device_randn((n, k), dtype=torch.float16) | ||
| c = device_zeros((m, n), dtype=torch.float32) | ||
| compiled(a, b, c) | ||
|
|
||
| expected = torch.matmul(a, b.T).float() | ||
| assert_close(c, expected, rtol=1e-3, atol=1e-3) |
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.
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.
Should we just pass it as i32 and not bother with index?
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.
We can, probably, but it will require more changes across the codebase (
StreamExecutable.define_entrypointand other places), lets keep it as index for now.