Skip to content

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
ggml-org:masterfrom
mattjallo:cuda-fix-get-rows-back
Open

CUDA: fix get_rows_back for tables with more than 65535 rows (grid-y clamp + stride)#25103
mattjallo wants to merge 1 commit into
ggml-org:masterfrom
mattjallo:cuda-fix-get-rows-back

Conversation

@mattjallo

Copy link
Copy Markdown

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).

@mattjallo mattjallo requested review from a team and ggerganov as code owners June 28, 2026 14:49
@github-actions github-actions Bot added testing Everything test related ggml changes relating to the ggml tensor library for machine learning CUDA Related to the CUDA backend labels Jun 28, 2026
@ggml-gh-bot

ggml-gh-bot Bot commented Jun 28, 2026

Copy link
Copy Markdown

Hi @mattjallo, thanks for your contribution!

Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:

  • AI-generated content: This project does not accept PRs, descriptions or commit messages that are fully or predominantly AI-generated. If you have used AI to assist you in writing code, please make sure to disclose that explicitly.

Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below.

@mattjallo

Copy link
Copy Markdown
Author

re: flag from ggml-gh-bot, yes predominately - hand reviewed and tested

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CUDA Related to the CUDA backend ggml changes relating to the ggml tensor library for machine learning testing Everything test related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant