-
Notifications
You must be signed in to change notification settings - Fork 23
Experimental rocSHMEM support #356
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
alextmagro
wants to merge
7
commits into
dev
Choose a base branch
from
rocshmem_enablement
base: dev
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.
+431
−1
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3597142
Experimental rocSHMEM support
alextmagro 1c54796
add rocshmem wait warning
alextmagro ff54a6a
CMake Cleanup
alextmagro 0a4c252
include/hipify refactor
alextmagro b95cad1
make IMPORTED rocshmem library
alextmagro 22f7bf5
Move rocshmem_home logic to subproject
alextmagro e82a4b1
change rocshmem_api from object to static
alextmagro 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
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,54 @@ | ||
| # Copyright (c) 2025, Advanced Micro Devices, Inc. All rights reserved. | ||
| # License for AMD contributions = MIT. See LICENSE for more information | ||
|
|
||
| cmake_minimum_required (VERSION 3.21) | ||
| project(rocshmem LANGUAGES HIP) | ||
|
|
||
| find_package(hip REQUIRED) | ||
| find_package(MPI REQUIRED) | ||
ipanfilo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| add_library(rocshmemapi STATIC rocshmem_waitkernel.hip) | ||
|
|
||
| target_compile_options(rocshmemapi PRIVATE | ||
ipanfilo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| $<$<COMPILE_LANGUAGE:HIP>:-fgpu-rdc> | ||
| ) | ||
|
|
||
| set_target_properties(rocshmemapi PROPERTIES | ||
| CXX_STANDARD 17 | ||
| HIP_STANDARD 17 | ||
| POSITION_INDEPENDENT_CODE ON | ||
| ) | ||
|
|
||
| if(DEFINED ENV{ROCSHMEM_HOME}) | ||
| set(ROCSHMEM_HOME "$ENV{ROCSHMEM_HOME}" CACHE STRING "Location of ROCSHMEM installation") | ||
| else() | ||
| set(ROCSHMEM_HOME "/opt/rocm" CACHE STRING "Location of ROCSHMEM installation (default)") | ||
| endif() | ||
| set(ROCSHMEM_LIBRARY_PATH "${ROCSHMEM_HOME}/lib/librocshmem.a") | ||
| if (EXISTS ${ROCSHMEM_LIBRARY_PATH}) | ||
| add_library(rocshmem STATIC IMPORTED) | ||
| set_target_properties(rocshmem PROPERTIES | ||
| IMPORTED_LOCATION "${ROCSHMEM_LIBRARY_PATH}" | ||
| IMPORTED_LINK_INTERFACE_LANGUAGES "CXX" | ||
| ) | ||
| else() | ||
| message(FATAL_ERROR "ROCSHMEM library not found at ${ROCSHMEM_LIBRARY_PATH}. PLease set ROCSHMEM_HOME.") | ||
| endif() | ||
|
|
||
| set(ROCSHMEM_INCLUDE_DIR "${ROCSHMEM_HOME}/include/rocshmem") | ||
| if(NOT EXISTS "${ROCSHMEM_INCLUDE_DIR}") | ||
| set(ROCSHMEM_INCLUDE_DIR "${ROCSHMEM_HOME}/include") | ||
| endif() | ||
|
|
||
| target_include_directories(rocshmemapi PUBLIC | ||
| "${ROCSHMEM_INCLUDE_DIR}" | ||
| "${CMAKE_CURRENT_SOURCE_DIR}" | ||
| "${MPI_INCLUDE_PATH}" | ||
| ) | ||
|
|
||
| target_link_libraries(rocshmemapi PUBLIC | ||
ipanfilo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| rocshmem | ||
| MPI::MPI_CXX | ||
| hip::host | ||
| hip::device | ||
| ) | ||
115 changes: 115 additions & 0 deletions
115
transformer_engine/common/rocshmem_api/rocshmem_waitkernel.hip
ipanfilo marked this conversation as resolved.
Show resolved
Hide resolved
|
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,115 @@ | ||
| /************************************************************************* | ||
| * Copyright (c) 2025, Advanced Micro Devices, Inc. All rights reserved. | ||
| * License for AMD contributions = MIT. See LICENSE for more information | ||
| *************************************************************************/ | ||
|
|
||
| #include <hip/hip_runtime.h> | ||
| #include <rocshmem.hpp> | ||
|
|
||
| #include "../util/logging_hip.h" | ||
| #include "rocshmem_waitkernel.hpp" | ||
|
|
||
| using namespace rocshmem; | ||
|
|
||
| __global__ void wait_until_on_stream_and_reset(uint64_t *wait_flag, | ||
| uint64_t wait_value, | ||
| uint64_t signal_reset) { | ||
| rocshmem_ulonglong_wait_until((unsigned long long*)wait_flag, | ||
| ROCSHMEM_CMP_EQ, | ||
| (unsigned long long)wait_value); | ||
| } | ||
|
|
||
| __global__ void rocshmem_putmem_signal_kernel(void* dst_ptr, const void* src_ptr, | ||
| size_t nelement, uint64_t* sig_addr, | ||
| uint64_t sigval, int peer) { | ||
| if (threadIdx.x == 0 && blockIdx.x == 0) { | ||
| rocshmem_putmem(dst_ptr, src_ptr, nelement, peer); | ||
| rocshmem_fence(); | ||
| rocshmem_ulonglong_p((unsigned long long*)sig_addr, | ||
| (unsigned long long)sigval, | ||
| peer); | ||
| } | ||
| } | ||
|
|
||
| void te_rocshmem_putmem_signal(void* dst_ptr, const void* src_ptr, size_t nelement, | ||
| uint64_t* sig_addr, uint64_t sigval, int peer, | ||
| hipStream_t cur_stream) { | ||
| hipLaunchKernelGGL(rocshmem_putmem_signal_kernel, | ||
| dim3(1), dim3(1), 0, cur_stream, | ||
| dst_ptr, src_ptr, nelement, sig_addr, | ||
| sigval, peer); | ||
| } | ||
|
|
||
| void te_rocshmem_wait_on_stream(uint64_t* sig_addr, | ||
| WaitKind wait_kind, | ||
| hipStream_t cur_stream) { | ||
| uint64_t wait_value = 1; | ||
| uint64_t signal_reset = 0; | ||
|
|
||
| NVTE_CHECK(wait_kind >= WaitKind::KERNEL_WAIT && | ||
| wait_kind <= WaitKind::STREAM_WAIT, | ||
| "Invalid wait kind"); | ||
|
|
||
| switch (wait_kind) { | ||
| // ### wait_until_on_stream not yet implemented for rocshmem ### | ||
| // ### KernelWait is robust but slightly slower due to launch ### | ||
| case WaitKind::ROCSHMEM_WAIT: | ||
| printf("WARNING: rocshmem wait is not implemented yet, defaulting to kernel wait.\n"); | ||
| // rocshmem__ulonglong_wait_until_on_stream(sig_addr, | ||
| // ROCSHMEM_CMP_EQ, | ||
| // wait_value, | ||
|
Collaborator
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. Let's add a warning here saying that rocshmem_wait is not supported on ROCm. |
||
| // cur_stream); | ||
| // hipStreamWriteValue64(cur_stream, | ||
| // reinterpret_cast<hipDeviceptr_t>(sig_addr), | ||
| // signal_reset, 0); | ||
| // break; | ||
| case WaitKind::KERNEL_WAIT: | ||
| hipLaunchKernelGGL(wait_until_on_stream_and_reset, | ||
| dim3(1), dim3(1), 0, cur_stream, | ||
| sig_addr, wait_value, signal_reset); | ||
| hipStreamWriteValue64(cur_stream, | ||
| reinterpret_cast<hipDeviceptr_t>(sig_addr), | ||
| signal_reset, 0); | ||
| break; | ||
| case WaitKind::STREAM_WAIT: | ||
| hipStreamWaitValue64(cur_stream, | ||
| reinterpret_cast<hipDeviceptr_t>(sig_addr), | ||
| wait_value, hipStreamWaitValueGte); | ||
| hipStreamWriteValue64(cur_stream, | ||
| reinterpret_cast<hipDeviceptr_t>(sig_addr), | ||
| signal_reset, 0); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| int te_rocshmem_init_thread(int required, int* provided) { | ||
| if (required == 0 && provided == nullptr) { | ||
| rocshmem_init(); | ||
| return 0; | ||
| } else { | ||
| return rocshmem_init_thread(required, provided); | ||
| } | ||
| } | ||
|
|
||
| void te_rocshmem_finalize() { | ||
| rocshmem_finalize(); | ||
| } | ||
|
|
||
| int te_rocshmem_my_pe() { | ||
| return rocshmem_my_pe(); | ||
| } | ||
|
|
||
| int te_rocshmem_n_pes() { | ||
| return rocshmem_n_pes(); | ||
| } | ||
|
|
||
| void* te_rocshmem_malloc(size_t size) { | ||
| return rocshmem_malloc(size); | ||
| } | ||
|
|
||
| void te_rocshmem_free(void* ptr) { | ||
| rocshmem_free(ptr); | ||
| } | ||
|
|
||
| void te_rocshmem_wait_until(uint64_t* signal_addr, uint64_t expected_value, | ||
| hipStream_t stream); | ||
33 changes: 33 additions & 0 deletions
33
transformer_engine/common/rocshmem_api/rocshmem_waitkernel.hpp
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,33 @@ | ||
| /************************************************************************* | ||
| * Copyright (c) 2025, Advanced Micro Devices, Inc. All rights reserved. | ||
| * License for AMD contributions = MIT. See LICENSE for more information | ||
| *************************************************************************/ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <cstdint> | ||
|
|
||
| enum class WaitKind : uint8_t { | ||
| KERNEL_WAIT = 0, | ||
| ROCSHMEM_WAIT = 1, | ||
| STREAM_WAIT = 2 | ||
| }; | ||
|
|
||
| void te_rocshmem_wait_on_stream(uint64_t *sig_addr, WaitKind wait_kind, hipStream_t cur_stream); | ||
|
|
||
| void te_rocshmem_putmem_signal(void* dst_ptr, const void* src_ptr, size_t nelement, | ||
| uint64_t* sig_addr, uint64_t sigval, int peer, hipStream_t cur_stream); | ||
|
|
||
| /* | ||
| These are minimal wrappers around rocshmem functions. As pytorch is a cpp extension, | ||
| rocshmem is a static library, and rocshmem does not have separate host / device libraries | ||
| we need to move these to common, which handles device code properly. | ||
| */ | ||
| int te_rocshmem_init_thread(int required, int* provided); | ||
| void te_rocshmem_finalize(); | ||
| int te_rocshmem_my_pe(); | ||
| int te_rocshmem_n_pes(); | ||
| void* te_rocshmem_malloc(size_t size); | ||
| void te_rocshmem_free(void* ptr); | ||
| void te_rocshmem_wait_until(uint64_t* signal_addr, uint64_t expected_value, | ||
| hipStream_t stream); |
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.
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.