-
Notifications
You must be signed in to change notification settings - Fork 17
Implements copy function #113
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
+128
−0
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
1031a5d
initial copy impl
astroC86 504b3f4
Merge remote-tracking branch 'origin/main' into astroC86/get-or-put-t…
astroC86 d1cc73f
Merge branch 'main' into astroC86/get-or-put-to-copy
astroC86 3853f82
Intial impl of copy
astroC86 ea6f2da
Apply Ruff auto-fixes
github-actions[bot] 9975944
Merge branch 'main' into astroC86/get-or-put-to-copy
mawad-amd e85c1bb
replaced get and put with copy
astroC86 f7e02bc
Apply Ruff auto-fixes
github-actions[bot] 36b563f
Merge branch 'main' into astroC86/get-or-put-to-copy
astroC86 3c54277
Merge
astroC86 877df70
Feat: Impl copy
astroC86 fcc41e8
remoted trap flag
astroC86 2c4e9b3
Apply Ruff auto-fixes
github-actions[bot] 6026a60
Merge branch 'main' into astroC86/get-or-put-to-copy
neoblizz 671e3c8
Add missing docstring for `cur_rank`
mawad-amd c4b37d5
Merge branch 'main' into astroC86/get-or-put-to-copy
mawad-amd 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
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,75 @@ | ||
# SPDX-License-Identifier: MIT | ||
# Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved. | ||
|
||
import torch | ||
import triton | ||
import triton.language as tl | ||
import pytest | ||
import iris | ||
|
||
|
||
@triton.jit | ||
def copy_kernel( | ||
data, | ||
results, | ||
cur_rank: tl.constexpr, | ||
num_ranks: tl.constexpr, | ||
BLOCK_SIZE: tl.constexpr, | ||
heap_bases: tl.tensor, | ||
): | ||
pid = tl.program_id(0) | ||
block_start = pid * BLOCK_SIZE | ||
offsets = block_start + tl.arange(0, BLOCK_SIZE) | ||
mask = offsets < BLOCK_SIZE | ||
|
||
for target_rank in range(num_ranks): | ||
src_data = data + BLOCK_SIZE * cur_rank | ||
dest_data = results + BLOCK_SIZE * target_rank | ||
iris.copy(src_data + offsets, dest_data + offsets, target_rank, cur_rank, cur_rank, heap_bases, mask) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"dtype", | ||
[ | ||
torch.int8, | ||
torch.float16, | ||
torch.bfloat16, | ||
torch.float32, | ||
], | ||
) | ||
@pytest.mark.parametrize( | ||
"BLOCK_SIZE", | ||
[ | ||
1, | ||
8, | ||
16, | ||
32, | ||
], | ||
) | ||
def test_copy(dtype, BLOCK_SIZE): | ||
shmem = iris.iris(1 << 20) | ||
num_ranks = shmem.get_num_ranks() | ||
heap_bases = shmem.get_heap_bases() | ||
cur_rank = shmem.get_rank() | ||
|
||
data = shmem.zeros((num_ranks, BLOCK_SIZE), dtype=dtype) | ||
base = cur_rank + num_ranks | ||
for i in range(num_ranks): | ||
data[i, :] = base * (i + 1) | ||
|
||
results = shmem.zeros((num_ranks, BLOCK_SIZE), dtype=dtype) | ||
grid = lambda meta: (1,) | ||
copy_kernel[grid](data, results, cur_rank, num_ranks, BLOCK_SIZE, heap_bases) | ||
shmem.barrier() | ||
|
||
expected = shmem.zeros((num_ranks, BLOCK_SIZE), dtype=dtype) | ||
for rank_id in range(num_ranks): | ||
expected[rank_id, :] = (rank_id + num_ranks) * (cur_rank + 1) | ||
|
||
try: | ||
torch.testing.assert_close(results, expected, rtol=0, atol=0) | ||
except AssertionError as e: | ||
print(e) | ||
print("Expected:", expected) | ||
print("Actual:", results) | ||
raise |
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.