Skip to content

Fix issue #28407: cv::cuda::resize fails with continuous GpuMat#4071

Open
0AnshuAditya0 wants to merge 1 commit into
opencv:4.xfrom
0AnshuAditya0:fix-cuda-resize-continuous-28407
Open

Fix issue #28407: cv::cuda::resize fails with continuous GpuMat#4071
0AnshuAditya0 wants to merge 1 commit into
opencv:4.xfrom
0AnshuAditya0:fix-cuda-resize-continuous-28407

Conversation

@0AnshuAditya0
Copy link
Copy Markdown

Summary

Fixes issue where cv::cuda::resize fails with error "invalid argument in function 'createTextureObject'" when using GpuMat created via cv::cuda::createContinuous().

Root Cause

  • CUDA texture objects require properly aligned pitch values
  • createContinuous() GpuMat may have pitch that doesn't meet alignment requirements
  • Previous code only handled single row/column cases, not invalid pitch

Changes

  • texture.hpp: Added validation to check if step/pitch meets CUDA requirements
  • test_resize.cpp: Added regression test ResizeContinuous that verifies:
    • Regular GpuMat works (baseline)
    • Continuous GpuMat works (previously failed)
    • Both produce identical results

Testing

  • Test covers multiple sizes (10x10, 64x64, 128x128)
  • Multiple data types (CV_8UC1, CV_8UC3, CV_32FC1)
  • Multiple interpolation methods (NEAREST, LINEAR, CUBIC)

Fixes opencv/opencv#28407

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

@0AnshuAditya0 0AnshuAditya0 force-pushed the fix-cuda-resize-continuous-28407 branch from 8c0d111 to bf1fde3 Compare February 1, 2026 07:54
@asmorkalov asmorkalov force-pushed the fix-cuda-resize-continuous-28407 branch from bf1fde3 to 3055e49 Compare May 8, 2026 08:54
@asmorkalov asmorkalov self-assigned this May 8, 2026
@asmorkalov asmorkalov self-requested a review May 8, 2026 08:54
@asmorkalov
Copy link
Copy Markdown
Contributor

Rebased to current 4.x to trigger CI.

@asmorkalov
Copy link
Copy Markdown
Contributor

Local test fails:

 ./bin/opencv_test_cudawarping --gtest_filter=*ResizeContinuous*

Available options besides google test option: 
Usage: opencv_test_cudawarping [params] 

        --cuda_device (value:-1)
                CUDA device on which tests will be executed (-1 means all devices)
        -h, --help (value:false)
                Print help info

Run tests on all supported CUDA devices 

*** CUDA Device Query (Runtime API) version (CUDART static linking) *** 

Device count: 1

Device 0: "NVIDIA GeForce RTX 3070"
  CUDA Driver Version / Runtime Version          13.10 / 12.60
  CUDA Capability Major/Minor version number:    8.6
  Total amount of global memory:                 7834 MBytes (8214085632 bytes)
  GPU Clock Speed:                               1.74 GHz
  Max Texture Dimension Size (x,y,z)             1D=(131072), 2D=(131072,65536), 3D=(16384,16384,16384)
  Max Layered Texture Size (dim) x layers        1D=(32768) x 2048, 2D=(32768,32768) x 2048
  Total amount of constant memory:               65536 bytes
  Total amount of shared memory per block:       49152 bytes
  Total number of registers available per block: 65536
  Warp size:                                     32
  Maximum number of threads per block:           1024
  Maximum sizes of each dimension of a block:    1024 x 1024 x 64
  Maximum sizes of each dimension of a grid:     2147483647 x 65535 x 65535
  Maximum memory pitch:                          2147483647 bytes
  Texture alignment:                             512 bytes
  Concurrent copy and execution:                 Yes with 2 copy engine(s)
  Run time limit on kernels:                     Yes
  Integrated GPU sharing Host Memory:            No
  Support host page-locked memory mapping:       Yes
  Concurrent kernel execution:                   Yes
  Alignment requirement for Surfaces:            Yes
  Device has ECC support enabled:                No
  Device is using TCC driver mode:               No
  Device supports Unified Addressing (UVA):      Yes
  Device PCI Bus ID / PCI location ID:           16 / 0
  Compute Mode:
      Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) 

deviceQuery, CUDA Driver = CUDART, CUDA Driver Version  = 13.10, CUDA Runtime Version = 12.60, NumDevs = 1

CTEST_FULL_OUTPUT
OpenCV version: 4.14.0-pre
OpenCV VCS version: 4.13.0-249-g9929b5ceb9
Build type: Release
Compiler: /usr/bin/c++  (ver 13.3.0)
Algorithm hint: ALGO_HINT_ACCURATE
HAL: YES (ipp (ver 0.0.1))
Parallel framework: pthreads (nthreads=16)
CPU features: SSE? SSE2? SSE3? *SSE4.1? *SSE4.2? *AVX? *FP16? *AVX2? *AVX512-SKX?
Intel(R) IPP version: disabled
pci id for fd 19: 10de:2484, driver (null)
pci id for fd 20: 10de:2484, driver (null)
OpenCL is disabled
TEST: Skip tests with tags: 'mem_6gb', 'verylong'
Note: Google Test filter = *ResizeContinuous*
[==========] Running 27 tests from 1 test case.
[----------] Global test environment set-up.
[----------] 27 tests from CUDA_Warping/ResizeContinuous
[ RUN      ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/0, where GetParam() = (NVIDIA GeForce RTX 3070, 10x10, 8UC1, INTER_NEAREST)
Exception message: OpenCV(4.14.0-pre) /mnt/Projects/Projects/opencv_contrib/modules/cudev/include/opencv2/cudev/ptr2d/texture.hpp:147: error: (-217:Gpu API call) invalid argument in function 'createTextureObject'

/mnt/Projects/Projects/opencv_contrib/modules/cudawarping/test/test_resize.cpp:300: Failure
Expected: cv::cuda::resize(d_src_continuous, d_dst_continuous, cv::Size(size.width * 2, size.height * 2), 0, 0, interpolation) doesn't throw an exception.
  Actual: it throws.
/mnt/Projects/Projects/opencv_contrib/modules/cudawarping/test/test_resize.cpp:309: Failure
The max difference between matrices "h_dst_regular" and "h_dst_continuous" is 248 at (2, 2), which exceeds "0.0", where "h_dst_regular" at (2, 2) evaluates to (248), "h_dst_continuous" at (2, 2) evaluates to (0), "0.0" evaluates to 0
[  FAILED  ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/0, where GetParam() = (NVIDIA GeForce RTX 3070, 10x10, 8UC1, INTER_NEAREST) (118 ms)
[ RUN      ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/1, where GetParam() = (NVIDIA GeForce RTX 3070, 10x10, 8UC1, INTER_LINEAR)
Exception message: OpenCV(4.14.0-pre) /mnt/Projects/Projects/opencv_contrib/modules/cudev/include/opencv2/cudev/ptr2d/texture.hpp:147: error: (-217:Gpu API call) invalid argument in function 'createTextureObject'

/mnt/Projects/Projects/opencv_contrib/modules/cudawarping/test/test_resize.cpp:300: Failure
Expected: cv::cuda::resize(d_src_continuous, d_dst_continuous, cv::Size(size.width * 2, size.height * 2), 0, 0, interpolation) doesn't throw an exception.
  Actual: it throws.
/mnt/Projects/Projects/opencv_contrib/modules/cudawarping/test/test_resize.cpp:309: Failure
The max difference between matrices "h_dst_regular" and "h_dst_continuous" is 253 at (18, 18), which exceeds "0.0", where "h_dst_regular" at (18, 18) evaluates to (253), "h_dst_continuous" at (18, 18) evaluates to (0), "0.0" evaluates to 0
[  FAILED  ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/1, where GetParam() = (NVIDIA GeForce RTX 3070, 10x10, 8UC1, INTER_LINEAR) (0 ms)
[ RUN      ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/2, where GetParam() = (NVIDIA GeForce RTX 3070, 10x10, 8UC1, INTER_CUBIC)
Exception message: OpenCV(4.14.0-pre) /mnt/Projects/Projects/opencv_contrib/modules/cudev/include/opencv2/cudev/ptr2d/texture.hpp:147: error: (-217:Gpu API call) invalid argument in function 'createTextureObject'

/mnt/Projects/Projects/opencv_contrib/modules/cudawarping/test/test_resize.cpp:300: Failure
Expected: cv::cuda::resize(d_src_continuous, d_dst_continuous, cv::Size(size.width * 2, size.height * 2), 0, 0, interpolation) doesn't throw an exception.
  Actual: it throws.
/mnt/Projects/Projects/opencv_contrib/modules/cudawarping/test/test_resize.cpp:309: Failure
The max difference between matrices "h_dst_regular" and "h_dst_continuous" is 255 at (12, 17), which exceeds "0.0", where "h_dst_regular" at (12, 17) evaluates to (255), "h_dst_continuous" at (12, 17) evaluates to (0), "0.0" evaluates to 0
[  FAILED  ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/2, where GetParam() = (NVIDIA GeForce RTX 3070, 10x10, 8UC1, INTER_CUBIC) (0 ms)
[ RUN      ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/3, where GetParam() = (NVIDIA GeForce RTX 3070, 10x10, 8UC3, INTER_NEAREST)
[       OK ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/3 (1 ms)
[ RUN      ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/4, where GetParam() = (NVIDIA GeForce RTX 3070, 10x10, 8UC3, INTER_LINEAR)
[       OK ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/4 (0 ms)
[ RUN      ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/5, where GetParam() = (NVIDIA GeForce RTX 3070, 10x10, 8UC3, INTER_CUBIC)
[       OK ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/5 (0 ms)
[ RUN      ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/6, where GetParam() = (NVIDIA GeForce RTX 3070, 10x10, 32FC1, INTER_NEAREST)
Exception message: OpenCV(4.14.0-pre) /mnt/Projects/Projects/opencv_contrib/modules/cudev/include/opencv2/cudev/ptr2d/texture.hpp:147: error: (-217:Gpu API call) invalid argument in function 'createTextureObject'

/mnt/Projects/Projects/opencv_contrib/modules/cudawarping/test/test_resize.cpp:300: Failure
Expected: cv::cuda::resize(d_src_continuous, d_dst_continuous, cv::Size(size.width * 2, size.height * 2), 0, 0, interpolation) doesn't throw an exception.
  Actual: it throws.
/mnt/Projects/Projects/opencv_contrib/modules/cudawarping/test/test_resize.cpp:309: Failure
The max difference between matrices "h_dst_regular" and "h_dst_continuous" is 252.859 at (12, 10), which exceeds "0.0", where "h_dst_regular" at (12, 10) evaluates to (252.859), "h_dst_continuous" at (12, 10) evaluates to (0), "0.0" evaluates to 0
[  FAILED  ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/6, where GetParam() = (NVIDIA GeForce RTX 3070, 10x10, 32FC1, INTER_NEAREST) (0 ms)
[ RUN      ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/7, where GetParam() = (NVIDIA GeForce RTX 3070, 10x10, 32FC1, INTER_LINEAR)
Exception message: OpenCV(4.14.0-pre) /mnt/Projects/Projects/opencv_contrib/modules/cudev/include/opencv2/cudev/ptr2d/texture.hpp:147: error: (-217:Gpu API call) invalid argument in function 'createTextureObject'

/mnt/Projects/Projects/opencv_contrib/modules/cudawarping/test/test_resize.cpp:300: Failure
Expected: cv::cuda::resize(d_src_continuous, d_dst_continuous, cv::Size(size.width * 2, size.height * 2), 0, 0, interpolation) doesn't throw an exception.
  Actual: it throws.
/mnt/Projects/Projects/opencv_contrib/modules/cudawarping/test/test_resize.cpp:309: Failure
The max difference between matrices "h_dst_regular" and "h_dst_continuous" is 253.649 at (2, 2), which exceeds "0.0", where "h_dst_regular" at (2, 2) evaluates to (253.649), "h_dst_continuous" at (2, 2) evaluates to (0), "0.0" evaluates to 0
[  FAILED  ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/7, where GetParam() = (NVIDIA GeForce RTX 3070, 10x10, 32FC1, INTER_LINEAR) (0 ms)
[ RUN      ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/8, where GetParam() = (NVIDIA GeForce RTX 3070, 10x10, 32FC1, INTER_CUBIC)
Exception message: OpenCV(4.14.0-pre) /mnt/Projects/Projects/opencv_contrib/modules/cudev/include/opencv2/cudev/ptr2d/texture.hpp:147: error: (-217:Gpu API call) invalid argument in function 'createTextureObject'

/mnt/Projects/Projects/opencv_contrib/modules/cudawarping/test/test_resize.cpp:300: Failure
Expected: cv::cuda::resize(d_src_continuous, d_dst_continuous, cv::Size(size.width * 2, size.height * 2), 0, 0, interpolation) doesn't throw an exception.
  Actual: it throws.
/mnt/Projects/Projects/opencv_contrib/modules/cudawarping/test/test_resize.cpp:309: Failure
The max difference between matrices "h_dst_regular" and "h_dst_continuous" is 270.327 at (6, 13), which exceeds "0.0", where "h_dst_regular" at (6, 13) evaluates to (270.327), "h_dst_continuous" at (6, 13) evaluates to (0), "0.0" evaluates to 0
[  FAILED  ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/8, where GetParam() = (NVIDIA GeForce RTX 3070, 10x10, 32FC1, INTER_CUBIC) (1 ms)
[ RUN      ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/9, where GetParam() = (NVIDIA GeForce RTX 3070, 64x64, 8UC1, INTER_NEAREST)
[       OK ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/9 (0 ms)
[ RUN      ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/10, where GetParam() = (NVIDIA GeForce RTX 3070, 64x64, 8UC1, INTER_LINEAR)
[       OK ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/10 (0 ms)
[ RUN      ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/11, where GetParam() = (NVIDIA GeForce RTX 3070, 64x64, 8UC1, INTER_CUBIC)
[       OK ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/11 (0 ms)
[ RUN      ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/12, where GetParam() = (NVIDIA GeForce RTX 3070, 64x64, 8UC3, INTER_NEAREST)
[       OK ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/12 (1 ms)
[ RUN      ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/13, where GetParam() = (NVIDIA GeForce RTX 3070, 64x64, 8UC3, INTER_LINEAR)
[       OK ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/13 (0 ms)
[ RUN      ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/14, where GetParam() = (NVIDIA GeForce RTX 3070, 64x64, 8UC3, INTER_CUBIC)
[       OK ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/14 (0 ms)
[ RUN      ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/15, where GetParam() = (NVIDIA GeForce RTX 3070, 64x64, 32FC1, INTER_NEAREST)
[       OK ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/15 (0 ms)
[ RUN      ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/16, where GetParam() = (NVIDIA GeForce RTX 3070, 64x64, 32FC1, INTER_LINEAR)
[       OK ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/16 (1 ms)
[ RUN      ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/17, where GetParam() = (NVIDIA GeForce RTX 3070, 64x64, 32FC1, INTER_CUBIC)
[       OK ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/17 (0 ms)
[ RUN      ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/18, where GetParam() = (NVIDIA GeForce RTX 3070, 128x128, 8UC1, INTER_NEAREST)
[       OK ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/18 (0 ms)
[ RUN      ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/19, where GetParam() = (NVIDIA GeForce RTX 3070, 128x128, 8UC1, INTER_LINEAR)
[       OK ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/19 (0 ms)
[ RUN      ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/20, where GetParam() = (NVIDIA GeForce RTX 3070, 128x128, 8UC1, INTER_CUBIC)
[       OK ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/20 (1 ms)
[ RUN      ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/21, where GetParam() = (NVIDIA GeForce RTX 3070, 128x128, 8UC3, INTER_NEAREST)
[       OK ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/21 (0 ms)
[ RUN      ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/22, where GetParam() = (NVIDIA GeForce RTX 3070, 128x128, 8UC3, INTER_LINEAR)
[       OK ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/22 (1 ms)
[ RUN      ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/23, where GetParam() = (NVIDIA GeForce RTX 3070, 128x128, 8UC3, INTER_CUBIC)
[       OK ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/23 (0 ms)
[ RUN      ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/24, where GetParam() = (NVIDIA GeForce RTX 3070, 128x128, 32FC1, INTER_NEAREST)
[       OK ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/24 (0 ms)
[ RUN      ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/25, where GetParam() = (NVIDIA GeForce RTX 3070, 128x128, 32FC1, INTER_LINEAR)
[       OK ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/25 (1 ms)
[ RUN      ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/26, where GetParam() = (NVIDIA GeForce RTX 3070, 128x128, 32FC1, INTER_CUBIC)
[       OK ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/26 (0 ms)
[----------] 27 tests from CUDA_Warping/ResizeContinuous (125 ms total)

[----------] Global test environment tear-down
[==========] 27 tests from 1 test case ran. (125 ms total)
[  PASSED  ] 21 tests.
[  FAILED  ] 6 tests, listed below:
[  FAILED  ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/0, where GetParam() = (NVIDIA GeForce RTX 3070, 10x10, 8UC1, INTER_NEAREST)
[  FAILED  ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/1, where GetParam() = (NVIDIA GeForce RTX 3070, 10x10, 8UC1, INTER_LINEAR)
[  FAILED  ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/2, where GetParam() = (NVIDIA GeForce RTX 3070, 10x10, 8UC1, INTER_CUBIC)
[  FAILED  ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/6, where GetParam() = (NVIDIA GeForce RTX 3070, 10x10, 32FC1, INTER_NEAREST)
[  FAILED  ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/7, where GetParam() = (NVIDIA GeForce RTX 3070, 10x10, 32FC1, INTER_LINEAR)
[  FAILED  ] CUDA_Warping/ResizeContinuous.Regression_Issue28407/8, where GetParam() = (NVIDIA GeForce RTX 3070, 10x10, 32FC1, INTER_CUBIC)

 6 FAILED TESTS

@0AnshuAditya0 0AnshuAditya0 force-pushed the fix-cuda-resize-continuous-28407 branch from 3055e49 to a4998dd Compare May 9, 2026 05:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cv::cuda::resize failed with Continuous GpuMat

2 participants