How to compile a sample code written using Opencv cpp libraries and CUDA .

asked 2016-09-01 00:27:33 -0600

lm35 gravatar image

Can some one please guide me compiling a sample code, which loads and display an image. Code is written using OpecnCV libraries and certain CUDA properties.

nvcc pkg-config --libs opencv -L. -L/usr/local/cuda/lib -lcuda -lcudart pkg-config --cflags opencv -I. -I/usr/local /cuda/include LoadDisplayImageViaGPU.cu -o LoadDisplayImageViaGPU.out

Above given is the way how I tried to compile. It gave me following errors.

tmpxft_00000a84_00000000-4_LoadDisplayImageViaGPU.cudafe1.cpp:(.text+0x6e): undefined reference to cv::imread(std::string const&, int)' tmpxft_00000a84_00000000-4_LoadDisplayImageViaGPU.cudafe1.cpp:(.text+0xc0): undefined reference tocv::gpu::GpuMat::upload(cv::Mat const&)' tmpxft_00000a84_00000000-4_LoadDisplayImageViaGPU.cudafe1.cpp:(.text+0xc5): undefined reference to cv::gpu::Stream::Null()' tmpxft_00000a84_00000000-4_LoadDisplayImageViaGPU.cudafe1.cpp:(.text+0x118): undefined reference tocv::gpu::threshold(cv::gpu::GpuMat const&, cv::gpu::GpuMat&, double, double, int, cv::gpu::Stream&)' tmpxft_00000a84_00000000-4_LoadDisplayImageViaGPU.cudafe1.cpp:(.text+0x13a): undefined reference to cv::gpu::GpuMat::download(cv::Mat&) const' tmpxft_00000a84_00000000-4_LoadDisplayImageViaGPU.cudafe1.cpp:(.text+0x150): undefined reference tocv::_InputArray::_InputArray(cv::Mat const&)' tmpxft_00000a84_00000000-4_LoadDisplayImageViaGPU.cudafe1.cpp:(.text+0x193): undefined reference to cv::imshow(std::string const&, cv::_InputArray const&)' tmpxft_00000a84_00000000-4_LoadDisplayImageViaGPU.cudafe1.cpp:(.text+0x1bb): undefined reference tocv::waitKey(int)' /tmp/tmpxft_00000a84_00000000-17_LoadDisplayImageViaGPU.o: In function cv::Mat::~Mat()': tmpxft_00000a84_00000000-4_LoadDisplayImageViaGPU.cudafe1.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): undefined reference tocv::fastFree(void*)' /tmp/tmpxft_00000a84_00000000-17_LoadDisplayImageViaGPU.o: In function cv::Mat::release()': tmpxft_00000a84_00000000-4_LoadDisplayImageViaGPU.cudafe1.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x47): undefined reference tocv::Mat::deallocate()' /tmp/tmpxft_00000a84_00000000-17_LoadDisplayImageViaGPU.o: In function cv::gpu::GpuMat::~GpuMat()': tmpxft_00000a84_00000000-4_LoadDisplayImageViaGPU.cudafe1.cpp:(.text._ZN2cv3gpu6GpuMatD2Ev[_ZN2cv3gpu6GpuMatD5Ev]+0x14): undefined reference tocv::gpu::GpuMat::release()' /tmp/tmpxft_00000a84_00000000-17_LoadDisplayImageViaGPU.o:(.gcc_except_table+0x60): undefined reference to `typeinfo for cv::Exception' collect2: error: ld returned 1 exit status

Can someone please help me

edit retag flag offensive close merge delete

Comments

Are you sure that OpenCV itself was built using GPU support and with the correct GPU architecture?

StevenPuttemans gravatar imageStevenPuttemans ( 2016-09-01 03:04:29 -0600 )edit

Following are my OpenCV installation results related to CUDA

Use Cuda: YES (ver 7.5)

-- Use OpenCL: YES

-- NVIDIA CUDA -- Use CUFFT: YES -- Use CUBLAS: NO -- USE NVCUVID: NO -- NVIDIA GPU arch: 35 30 -- NVIDIA PTX archs: -- Use fast math: NO**

Also while installation i kept 'CUDA_GENERATION=Auto', since I was getting error. Actual architecture is Kepler

lm35 gravatar imagelm35 ( 2016-09-01 03:49:29 -0600 )edit

And you are absolutely sure that your graphics card supports a compute capability (arch) of 3.5? I have a Quadro K2000 card and it only supports 3.0, adding 3.5 gives tons of similar errors!

StevenPuttemans gravatar imageStevenPuttemans ( 2016-09-01 06:30:43 -0600 )edit

Mine is Tesla k40 with compute capability of 3.5

lm35 gravatar imagelm35 ( 2016-09-01 06:40:12 -0600 )edit

Can you please be a bit more elaborate on " I have a Quadro K2000 card and it only supports 3.0, adding 3.5 gives tons of similar errors!".. By "adding 3.5 gives " what do you mean. Sorry in advance for silly queries.

lm35 gravatar imagelm35 ( 2016-09-03 02:06:43 -0600 )edit

When running cmake-gui in your folder with the source code, you will see that the parameter architecture can obtain several architectures. Always select the only one supported for your system, since sometimes it is hard to get it compiled for non supported architectures.

StevenPuttemans gravatar imageStevenPuttemans ( 2016-09-05 03:04:52 -0600 )edit

From link text, I read the following By default, the OpenCV CUDA module includes: Binaries for compute capabilities 1.3 and 2.0 (controlled by CUDA_ARCH_BIN in CMake) PTX code for compute capabilities 1.1 and 1.3 (controlled by CUDA_ARCH_PTX in CMake) So while running cmake can I add CUDA_ARCH_PTX = 3.5 and CUDA_ARCH_BIN = 3.5, since Teslak40's CC is 3.5. Does the note in the link says that Opencv can take only value 1.3,1.1,2.0 as default and will not accept 3.5 ???

lm35 gravatar imagelm35 ( 2016-10-06 03:06:30 -0600 )edit