onnxruntime
809135c0 - [CUDA] Fix MaxPool wrong values/indices for dilation>1 with non-zero begin padding (#29638)

Commit
33 days ago
[CUDA] Fix MaxPool wrong values/indices for dilation>1 with non-zero begin padding (#29638) ### Description The CUDA MaxPool custom index kernel (`max_pool_with_index.cu`) clamped a negative window start to `0` via `_Max<int64_t>(start, 0)`, discarding the dilation phase. For any axis with begin-pad > 0 **and** dilation > 1, the loop began at input index `0` (padding) instead of the first valid dilated tap, silently producing wrong `Y` values and wrong `Indices` (also corrupting downstream `MaxUnpool`). CPU is unaffected. Repro (`k=2, s=1, pads=[1,1], dilations=[2]`, `x=[1,9,2,8,3,7,4,6,5]`): CUDA returned `Y[0]=1`/`idx[0]=0` vs CPU `9`/`1`. **Changes** - **Kernel** (`onnxruntime/core/providers/cuda/nn/max_pool_with_index.cu`): replace each `X_start = _Max<int64_t>(X_start, 0)` with a phase-preserving advance to the first non-negative dilated tap. `*_end` is computed from the original start, so it stays correct, and the `maxval` seed reads a valid in-bounds tap. ```cpp // instead of: h_start = _Max<int64_t>(h_start, 0); if (h_start < 0) h_start += ((-h_start + dilation_h - 1) / dilation_h) * dilation_h; ``` Applied to `d_start`, `w_start`, `h_start`, so all of 1D/2D/3D are covered. - **Tests** (`onnxruntime/test/providers/cpu/nn/pool_op_test.cc`): un-excluded the CUDA legs from `MaxPool_10_DilationPadding_1d`/`_2d` (previously excluded due to this bug), and added `MaxPool_DilationPadding_1d_Indices` / `_2d_Indices` covering both value and index outputs with CPU as the oracle. ### Motivation and Context Dilated MaxPool on CUDA always lands on this custom-kernel path (`MaxPool<8>` selects it whenever `I != nullptr || !default_dilations`, and `dilation > 1` forces `!default_dilations`), so the wrong-result was unavoidable for dilated + padded MaxPool. Found as an adjacent finding during the AvgPool `ceil_mode` / asymmetric-pad work; the CUDA AvgPool kernel does not share this bug. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Author
Parents
Loading