Fix uint32 gridDim overflow in naive conv on large batch #3958
Open
chun-wan wants to merge 1 commit into
Open
Conversation
…figuration argument) The naive forward convolution solver builds a 1-D launch grid with global work size grid_size * 256, where grid_size = n * k (default/NCHW layout) or n * ho (NHWC). This value is passed to hipExtModuleLaunchKernel() as a uint32_t. For large problems it reaches/exceeds 2^32 and is silently truncated, producing an illegal grid (e.g. gridDim.x == 0 when n*k*256 is a multiple of 2^32) and a HIP "invalid configuration argument" during Find (EvaluateInvokers). The asynchronous error then corrupts the HIP context and can make an unrelated later launch fail with miopenStatusUnknownError. Reproduced on gfx950 (MI355X) with a ViT patch-embedding convolution: Conv2d(3, 1024, kernel_size=14, stride=14, bias=False), input [N,3,14,14] bf16. A stream of large N triggers it (e.g. N=32768: grid_size = n*k = 2^25, global work size = 2^25 * 256 = 2^33, truncated to 0 -> gridDim.x = 0). Fix (two layers): - ConvDirectNaiveConvFwd::IsApplicable: declare the solver not applicable when the 1-D grid would overflow uint32 (grid_size * 256 >= 2^32), so a non-overflowing solver is selected instead. - HIPOCKernelInvoke::run: validate the launch geometry before the HIP call and throw (mirroring run_cooperative()'s WORKAROUND_SWDEV_448157) so an oversized launch can no longer silently truncate and corrupt the HIP context; Find drops the offending candidate cleanly. Validated in a production-config build (MLIR + AI heuristics on): the repro's miopenStatusUnknownError is gone, every batch size in the repro sequence is served by a valid solver (ConvHipImplicitGemmGroupFwdXdlops) with correct output, and the conv-followed-by-another-kernel path no longer fails fatally.
chun-wan
requested review from
BradPepersAMD,
BrianHarrisonAMD,
JonathanLichtnerAMD and
adickin-amd
as code owners
July 15, 2026 12:38
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.
…figuration argument)
The naive forward convolution solver builds a 1-D launch grid with global work size grid_size * 256, where grid_size = n * k (default/NCHW layout) or n * ho (NHWC). This value is passed to hipExtModuleLaunchKernel() as a uint32_t. For large problems it reaches/exceeds 2^32 and is silently truncated, producing an illegal grid (e.g. gridDim.x == 0 when nk256 is a multiple of 2^32) and a HIP "invalid configuration argument" during Find (EvaluateInvokers). The asynchronous error then corrupts the HIP context and can make an unrelated later launch fail with miopenStatusUnknownError.
Reproduced on gfx950 (MI355X) with a ViT patch-embedding convolution:
Conv2d(3, 1024, kernel_size=14, stride=14, bias=False), input [N,3,14,14] bf16.
A stream of large N triggers it (e.g. N=32768: grid_size = n*k = 2^25, global work size = 2^25 * 256 = 2^33, truncated to 0 -> gridDim.x = 0).
Fix (two layers):
Validated in a production-config build (MLIR + AI heuristics on): the repro's miopenStatusUnknownError is gone, every batch size in the repro sequence is served by a valid solver (ConvHipImplicitGemmGroupFwdXdlops) with correct output, and the conv-followed-by-another-kernel path no longer fails fatally.
Proposed changes
Please describe the motivation behind the pull request, whether it enables a new feature or fixes a bug. If there are associated pull requests or issues, please link them to the pull request.
Checklist
Please put an
xinto the boxes that apply. You can also fill these out after creating the PR. If you're not sure, please don't hesitate to ask.make format&make check_formatto ensure the changes have been formatted