Skip to content

the cv::cuda::transpose crash when CV_32F rows exceed 1048560 #26317

Open
@braindevices

Description

@braindevices

System Information

OpenCV: 4.10.0
compiler: clang 17.0.6
Platform: almalinux9
cuda sdk: 12.3

Detailed description

exception message: OpenCV(4.10.0) opencv-4.10.0/contrib/modules/cudev/include/opencv2/cudev/grid/detail/transpose.hpp:118: error: (-217:Gpu API call) invalid configuration argument in function 'transpose

Steps to reproduce

for (int i = 1048555; i <= 1048561; i += 1)
    {
        cv::Mat src(i, 4, CV_32F, cv::Scalar{2});
        cv::Mat dst;
        cv::RNG rng{};
        rng.fill(
            src,
            cv::RNG::UNIFORM,
            0,
            200
        );

        // CPU works
        cv::transpose(src, dst);

        // GPU works
        cv::cuda::GpuMat d_src(src);
        cv::cuda::GpuMat d_dst;
        cv::cuda::GpuMat d_dst2{src.cols, src.rows, src.type(), cv::Scalar{10}};
        std::cout << cv::cuda::sum(d_src) << "| " << cv::cuda::sum(d_dst2) << std::endl; 
        cv::cuda::transpose(d_src, d_dst);
        cv::cuda::transpose(d_src, d_dst2);
        std::cout << cv::cuda::sum(d_src) << "| " << cv::cuda::sum(d_dst) << "| " << cv::cuda::sum(d_dst2) << std::endl; 
        // Check results
        bool passed = cv::norm(dst - cv::Mat(d_dst), cv::NORM_INF) < 1e-3;
        bool passed2 = cv::norm(dst - cv::Mat(d_dst2), cv::NORM_INF) < 1e-3;
        std::cout<< "i=" << i << " dst without memory initalized:" << (passed ? "passed" : "FAILED") << std::endl;
        std::cout<< "i=" << i <<  "dst with memory initalized:" << (passed2 ? "passed" : "FAILED") << std::endl;

        // Deallocate data here, otherwise deallocation will be performed
        // after context is extracted from the stack
        d_src.release();
        d_dst.release();
        d_dst2.release();
        std::cout << "released\n";
    }

Issue submission checklist

  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
  • I updated to the latest OpenCV version and the issue is still there
  • There is reproducer code and related data files (videos, images, onnx, etc)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions