-
Notifications
You must be signed in to change notification settings - Fork 17
Refactor 08_gemm_atomics_all_reduce example with reusable function and simplified pytest #132
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
Copilot
wants to merge
6
commits into
main
Choose a base branch
from
copilot/fix-62
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
6 commits
Select commit
Hold shift + click to select a range
653a85c
Initial plan
Copilot 95d6000
Add pytest test for gemm_atomics_all_reduce example
Copilot 5a630b7
Simplify test parameters and reduce matrix sizes for better performance
Copilot d3a7336
Fix pytest import errors by moving torch references and adding proper…
Copilot 0534462
Apply Ruff auto-fixes
github-actions[bot] 62f94fb
Refactor GEMM atomics all-reduce example to use reusable function and…
Copilot 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,70 @@ | ||
#!/usr/bin/env python3 | ||
# SPDX-License-Identifier: MIT | ||
# Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved. | ||
|
||
import importlib.util | ||
from pathlib import Path | ||
|
||
import pytest | ||
import torch | ||
import iris | ||
from examples.common.validation import validate_gemm | ||
|
||
# Import the benchmark module | ||
current_dir = Path(__file__).parent | ||
benchmark_path = (current_dir / "../../examples/08_gemm_atomics_all_reduce/benchmark.py").resolve() | ||
spec = importlib.util.spec_from_file_location("benchmark", benchmark_path) | ||
benchmark_module = importlib.util.module_from_spec(spec) | ||
spec.loader.exec_module(benchmark_module) | ||
|
||
# Test parameters | ||
DTYPES = [torch.float16, torch.float32] | ||
MATRIX_SIZES = [(256, 256, 256), (512, 512, 512)] | ||
BLOCK_SIZES = [(64, 64, 32)] | ||
|
||
|
||
@pytest.mark.parametrize("dtype", DTYPES) | ||
@pytest.mark.parametrize("m, n, k", MATRIX_SIZES) | ||
@pytest.mark.parametrize("block_m, block_n, block_k", BLOCK_SIZES) | ||
def test_gemm_atomics_all_reduce(dtype, m, n, k, block_m, block_n, block_k): | ||
# Initialize iris with appropriate heap size | ||
heap_size = 1 << 30 # 1GB | ||
shmem = iris.iris(heap_size) | ||
|
||
rank = shmem.get_rank() | ||
world_size = shmem.get_num_ranks() | ||
|
||
# Skip test if matrix dimensions are not divisible by world size | ||
if n % world_size != 0 or k % world_size != 0: | ||
pytest.skip(f"Matrix dimensions not divisible by world size {world_size}") | ||
|
||
# Create test matrices | ||
A = shmem.randn(m, k, device="cuda", dtype=dtype) | ||
B = shmem.randn(n, k, device="cuda", dtype=dtype) | ||
|
||
# Run the GEMM all-reduce operation using the benchmark function | ||
global_C, local_C = benchmark_module.run_gemm_all_reduce( | ||
A, | ||
B, | ||
shmem, | ||
block_m=block_m, | ||
block_n=block_n, | ||
block_k=block_k, | ||
gsize_m=8, | ||
two_tiles=True, | ||
num_stages=4, | ||
num_warps=4, | ||
waves_per_eu=2, | ||
mfma_instr_size=16, | ||
kpack=1, | ||
trace_tiles=False, | ||
) | ||
|
||
# Validate results | ||
success = validate_gemm(A, B, global_C, shmem, atol=1e-1) | ||
|
||
# Assert test passed | ||
assert success, "GEMM all-reduce validation failed" | ||
|
||
# Verify that we got a non-zero result | ||
assert not torch.allclose(global_C, torch.zeros_like(global_C)), "Result should not be all zeros" |
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.
The hardcoded tolerance value
1e-1
should be defined as a named constant (e.g.,GEMM_VALIDATION_TOLERANCE = 1e-1
) to make it clear this is a configurable parameter and easier to adjust for different precision requirements.Copilot uses AI. Check for mistakes.