-
Notifications
You must be signed in to change notification settings - Fork 19
Introduce cache modifiers #158
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
mawad-amd
wants to merge
21
commits into
main
Choose a base branch
from
muhaawad/cache-modifiers
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.
+575
−13
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
ba7028b
Add initial cache modifiers code and docs
mawad-amd 276713b
Add test
mawad-amd 6f6818f
Apply Ruff auto-fixes
github-actions[bot] 9ad63a0
Use `None` for default value
mawad-amd 677c966
Apply Ruff auto-fixes
github-actions[bot] af3592d
Cleanup the test
mawad-amd 8a411a2
Apply Ruff auto-fixes
github-actions[bot] ff26f96
Merge branch 'main' into muhaawad/cache-modifiers
mawad-amd 8f76d95
Check return value
mawad-amd 87fb74a
Remove volatile from store
mawad-amd 162ec39
Add test store
mawad-amd 01da6ca
Apply Ruff auto-fixes
github-actions[bot] 9a27ead
Add put/get modifiers
mawad-amd 99ee66c
Add tests for put and get cache modifiers
mawad-amd 74d0133
Apply Ruff auto-fixes
github-actions[bot] e76d4c5
Test default values
mawad-amd 451ee99
Fix default value docstring
mawad-amd b524f40
Fix tests
mawad-amd b8bd8a7
Apply Ruff auto-fixes
github-actions[bot] 0a157b5
Sync cache modifiers branch with main and add cache modifiers to copy…
Copilot b127b91
Merge branch 'main' into muhaawad/cache-modifiers
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# 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 | ||
from itertools import product | ||
|
||
|
||
@triton.jit | ||
def copy_kernel( | ||
data, | ||
results, | ||
cur_rank: tl.constexpr, | ||
num_ranks: tl.constexpr, | ||
BLOCK_SIZE: tl.constexpr, | ||
heap_bases: tl.tensor, | ||
load_cache_modifier: tl.constexpr, | ||
store_cache_modifier: tl.constexpr, | ||
): | ||
pid = tl.program_id(0) | ||
block_start = pid * BLOCK_SIZE | ||
offsets = block_start + tl.arange(0, BLOCK_SIZE) | ||
mask = offsets < BLOCK_SIZE | ||
|
||
# Test copy with cache modifiers - copy from current rank to other ranks | ||
for target_rank in range(num_ranks): | ||
src_data = data + BLOCK_SIZE * cur_rank | ||
dest_data = results + BLOCK_SIZE * target_rank | ||
if load_cache_modifier is None and store_cache_modifier is None: | ||
iris.copy(src_data + offsets, dest_data + offsets, cur_rank, target_rank, cur_rank, heap_bases, mask=mask) | ||
elif load_cache_modifier is None: | ||
iris.copy( | ||
src_data + offsets, | ||
dest_data + offsets, | ||
cur_rank, | ||
target_rank, | ||
cur_rank, | ||
heap_bases, | ||
mask=mask, | ||
store_cache_modifier=store_cache_modifier, | ||
) | ||
elif store_cache_modifier is None: | ||
iris.copy( | ||
src_data + offsets, | ||
dest_data + offsets, | ||
cur_rank, | ||
target_rank, | ||
cur_rank, | ||
heap_bases, | ||
mask=mask, | ||
load_cache_modifier=load_cache_modifier, | ||
) | ||
else: | ||
iris.copy( | ||
src_data + offsets, | ||
dest_data + offsets, | ||
cur_rank, | ||
target_rank, | ||
cur_rank, | ||
heap_bases, | ||
mask=mask, | ||
load_cache_modifier=load_cache_modifier, | ||
store_cache_modifier=store_cache_modifier, | ||
) | ||
|
||
|
||
# Define cache modifiers for load and store operations | ||
LOAD_CACHE_MODIFIERS = [None, "", ".ca", ".cg", ".cv"] | ||
STORE_CACHE_MODIFIERS = [None, "", ".wb", ".cg", ".cs", ".wt"] | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"load_cache_modifier,store_cache_modifier", list(product(LOAD_CACHE_MODIFIERS, STORE_CACHE_MODIFIERS)) | ||
) | ||
def test_copy_cache_modifiers(load_cache_modifier, store_cache_modifier): | ||
"""Test copy operation with various cache modifiers""" | ||
shmem = iris.iris(1 << 20) | ||
num_ranks = shmem.get_num_ranks() | ||
heap_bases = shmem.get_heap_bases() | ||
cur_rank = shmem.get_rank() | ||
|
||
BLOCK_SIZE = 16 | ||
data = shmem.zeros((num_ranks, BLOCK_SIZE), dtype=torch.float32) | ||
base = cur_rank + num_ranks | ||
for i in range(num_ranks): | ||
data[i, :] = base * (i + 1) | ||
|
||
results = shmem.zeros((num_ranks, BLOCK_SIZE), dtype=torch.float32) | ||
grid = lambda meta: (1,) | ||
copy_kernel[grid]( | ||
data, results, cur_rank, num_ranks, BLOCK_SIZE, heap_bases, load_cache_modifier, store_cache_modifier | ||
) | ||
|
||
shmem.barrier() | ||
|
||
# Verify results - each rank should have copied its data to all ranks | ||
for i in range(num_ranks): | ||
expected_value = base * (cur_rank + 1) | ||
assert torch.allclose(results[i], torch.full((BLOCK_SIZE,), expected_value, dtype=torch.float32)), ( | ||
f"Mismatch at rank {cur_rank}, target {i} with load_cache_modifier={load_cache_modifier}, store_cache_modifier={store_cache_modifier}" | ||
) |
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.