Add GPU JIT implementation for gridsample operation - #5139
Open
Imeguras wants to merge 3 commits into
Open
Conversation
…performance. Assisted-by: Claude
Contributor
|
Thank you for your contribution! Since this is an external pull request, a maintainer must review PR and add the "ok-to-test" label if it is approved for testing. |
Imeguras
marked this pull request as ready for review
August 18, 2026 21:36
Author
|
Hello! Im new to the contributing to such a big project. I noticed that one of the tests was building the gridsample by hand is it intentional? I look into others but didnt get my answer. |
Author
|
... Found a bug while testing out the performance increases on InternImage |
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.
Motivation
MIGraphX's ONNX parser lowers bilinear GridSample into a concat+gathernd decomposition that materializes explicit index tensors for every output element rather than computing sample positions inline.
For a typical Mask R-CNN mask-paste (100 instances, 28×28→640×640), this produces ~327 MB of baked index literals and takes 78.0 ms on an RX 7800 XT — 51% in concat, 27% in gathernd.
In practice this makes something like InternImage(the smaller models) run at less than 1 fps even with a rocm/hip and other amd dedicated frameworks, which for my project(being an alternative to deepstream is just horrible).
Technical Details
parse_gridsample.cpp's linear_sampler::sample() lowers bilinear GridSample into a concat+gathernd decomposition. For each output element it builds explicit {x0,y0}/{x1,y0}/{x0,y1}/{x1,y1} corner index tensors as ONNX-parser-time literals, then does four gathernd fetches + weighted add. It werks, but ends up baking a lot of memory for index literals into the compiled program.
Fix: a new gridsample operator with a dedicated GPU JIT kernel, following the existing pattern used by nonmaxsuppression/resize/roialign (src/targets/gpu/jit/.cpp + src/targets/gpu/kernels/include/migraphx/kernels/.hpp):
Changelog Category