Ask Your Question
0

cv::cudacodec::createVideoReader segfault

asked 2017-11-13 12:56:06 -0600

fywa_prolge gravatar image

Hi,

I'm trying to run an OpenCV sample code presented here: opencv-3.3.1/samples/gpu/video_reader.cpp, but always get an segmentation fault signal within cv::cudacodec::createVideoReader(fname).

The stack trace is:

 1 cv::cudacodec::detail::CuvidVideoSource::CuvidVideoSource(cv::String const&) 
 2 cv::cudacodec::createVideoReader(cv::String const&) 
 3 main

Further debugging told me that memory access violation occurs at this line of code in opencv-3.3.1/modules/cudacodec/src/cuvid_video_cource.cpp:

CUresult cuRes = cuvidCreateVideoSource(&videoSource_, fname.c_str(), &params);

And seems like it calls an invalid address. Disasm also shows memory access violation at callq command.

Cuda video SDK samples shows that there's a robust dynamic linking presents. Do I need some extra dynamic linking while using OpenCV? Or maybe I do something wrong?

Running ./opencv_test_cudacodec also ends up with segfault.

What is being linked when I compile the sample:

g++ -Wl,--trace,--rpath,/usr/local/lib,--rpath,/usr/local/cuda/lib64 -Wl,-rpath,/home/den/Qt/5.7/gcc_64/lib -o opencv_cuda_test main.o   -lopencv_core -lopencv_cudacodec -lopencv_videoio -lopencv_highgui -lnvcuvid -L/usr/local/cuda/lib64 -L/home/den/Qt/5.7/gcc_64/lib -lQt5Core -lpthread

Specs:

  • Ubuntu 16.04;
  • GeForce GTX 960;
  • Driver Version: 384.90;
  • CUDA 9.0
  • opencv-3.3.1 (tried both release version and latest 'master' branch)
  • This is a configuration of OpenCV:
    -- General configuration for OpenCV 3.3.1-dev =====================================
    --   Version control:               3.3.1-144-gba940de
    -- 
    --   Platform:
    --     Timestamp:                   2017-11-13T17:54:56Z
    --     Host:                        Linux 4.4.0-98-generic x86_64
    --     CMake:                       3.5.1
    --     CMake generator:             Unix Makefiles
    --     CMake build tool:            /usr/bin/make
    --     Configuration:               RELEASE
    -- 
    --   CPU/HW features:
    --     Baseline:                    SSE SSE2 SSE3
    --       requested:                 SSE3
    --     Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2
    --       requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2
    --       SSE4_1 (3 files):          + SSSE3 SSE4_1
    --       SSE4_2 (1 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
    --       FP16 (2 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
    --       AVX (5 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
    --       AVX2 (9 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
    -- 
    --   C/C++:
    --     Built as dynamic libs?:      YES
    --     C++ Compiler:                /usr/bin/c++  (ver 5.4.0)
    --     C++ flags (Release):         -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
    --     C++ flags (Debug):           -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
    --     C Compiler:                  /usr/bin/cc
    --     C flags (Release):           -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-narrowing -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections  -msse -msse2 -msse3 -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUG
    --     C flags (Debug):             -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-narrowing -Wno-comment -fdiagnostics-show-option -Wno-long-long ...
(more)
edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
1

answered 2017-11-13 18:42:25 -0600

liyiwei gravatar image

I have seen similar problem with CUDA 9.0. Switching back to CUDA 8.0 works for me.

edit flag offensive delete link more
0

answered 2017-11-22 08:31:24 -0600

fywa_prolge gravatar image

I've resolved this problem.

The fact is file /usr/local/cuda-9.0/targets/x86_64-linux/include/dynlink_cuviddec.h contains code which requires additional symbol loading (which you can faound either in /usr/local/cuda-9.0/samples/3_Imaging/cudaDecodeGL/dynlink_nvcuvid.cpp or in the Video Codec SDK samples here: Video_Codec_SDK_8.0.14/Samples/common/src/

So, if you want to compile OpenCV sample decoder, you must compile dynlink_nvcuvid.cpp with your project while including files dynlink_cuviddec.h and dynlink_nvcuvid.h from Video Codec SDK

Also, don't forget to init API functions:

    void* hHandleDriver = 0;
    CUresult res = cuInit(0, __CUDA_API_VERSION, hHandleDriver);
    if (res != CUDA_SUCCESS) {
        throw exception();
    }
    res = cuvidInit(0);
    if (res != CUDA_SUCCESS) {
        throw exception();
    }
edit flag offensive delete link more

Comments

I ran into the same problem, but I'm using Windows 10 with OpenCv 3.3.1 and CUDA 9 and used Cmake to generate Visual Studio 2013 project to built it.

I have found the source files that you are talking about. but would you please mention what is the project that I need to include them in? opencv_cudacodec?

Finally, would please tell me where shall I put the mentioned code snippet?

Thanks in advance

Eslam gravatar imageEslam ( 2018-01-13 06:15:05 -0600 )edit

If am guessing right, then I don't need to rebuild opencv.

So I added those 3 source files into my project and included dynlink_nvcuvid.h into my main.cpp and executed your code snipped first thing in the main(). but I still get the same access violation.

Is this what your solution intended to be?

Eslam gravatar imageEslam ( 2018-01-13 06:41:36 -0600 )edit

You on the right way, but:

1) Maybe, you should rebuild openCV. Run CMake and check if there are entry 'WITH_NVCUVID = ON'. If it is OFF, you must reach a state when it becomes ON. Usually this issue is related to CMake could not find libnvcuvid.so (.dll) in dll search dir, and could be solved by symlinking this file from nvidia driver's dir. 2)Access violation could be also related to libnvcuvid.so was not found in dll search dir. You can debug function 'LOAD_LIBRARY' in dynlink_nvcuvid.cpp to figure out what exactly happens on loading symbols from this shared library.

fywa_prolge gravatar imagefywa_prolge ( 2018-02-13 07:08:13 -0600 )edit

Indeed I needed to build with WITH_NVCUVID = ON Thanks!

Eslam gravatar imageEslam ( 2018-06-18 04:44:17 -0600 )edit

How exactly do you add dynlink_nvcuvid.cpp to you project? I copied it to my project dir, added headers to my main source file (modified decoder example) at the top: #include <dynlink_nvcuvid.h> #include <dynlink_cuviddec.h> then compile with gcc -std=gnu++11 main.cpp dynlink_nvcuvid.cpp ...[the rest cuda/opencv include/lib dirs], but it does not see initCuvid() "undefined reference to `cuvidInit" (I compiled with WITH_NVCUVID=ON)

nazikus gravatar imagenazikus ( 2018-06-27 09:02:49 -0600 )edit

I reproduced everything on Ubuntu 16.04 with Opencv 3.4.2 and CUDA 9.2 and used Qtcreator as the IDE. and you shouldn't be seeing that undefined reference because its definition is in dynlink_nvcuvid.cpp

Eslam gravatar imageEslam ( 2018-08-28 07:38:20 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-11-13 12:56:06 -0600

Seen: 2,259 times

Last updated: Nov 22 '17