CUDA: fix get_rows_back for tables with more than 65535 rows (grid-y clamp + stride)#25103
Open
mattjallo wants to merge 1 commit into
Open
CUDA: fix get_rows_back for tables with more than 65535 rows (grid-y clamp + stride)#25103mattjallo wants to merge 1 commit into
mattjallo wants to merge 1 commit into
Conversation
|
Hi @mattjallo, thanks for your contribution! Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:
Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below. |
Author
|
re: flag from ggml-gh-bot, yes predominately - hand reviewed and tested |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem. ggml_cuda_op_get_rows_back launches a grid whose y-dimension is the destination row count (ne1) with no clamp. Any table with more than 65535 rows — e.g. an embedding/vocab gradient — aborts at launch with GET_ROWS_BACK failed: invalid argument (CUDA grid y/z max is 65535). The forward get_rows kernel already clamps grid dims to UINT16_MAX; the backward one didn't.
Fix. Clamp grid.y to MIN(ne1, UINT16_MAX) and grid-stride over the destination rows in k_get_rows_back_float. Results and determinism are unchanged for tables that already fit; larger tables now compute correctly (the kernel stays the existing deterministic gather — perf is unchanged).
Test. Adds a test-backend-ops case test_get_rows_back(F32, n=1, m=70000, r=4, b=1). Without the fix it aborts on CUDA; with it, GET_ROWS_BACK passes 4/4 on an RTX 4060 (verified against the CPU reference).