问题
I installed NVIDIA drivers, CUDA 10.2, CuDNN 7.5, openCV 4.2.0 on Ubuntu 18.04. I tested each installation independently by running some example codes, it works fine.
but when I run OpenCV+CUDA program like below
#include <iostream>
#include <ctime>
#include <cmath>
#include "bits/time.h"
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/core/cuda.hpp>
#include <opencv2/cudaarithm.hpp>
#include <opencv2/cudaimgproc.hpp>
#define TestCUDA true
int main() {
std::clock_t begin = std::clock();
try {
cv::String filename = "/home/raul/Pictures/Screenshot_20170317_105454.png";
cv::Mat srcHost = cv::imread(filename, cv::IMREAD_GRAYSCALE);
for(int i=0; i<1000; i++) {
if(TestCUDA) {
cv::cuda::GpuMat dst, src;
src.upload(srcHost);
//cv::cuda::threshold(src,dst,128.0,255.0, CV_THRESH_BINARY);
cv::cuda::bilateralFilter(src,dst,3,1,1);
cv::Mat resultHost;
dst.download(resultHost);
} else {
cv::Mat dst;
cv::bilateralFilter(srcHost,dst,3,1,1);
}
}
//cv::imshow("Result",resultHost);
//cv::waitKey();
} catch(const cv::Exception& ex) {
std::cout << "Error: " << ex.what() << std::endl;
}
std::clock_t end = std::clock();
std::cout << double(end-begin) / CLOCKS_PER_SEC << std::endl;
}
i get error as
Error: OpenCV(4.2.0) /home/naeem/opencv_contrib-4.2.0/modules/cudaimgproc/src/cuda/bilateral_filter.cu:138: error: (-217:Gpu API call) invalid device function in function 'bilateral_caller'
seems like i am stuck..
I compiled using CMAKE and current status of Cuda,CudNN, opencv as below
naeem@machine:~/HOME$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Wed_Oct_23_19:24:38_PDT_2019
Cuda compilation tools, release 10.2, V10.2.89
naeem@machine:~/HOME$ nvidia-smi
Mon Apr 20 12:06:13 2020
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 440.64.00 Driver Version: 440.64.00 CUDA Version: 10.2 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
|===============================+======================+======================|
| 0 GeForce GTX 105... On | 00000000:01:00.0 Off | N/A |
| N/A 47C P0 N/A / N/A | 419MiB / 4040MiB | 0% Default |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: GPU Memory |
| GPU PID Type Process name Usage |
|=============================================================================|
| 0 1235 G /usr/lib/xorg/Xorg 28MiB |
| 0 1335 G /usr/bin/gnome-shell 47MiB |
| 0 2515 G /usr/lib/xorg/Xorg 171MiB |
| 0 2686 G /usr/bin/gnome-shell 116MiB |
| 0 4551 G /proc/self/exe 48MiB |
| 0 4552 G ...-token=57FD8DE5B1D317B30965C435E4973B6F 1MiB |
+-----------------------------------------------------------------------------+
naeem@machine:~/HOME$ ldconfig -p | grep opencv
libopencv_xphoto.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_xphoto.so.4.2
libopencv_xphoto.so (libc6,x86-64) => /usr/local/lib/libopencv_xphoto.so
libopencv_xobjdetect.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_xobjdetect.so.4.2
libopencv_xobjdetect.so (libc6,x86-64) => /usr/local/lib/libopencv_xobjdetect.so
libopencv_ximgproc.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_ximgproc.so.4.2
libopencv_ximgproc.so (libc6,x86-64) => /usr/local/lib/libopencv_ximgproc.so
libopencv_xfeatures2d.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_xfeatures2d.so.4.2
libopencv_xfeatures2d.so (libc6,x86-64) => /usr/local/lib/libopencv_xfeatures2d.so
libopencv_videostab.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_videostab.so.4.2
libopencv_videostab.so (libc6,x86-64) => /usr/local/lib/libopencv_videostab.so
libopencv_videoio.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_videoio.so.4.2
libopencv_videoio.so (libc6,x86-64) => /usr/local/lib/libopencv_videoio.so
libopencv_video.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_video.so.4.2
libopencv_video.so (libc6,x86-64) => /usr/local/lib/libopencv_video.so
libopencv_tracking.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_tracking.so.4.2
libopencv_tracking.so (libc6,x86-64) => /usr/local/lib/libopencv_tracking.so
libopencv_text.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_text.so.4.2
libopencv_text.so (libc6,x86-64) => /usr/local/lib/libopencv_text.so
libopencv_surface_matching.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_surface_matching.so.4.2
libopencv_surface_matching.so (libc6,x86-64) => /usr/local/lib/libopencv_surface_matching.so
libopencv_superres.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_superres.so.4.2
libopencv_superres.so (libc6,x86-64) => /usr/local/lib/libopencv_superres.so
libopencv_structured_light.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_structured_light.so.4.2
libopencv_structured_light.so (libc6,x86-64) => /usr/local/lib/libopencv_structured_light.so
libopencv_stitching.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_stitching.so.4.2
libopencv_stitching.so (libc6,x86-64) => /usr/local/lib/libopencv_stitching.so
libopencv_stereo.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_stereo.so.4.2
libopencv_stereo.so (libc6,x86-64) => /usr/local/lib/libopencv_stereo.so
libopencv_shape.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_shape.so.4.2
libopencv_shape.so (libc6,x86-64) => /usr/local/lib/libopencv_shape.so
libopencv_sfm.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_sfm.so.4.2
libopencv_sfm.so (libc6,x86-64) => /usr/local/lib/libopencv_sfm.so
libopencv_saliency.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_saliency.so.4.2
libopencv_saliency.so (libc6,x86-64) => /usr/local/lib/libopencv_saliency.so
libopencv_rgbd.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_rgbd.so.4.2
libopencv_rgbd.so (libc6,x86-64) => /usr/local/lib/libopencv_rgbd.so
libopencv_reg.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_reg.so.4.2
libopencv_reg.so (libc6,x86-64) => /usr/local/lib/libopencv_reg.so
libopencv_quality.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_quality.so.4.2
libopencv_quality.so (libc6,x86-64) => /usr/local/lib/libopencv_quality.so
libopencv_plot.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_plot.so.4.2
libopencv_plot.so (libc6,x86-64) => /usr/local/lib/libopencv_plot.so
libopencv_photo.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_photo.so.4.2
libopencv_photo.so (libc6,x86-64) => /usr/local/lib/libopencv_photo.so
libopencv_phase_unwrapping.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_phase_unwrapping.so.4.2
libopencv_phase_unwrapping.so (libc6,x86-64) => /usr/local/lib/libopencv_phase_unwrapping.so
libopencv_optflow.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_optflow.so.4.2
libopencv_optflow.so (libc6,x86-64) => /usr/local/lib/libopencv_optflow.so
libopencv_objdetect.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_objdetect.so.4.2
libopencv_objdetect.so (libc6,x86-64) => /usr/local/lib/libopencv_objdetect.so
libopencv_ml.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_ml.so.4.2
libopencv_ml.so (libc6,x86-64) => /usr/local/lib/libopencv_ml.so
libopencv_line_descriptor.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_line_descriptor.so.4.2
libopencv_line_descriptor.so (libc6,x86-64) => /usr/local/lib/libopencv_line_descriptor.so
libopencv_imgproc.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_imgproc.so.4.2
libopencv_imgproc.so (libc6,x86-64) => /usr/local/lib/libopencv_imgproc.so
libopencv_imgcodecs.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_imgcodecs.so.4.2
libopencv_imgcodecs.so (libc6,x86-64) => /usr/local/lib/libopencv_imgcodecs.so
libopencv_img_hash.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_img_hash.so.4.2
libopencv_img_hash.so (libc6,x86-64) => /usr/local/lib/libopencv_img_hash.so
libopencv_highgui.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_highgui.so.4.2
libopencv_highgui.so (libc6,x86-64) => /usr/local/lib/libopencv_highgui.so
libopencv_hfs.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_hfs.so.4.2
libopencv_hfs.so (libc6,x86-64) => /usr/local/lib/libopencv_hfs.so
libopencv_hdf.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_hdf.so.4.2
libopencv_hdf.so (libc6,x86-64) => /usr/local/lib/libopencv_hdf.so
libopencv_gapi.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_gapi.so.4.2
libopencv_gapi.so (libc6,x86-64) => /usr/local/lib/libopencv_gapi.so
libopencv_fuzzy.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_fuzzy.so.4.2
libopencv_fuzzy.so (libc6,x86-64) => /usr/local/lib/libopencv_fuzzy.so
libopencv_freetype.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_freetype.so.4.2
libopencv_freetype.so (libc6,x86-64) => /usr/local/lib/libopencv_freetype.so
libopencv_flann.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_flann.so.4.2
libopencv_flann.so (libc6,x86-64) => /usr/local/lib/libopencv_flann.so
libopencv_features2d.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_features2d.so.4.2
libopencv_features2d.so (libc6,x86-64) => /usr/local/lib/libopencv_features2d.so
libopencv_face.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_face.so.4.2
libopencv_face.so (libc6,x86-64) => /usr/local/lib/libopencv_face.so
libopencv_dpm.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_dpm.so.4.2
libopencv_dpm.so (libc6,x86-64) => /usr/local/lib/libopencv_dpm.so
libopencv_dnn_superres.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_dnn_superres.so.4.2
libopencv_dnn_superres.so (libc6,x86-64) => /usr/local/lib/libopencv_dnn_superres.so
libopencv_dnn_objdetect.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_dnn_objdetect.so.4.2
libopencv_dnn_objdetect.so (libc6,x86-64) => /usr/local/lib/libopencv_dnn_objdetect.so
libopencv_dnn.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_dnn.so.4.2
libopencv_dnn.so (libc6,x86-64) => /usr/local/lib/libopencv_dnn.so
libopencv_datasets.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_datasets.so.4.2
libopencv_datasets.so (libc6,x86-64) => /usr/local/lib/libopencv_datasets.so
libopencv_cudev.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_cudev.so.4.2
libopencv_cudev.so (libc6,x86-64) => /usr/local/lib/libopencv_cudev.so
libopencv_cudawarping.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_cudawarping.so.4.2
libopencv_cudawarping.so (libc6,x86-64) => /usr/local/lib/libopencv_cudawarping.so
libopencv_cudastereo.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_cudastereo.so.4.2
libopencv_cudastereo.so (libc6,x86-64) => /usr/local/lib/libopencv_cudastereo.so
libopencv_cudaoptflow.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_cudaoptflow.so.4.2
libopencv_cudaoptflow.so (libc6,x86-64) => /usr/local/lib/libopencv_cudaoptflow.so
libopencv_cudaobjdetect.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_cudaobjdetect.so.4.2
libopencv_cudaobjdetect.so (libc6,x86-64) => /usr/local/lib/libopencv_cudaobjdetect.so
libopencv_cudalegacy.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_cudalegacy.so.4.2
libopencv_cudalegacy.so (libc6,x86-64) => /usr/local/lib/libopencv_cudalegacy.so
libopencv_cudaimgproc.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_cudaimgproc.so.4.2
libopencv_cudaimgproc.so (libc6,x86-64) => /usr/local/lib/libopencv_cudaimgproc.so
libopencv_cudafilters.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_cudafilters.so.4.2
libopencv_cudafilters.so (libc6,x86-64) => /usr/local/lib/libopencv_cudafilters.so
libopencv_cudafeatures2d.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_cudafeatures2d.so.4.2
libopencv_cudafeatures2d.so (libc6,x86-64) => /usr/local/lib/libopencv_cudafeatures2d.so
libopencv_cudabgsegm.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_cudabgsegm.so.4.2
libopencv_cudabgsegm.so (libc6,x86-64) => /usr/local/lib/libopencv_cudabgsegm.so
libopencv_cudaarithm.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_cudaarithm.so.4.2
libopencv_cudaarithm.so (libc6,x86-64) => /usr/local/lib/libopencv_cudaarithm.so
libopencv_core.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_core.so.4.2
libopencv_core.so (libc6,x86-64) => /usr/local/lib/libopencv_core.so
libopencv_ccalib.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_ccalib.so.4.2
libopencv_ccalib.so (libc6,x86-64) => /usr/local/lib/libopencv_ccalib.so
libopencv_calib3d.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_calib3d.so.4.2
libopencv_calib3d.so (libc6,x86-64) => /usr/local/lib/libopencv_calib3d.so
libopencv_bioinspired.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_bioinspired.so.4.2
libopencv_bioinspired.so (libc6,x86-64) => /usr/local/lib/libopencv_bioinspired.so
libopencv_bgsegm.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_bgsegm.so.4.2
libopencv_bgsegm.so (libc6,x86-64) => /usr/local/lib/libopencv_bgsegm.so
libopencv_aruco.so.4.2 (libc6,x86-64) => /usr/local/lib/libopencv_aruco.so.4.2
libopencv_aruco.so (libc6,x86-64) => /usr/local/lib/libopencv_aruco.so
回答1:
Thanks talnomies. Its was build using wrong architecture. When i matched cc6.1 it works fine
cmake:
sudo cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_C_COMPILER=/usr/bin/gcc-6 -D CMAKE_INSTALL_PREFIX=/usr/local -D INSTALL_PYTHON_EXAMPLES=ON -D INSTALL_C_EXAMPLES=OFF -D WITH_TBB=ON -D WITH_CUDA=ON -D BUILD_opencv_cudacodec=OFF -D ENABLE_FAST_MATH=1 -D CUDA_FAST_MATH=1 -D WITH_CUBLAS=1 -D WITH_V4L=ON -D WITH_QT=OFF -D WITH_OPENGL=ON -D WITH_GSTREAMER=ON -D OPENCV_GENERATE_PKGCONFIG=ON -D OPENCV_PC_FILE_NAME=opencv.pc -D OPENCV_ENABLE_NONFREE=ON -D OPENCV_PYTHON3_INSTALL_PATH=~/.virtualenvs/cv/lib/python3.6/site-packages -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-4.2.0/modules -D PYTHON_EXECUTABLE=~/.virtualenvs/cv/bin/python -D BUILD_EXAMPLES=ON -D WITH_CUDNN=ON -D OPENCV_DNN_CUDA=ON -D CUDA_ARCH_BIN=6.1 -D CUDA_GENERATION=Pascal \ ..
来源:https://stackoverflow.com/questions/61317799/linking-issue-after-installation-of-nvidia-cuda-10-2-cudnn-7-5-opencv-4-2-0-o