-
Notifications
You must be signed in to change notification settings - Fork 77
Add setup for Helion to compile on MTIA with basic test #1169
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
Myrthan
wants to merge
1
commit into
pytorch:main
Choose a base branch
from
Myrthan:export-D76375133
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
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 |
|---|---|---|
|
|
@@ -13,13 +13,16 @@ | |
| from .triton_helpers import triton_send_signal as triton_send_signal | ||
| from .triton_helpers import triton_wait_multiple_signal as triton_wait_multiple_signal | ||
| from .triton_helpers import triton_wait_signal as triton_wait_signal | ||
| import os | ||
|
|
||
| if TYPE_CHECKING: | ||
| import triton | ||
|
|
||
|
|
||
| def _alloc_fn(size: int, alignment: int, stream: int | None) -> torch.Tensor: | ||
| return torch.empty(size, device="cuda", dtype=torch.int8) | ||
| # Dynamically get device from Triton backend | ||
| backend = triton.runtime.driver.active.get_current_target().backend # pyright: ignore[reportAttributeAccessIssue,reportOptionalMemberAccess] | ||
| return torch.empty(size, device=backend, dtype=torch.int8) | ||
|
|
||
|
|
||
| def set_triton_allocator() -> None: | ||
|
|
@@ -66,14 +69,19 @@ def get_num_sm(device: torch.device, *, reserved_sms: int = 0) -> int: | |
| # TODO(EikanWang): gpu_subslice_count is an out-of-date term. we change update it to XeCore number. | ||
| elif device.type == "xpu": | ||
| available_sms = torch.xpu.get_device_properties(device.index).gpu_subslice_count | ||
| elif device.type == "mtia": | ||
| try: | ||
| from triton_mtia.backend.compiler import get_num_sm_for_arch | ||
| return get_num_sm_for_arch(device.backend.arch) | ||
| except ImportError: | ||
| raise RuntimeError("MTIA backend selected, but not available.") | ||
| else: | ||
| raise AssertionError("TODO: implement for other devices") | ||
| raise NotImplementedError(f"get_num_sm not implemented for device type: {device.type}") | ||
|
|
||
| if reserved_sms <= 0: | ||
| return available_sms | ||
| return max(available_sms - reserved_sms, 1) | ||
|
|
||
|
|
||
| def default_launcher( | ||
| triton_kernel: triton.JITFunction, | ||
| grid: tuple[int, ...], | ||
|
|
@@ -83,6 +91,23 @@ def default_launcher( | |
| **kwargs: dict, | ||
| ) -> object: | ||
| """Default launcher function that executes the kernel immediately.""" | ||
| # Get current backend from Triton | ||
| import triton | ||
| backend = triton.runtime.driver.active.get_current_target().backend # pyright: ignore[reportAttributeAccessIssue,reportOptionalMemberAccess] | ||
| if backend == "mtia": | ||
| # MTIA-specific initialization | ||
| try: | ||
| from mtia.re.re_unittest_lib import init_mtia_device | ||
| from triton_mtia.python.mtia.eager import mtia_triton_launcher | ||
|
|
||
| init_mtia_device() | ||
| # Ignore disk cache. Kernels will still keep an in-memory cache. | ||
| os.environ.setdefault("TRITON_ALWAYS_COMPILE", "1") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this required? Seems a bit odd to be running this code on every kernel launch and not cleaning it up. |
||
| mtia_triton_launcher.init() | ||
| except ImportError as e: | ||
| raise RuntimeError(f"MTIA backend selected but required modules not available: {e}") | ||
|
|
||
| # For both CUDA and MTIA, use the same kernel execution | ||
| return triton_kernel.run( | ||
| *args, | ||
| grid=grid, | ||
|
|
||
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
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.
I'd expect this to cause some lints, though for some reason CI isn't running. Can you do
./lint.sh install && ./lint.sh?