Repository navigation
[Perf] Enable PDL for fused MoE top-k gating #59737
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
vadiklyutiy
merged 16 commits into
vllm-project:main
from
wolfcomos:perf/topk-gating-pdl
Oct 19, 2026
Merged
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
6388a0e
[Kernel] Enable PDL for fused MoE top-k gating
wolfcomos 20395f9
Merge branch 'main' into perf/topk-gating-pdl
wolfcomos 4f9ade4
Merge branch 'main' into perf/topk-gating-pdl
wolfcomos c53ac81
Remove redundant CUDA version guards for top-k PDL
wolfcomos 713192b
Simplify device-side PDL guards in fused top-k gating
wolfcomos 23ff77b
Merge branch 'main' into perf/topk-gating-pdl
wolfcomos 09647c0
Remove host architecture check from top-k PDL launch
wolfcomos 30ec272
Match neighboring kernel ROCm guard style
wolfcomos 256473a
Merge main into perf/topk-gating-pdl
wolfcomos b5d2200
Merge branch 'main' into perf/topk-gating-pdl
wolfcomos 089aa00
Merge branch 'main' into perf/topk-gating-pdl
wolfcomos e7c301e
Merge branch 'main' into perf/topk-gating-pdl
wolfcomos 4333458
Merge main to pick up the duplicate hash-routing method fix
wolfcomos f0f86a3
Merge branch 'main' into perf/topk-gating-pdl
wolfcomos c8de7ab
Merge branch 'main' into perf/topk-gating-pdl
wolfcomos 8470dd4
Merge branch 'main' into perf/topk-gating-pdl
wolfcomos 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 |
|---|---|---|
|
|
@@ -276,7 +276,7 @@ __launch_bounds__(TPB) __global__ void moeTopK( | |
| */ | ||
|
|
||
| template <int VPT, int NUM_EXPERTS, int WARPS_PER_CTA, int BYTES_PER_LDG, int WARP_SIZE_PARAM, typename IndType, | ||
| typename InputType = float, ScoringFunc SF> | ||
| typename InputType = float, ScoringFunc SF, bool ENABLE_PDL = false> | ||
| __launch_bounds__(WARPS_PER_CTA* WARP_SIZE_PARAM) __global__ | ||
| void topkGating(const InputType* input, const bool* finished, float* output, const int num_rows, IndType* indices, | ||
| int* source_rows, const int k, const int start_expert, const int end_expert, const bool renormalize, | ||
|
|
@@ -329,6 +329,14 @@ __launch_bounds__(WARPS_PER_CTA* WARP_SIZE_PARAM) __global__ | |
| const int thread_row_in_warp = threadIdx.x / THREADS_PER_ROW; | ||
| const int thread_row = warp_base_row + thread_row_in_warp; | ||
|
|
||
| #if !defined(USE_ROCM) && defined(__CUDA_ARCH__) && __CUDA_ARCH__ >= 900 && CUDART_VERSION >= 12000 | ||
|
wolfcomos marked this conversation as resolved.
Resolved
wolfcomos marked this conversation as resolved.
Resolved
|
||
| if constexpr (ENABLE_PDL) { | ||
| // PDL permits early launch, but logits/metadata still depend on the producer. | ||
| cudaGridDependencySynchronize(); | ||
| cudaTriggerProgrammaticLaunchCompletion(); | ||
| } | ||
| #endif | ||
|
|
||
| // Threads with indices out of bounds should early exit here. | ||
| if (thread_row >= num_rows) | ||
| { | ||
|
|
@@ -620,6 +628,26 @@ void topkGatingLauncherHelper(const InputType* input, const bool* finished, floa | |
| const int num_blocks = (num_warps + WARPS_PER_TB - 1) / WARPS_PER_TB; | ||
|
|
||
| dim3 block_dim(WARP_SIZE_PARAM, WARPS_PER_TB); | ||
| #if !defined(USE_ROCM) && CUDART_VERSION >= 12000 | ||
|
Member
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. Shouldn't this
Contributor
Author
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. There isn't cuda arch macro on host side, so the checking will be a different here. |
||
| if (get_device_prop()->major >= 9) { | ||
|
wolfcomos marked this conversation as resolved.
Resolved
|
||
| cudaLaunchConfig_t config{}; | ||
| config.gridDim = dim3(num_blocks); | ||
| config.blockDim = block_dim; | ||
| config.stream = stream; | ||
| cudaLaunchAttribute attr{}; | ||
| attr.id = cudaLaunchAttributeProgrammaticStreamSerialization; | ||
| attr.val.programmaticStreamSerializationAllowed = 1; | ||
| config.attrs = &attr; | ||
| config.numAttrs = 1; | ||
| auto err = cudaLaunchKernelEx( | ||
| &config, | ||
| topkGating<VPT, EXPERTS, WARPS_PER_TB, BYTES_PER_LDG, WARP_SIZE_PARAM, IndType, InputType, SF, true>, | ||
| input, finished, output, num_rows, indices, source_row, k, start_expert, | ||
| end_expert, renormalize, bias, routed_scaling_factor, is_padding); | ||
| STD_TORCH_CHECK(err == cudaSuccess, "PDL topkGating launch failed: ", cudaGetErrorString(err)); | ||
| return; | ||
| } | ||
| #endif | ||
| topkGating<VPT, EXPERTS, WARPS_PER_TB, BYTES_PER_LDG, WARP_SIZE_PARAM, IndType, InputType, SF><<<num_blocks, block_dim, 0, stream>>>( | ||
| input, finished, output, num_rows, indices, source_row, k, start_expert, end_expert, renormalize, bias, routed_scaling_factor, is_padding); | ||
| } | ||
|
|
||
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.