Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception in constructor of cv::cuda::Stream #2705

Closed
rrrand opened this issue Oct 12, 2020 · 8 comments
Closed

Exception in constructor of cv::cuda::Stream #2705

rrrand opened this issue Oct 12, 2020 · 8 comments

Comments

@rrrand
Copy link

rrrand commented Oct 12, 2020

System information (version)
  • OpenCV => 4.2, 4.5-pre (c8ebe0e)
  • Operating System / Platform => Ubuntu 20.04
  • Compiler => g++-8.4.0
Detailed description

Exception occured in constructor of cv::cuda::Stream after caught exception from cv::cuda::warpPerspective (see issue #2361).

Exception in cv::cuda::warpPerspective was processed.
terminate called after throwing an instance of 'cv::Exception'
  what():  OpenCV(4.5.0-pre) /home/user/projects/opencv-4.5-builddir/opencv-master/modules/core/src/cuda_stream.cpp:303: error: (-217:Gpu API call) an illegal memory access was encountered in function 'Impl'

Steps to reproduce

Code based on example from issue #2361

// main.cpp

#include <cstdlib>
#include <opencv2/cudawarping.hpp>
#include <vector>
#include <iostream>

int main() {
  cv::Size inputSize{1000, 1000}; // can be different

  cv::Size outSize{670, 893};
  std::vector<double> values{
      0.3154414342519155,    0.2158186507123098,    133.1013012869572,
      -0.01298153793321658,  0.5681477441984867,    297.7284881948252,
      1.839213382549264e-05, 0.0006366310508410327, 1};

  cv::Mat matrix{cv::Size{3, 3}, CV_64FC1, values.data()};

  try {
    cv::cuda::GpuMat image{inputSize, CV_8UC4};

    cv::cuda::Stream stream;
    cv::cuda::warpPerspective(image, image, matrix, outSize, cv::INTER_LINEAR,
                              cv::BORDER_CONSTANT, cv::Scalar{0, 0, 0, 0},
                              stream);
    stream.waitForCompletion();
  }
  catch (const cv::Exception&) {
    std::cerr << "Exception in cv::cuda::warpPerspective was processed." << std::endl;
  }

  cv::cuda::Stream newStream;    // Exception!

  return EXIT_SUCCESS;
}
# cmake

cmake_minimum_required(VERSION 3.5)

project(min_ex)

# path to built from sources OpenCV
if (EXISTS /opt/opencv-4.2.0/lib/cmake/opencv4)
  set (OpenCV_DIR /opt/opencv-4.2.0/lib/cmake/opencv4)
endif()

find_package(OpenCV COMPONENTS core cudawarping REQUIRED)

add_executable(${PROJECT_NAME} src/main.cpp)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
target_link_libraries(${PROJECT_NAME} PRIVATE ${OpenCV_LIBS})
target_include_directories(${PROJECT_NAME} PRIVATE ${OpenCV_INCLUDE_DIRS})
@alalek
Copy link
Member

alalek commented Oct 12, 2020

4.2

We don't support outdated versions.
Try latest code from the master branch first.

@rrrand
Copy link
Author

rrrand commented Oct 12, 2020

@alalek
I've tested on current master (4.5-pre, c8ebe0e). The problem still remains. And the problem #2361 also remains.

@alalek
Copy link
Member

alalek commented Oct 12, 2020

Thank you for update!

Looks like this problem is the same and related to warpPerspective() CUDA implementation bug.

Closing as "duplicate".

@rrrand
Copy link
Author

rrrand commented Oct 12, 2020

@alalek
I absolutely agree that these two issues are related. But they are not the same. Exception in constructor is awful! And it should not just be closed!
At least it must be mentioned in original issue. Do you think I should do it?

@alalek
Copy link
Member

alalek commented Oct 12, 2020

mentioned

There is automatic cross-reference link in original issue.

@alalek
Copy link
Member

alalek commented Oct 12, 2020

Please try to build and run OpenCV CUDA tests (to ensure that CUDA runtime works).

@rrrand
Copy link
Author

rrrand commented Oct 13, 2020

There is automatic cross-reference link in original issue.

Thank you! Now I see.

There is automatic cross-reference link in original issue.

Could you please explain what exactly should be tested? I need to check that CUDA rutime works before or after exception? Or I should launch a separate test application?

@alalek
Copy link
Member

alalek commented Oct 13, 2020

Build and run opencv_test_cudaimgproc test application.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants