-
Notifications
You must be signed in to change notification settings - Fork 13.3k
CUDA: MoE helper in device code, better tile sizes #15525
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
JohannesGaessler
merged 6 commits into
ggml-org:master
from
JohannesGaessler:cuda-mmq-moe-device-4
Aug 25, 2025
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8bb55de
CUDA: MoE helper in device code, better tile sizes
JohannesGaessler 07c814b
reduce superfluous CUDA blocks
JohannesGaessler e7b884d
try AMD fix
JohannesGaessler 5724990
raise shared memory limit
JohannesGaessler a2f702a
reduce shared memory use
JohannesGaessler 1d60923
add assert
JohannesGaessler 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -420,16 +420,34 @@ static __device__ __forceinline__ half2 warp_reduce_sum(half2 a) { | |
|
||
template<int width = WARP_SIZE> | ||
static __device__ __forceinline__ int warp_reduce_all(int x) { | ||
#ifdef GGML_USE_HIP | ||
#ifndef GGML_USE_HIP | ||
if (width == WARP_SIZE) { | ||
return __all_sync(0xffffffff, x); | ||
} else | ||
#endif // GGML_USE_HIP | ||
{ | ||
#pragma unroll | ||
for (int offset = width/2; offset > 0; offset >>= 1) { | ||
x = x && __shfl_xor_sync(0xffffffff, x, offset, width); | ||
for (int offset = width/2; offset > 0; offset >>= 1) { | ||
x = __shfl_xor_sync(0xffffffff, x, offset, width) && x; | ||
} | ||
return x; | ||
} | ||
return x; | ||
#else | ||
static_assert(width == WARP_SIZE, "width != WARP_SIZE not implemented"); | ||
return __all_sync(0xffffffff, x); | ||
} | ||
|
||
template<int width = WARP_SIZE> | ||
static __device__ __forceinline__ int warp_reduce_any(int x) { | ||
#ifndef GGML_USE_HIP | ||
|
||
if (width == WARP_SIZE) { | ||
return __any_sync(0xffffffff, x); | ||
} else | ||
#endif // GGML_USE_HIP | ||
{ | ||
#pragma unroll | ||
for (int offset = width/2; offset > 0; offset >>= 1) { | ||
x = __shfl_xor_sync(0xffffffff, x, offset, width) || x; | ||
} | ||
return x; | ||
} | ||
} | ||
|
||
template<int width = WARP_SIZE> | ||
|
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.
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.
Why resitct this to cuda? might as well use __all on hip and check for ggml_cuda_get_physical_warp_size, even if we never use this with width == 64, that should still help rdna.
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 just wasn't aware of the
__all
instruction.