目录
一、CUDA测试
//找到NVIDIA_CUDA-11.2_Samples
cd NVIDIA_CUDA-11.2_Samples/
cd 1_Utilities/
cd deviceQuery
make
./deviceQuery
./deviceQuery Starting...
CUDA Device Query (Runtime API) version (CUDART static linking)
Detected 2 CUDA Capable device(s)
Device 0: "GeForce GTX 1060 6GB"
CUDA Driver Version / Runtime Version 11.2 / 11.2
CUDA Capability Major/Minor version number: 6.1
Total amount of global memory: 6078 MBytes (6373572608 bytes)
(10) Multiprocessors, (128) CUDA Cores/MP: 1280 CUDA Cores
GPU Max Clock rate: 1759 MHz (1.76 GHz)
Memory Clock rate: 4004 Mhz
Memory Bus Width: 192-bit
L2 Cache Size: 1572864 bytes
Maximum Texture Dimension Size (x,y,z) 1D=(131072), 2D=(131072, 65536), 3D=(16384, 16384, 16384)
Maximum Layered 1D Texture Size, (num) layers 1D=(32768), 2048 layers
Maximum Layered 2D Texture Size, (num) layers 2D=(32768, 32768), 2048 layers
Total amount of constant memory: 65536 bytes
Total amount of shared memory per block: 49152 bytes
Total shared memory per multiprocessor: 98304 bytes
Total number of registers available per block: 65536
Warp size: 32
Maximum number of threads per multiprocessor: 2048
Maximum number of threads per block: 1024
Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
Max dimension size of a grid size (x,y,z): (2147483647, 65535, 65535)
Maximum memory pitch: 2147483647 bytes
Texture alignment: 512 bytes
Concurrent copy and kernel execution: Yes with 2 copy engine(s)
Run time limit on kernels: No
Integrated GPU sharing Host Memory: No
Support host page-locked memory mapping: Yes
Alignment requirement for Surfaces: Yes
Device has ECC support: Disabled
Device supports Unified Addressing (UVA): Yes
Device supports Managed Memory: Yes
Device supports Compute Preemption: Yes
Supports Cooperative Kernel Launch: Yes
Supports MultiDevice Co-op Kernel Launch: Yes
Device PCI Domain ID / Bus ID / location ID: 0 / 3 / 0
Compute Mode:
< Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >
Device 1: "GeForce GTX 1060 6GB"
CUDA Driver Version / Runtime Version 11.2 / 11.2
CUDA Capability Major/Minor version number: 6.1
Total amount of global memory: 6078 MBytes (6373572608 bytes)
(10) Multiprocessors, (128) CUDA Cores/MP: 1280 CUDA Cores
GPU Max Clock rate: 1759 MHz (1.76 GHz)
Memory Clock rate: 4004 Mhz
Memory Bus Width: 192-bit
L2 Cache Size: 1572864 bytes
Maximum Texture Dimension Size (x,y,z) 1D=(131072), 2D=(131072, 65536), 3D=(16384, 16384, 16384)
Maximum Layered 1D Texture Size, (num) layers 1D=(32768), 2048 layers
Maximum Layered 2D Texture Size, (num) layers 2D=(32768, 32768), 2048 layers
Total amount of constant memory: 65536 bytes
Total amount of shared memory per block: 49152 bytes
Total shared memory per multiprocessor: 98304 bytes
Total number of registers available per block: 65536
Warp size: 32
Maximum number of threads per multiprocessor: 2048
Maximum number of threads per block: 1024
Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
Max dimension size of a grid size (x,y,z): (2147483647, 65535, 65535)
Maximum memory pitch: 2147483647 bytes
Texture alignment: 512 bytes
Concurrent copy and kernel execution: Yes with 2 copy engine(s)
Run time limit on kernels: No
Integrated GPU sharing Host Memory: No
Support host page-locked memory mapping: Yes
Alignment requirement for Surfaces: Yes
Device has ECC support: Disabled
Device supports Unified Addressing (UVA): Yes
Device supports Managed Memory: Yes
Device supports Compute Preemption: Yes
Supports Cooperative Kernel Launch: Yes
Supports MultiDevice Co-op Kernel Launch: Yes
Device PCI Domain ID / Bus ID / location ID: 0 / 130 / 0
Compute Mode:
< Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >
> Peer access from GeForce GTX 1060 6GB (GPU0) -> GeForce GTX 1060 6GB (GPU1) : No
> Peer access from GeForce GTX 1060 6GB (GPU1) -> GeForce GTX 1060 6GB (GPU0) : No
deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 11.2, CUDA Runtime Version = 11.2, NumDevs = 2
Result = PASS
二、opencv安装
1、源码安装ffmpeg
yum install cmake gcc gcc-c++
wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
tar xf yasm-1.3.0.tar.gz
cd yasm-1.3.0/
./configure --prefix=/usr/local
make -j8
make install
wget https://johnvansickle.com/ffmpeg/release-source/ffmpeg-4.1.tar.xz
tar xf ffmpeg-4.1.tar.xz
cd ffmpeg-4.1/
./configure --enable-shared --prefix=/opt/ffmpeg
make -j8
make install
echo "/opt/ffmpeg/lib" >> /etc/ld.so.conf
ldconfig
(
ldconfig: /usr/local/cuda-11.2/targets/x86_64-linux/lib/libcudnn_ops_train.so.8 不是符号链接
ldconfig: /usr/local/cuda-11.2/targets/x86_64-linux/lib/libcudnn_ops_infer.so.8 不是符号链接
ldconfig: /usr/local/cuda-11.2/targets/x86_64-linux/lib/libcudnn_cnn_train.so.8 不是符号链接
ldconfig: /usr/local/cuda-11.2/targets/x86_64-linux/lib/libcudnn.so.8 不是符号链接
ldconfig: /usr/local/cuda-11.2/targets/x86_64-linux/lib/libcudnn_cnn_infer.so.8 不是符号链接
ldconfig: /usr/local/cuda-11.2/targets/x86_64-linux/lib/libcudnn_adv_train.so.8 不是符号链接
ldconfig: /usr/local/cuda-11.2/targets/x86_64-linux/lib/libcudnn_adv_infer.so.8 不是符号链接
)
//均如下解决:
mv libcudnn_ops_infer.so libcudnn_ops_infer.so.bk
mv libcudnn_ops_infer.so.8 libcudnn_ops_infer.so.8.bk
ln -sf libcudnn_ops_infer.so.8.1.1 libcudnn_ops_infer.so.8
ln -sf libcudnn_ops_infer.so.8 libcudnn_ops_infer.so
配置环境变量
vi /etc/profile
//末尾添加(已修正):
export PATH=/opt/ffmpeg/bin:$PATH
//使配置生效
source /etc/profile
(设置环境变量出了问题,导致su ls等常用命令不能用:
由于无法使用常用命令,故直接在shell下不能够修改,这时就需要设置临时环境变量PATH。export PATH="/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin:/bin:/sbin"
然后就可以正常使用命令了,这时就要修改导致PATH出问题的文件。由于我是修改的/etc/profile配置文件,所以要进去重新修改。修改之后为了使其生效,需要输入source /etc/profile,或者重启。)
2、安装一些依赖包
//替换阿里Yum源
sed -e 's|^mirrorlist=|#mirrorlist=|g' -e 's|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl=https://mirrors.aliyun.com/rockylinux|g' -i.bak /etc/yum.repos.d/Rocky-*.repo
//makecache一下
dnf makecache
yum install -y cmake gcc gtk2-devel unzip
yum install -y libwebp-devel libjpeg-turbo-devel
yum install -y freeglut-devel mesa-libGL mesa-libGL-devel libtiff-devel
yum install -y tbb-devel
yum install -y boost boost-thread boost-devel
yum install -y gtk+-devel gimp-devel gimp-devel-tools gimp-help-browser zlib-devel libtiff-devel libjpeg-devel libpng-devel gstreamer-devel libraw1394-devel libdc1394-devel jasper-devel jasper-utils swig python libtool nasm libv4l-devel libv4l-devel python-devel numpy gstreamer-plugins-base-devel gtk2-devel gtk2-devel-docs libavcodec-devel libavformat-devel libswscale-devel libavutil-devel libeigen3-devel libtbb-devel libtiff-dev libavformat-devel libpq-devel libxine2-devel libglew-devel libtiff5-devel gstreamer-plugins-base-devel libjpeg-turbo-devel jasper-devel openexr-devel tbb-devel --skip-broken
3、安装opencv
wget https://github.com/opencv/opencv/archive/4.5.5.zip
unzip opencv-4.5.5.zip
mkdir opencv_build
安装包放置目录如下:
/opencv
/opencv-4.5.1 # opencv 源码目录
/opencv_contrib-4.5.1 # opencv_contrib 源码目录
/opencv_build # opencv 编译结果目录
cd opencv_build
cmake 参数如下。
make -j30
make install
cmake的内容:
CUDA_ARCH_BIN: gpu 算力,参考:[https://developer.nvidia.com/zh-cn/cuda-gpus]
cmake \
-D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_C_COMPILER=/usr/bin/gcc \
-D CMAKE_INSTALL_PREFIX=$(python3 -c "import sys; print(sys.prefix)") \
-D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib-4.5.5/modules \
-D CUDA_CUDA_LIBRARY=/usr/local/cuda-11.2/targets/x86_64-linux/lib/stubs/libcuda.so \
-D CUDA_ARCH_BIN=6.1 \
-D CUDA_ARCH_PTX="" \
-D WITH_CUDA=ON \
-D WITH_TBB=ON \
-D WITH_FFMPEG=ON \
-D BUILD_PYTHON_SUPPORT=ON \
-D BUILD_NEW_PYTHON_SUPPORT=ON \
-D BUILD_OPENCV_PYTHON3=ON \
-D PYTHON3_INCLUDE_DIR=$(python3 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \
-D PYTHON3_PACKAGES_PATH=$(python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") \
-D WITH_V4L=ON \
-D INSTALL_C_EXAMPLES=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D PYTHON3_EXECUTABLE=$(which python3) \
-D BUILD_EXAMPLES=ON \
-D WITH_QT=ON \
-D WITH_GSTREAMER=ON \
-D WITH_OPENGL=ON \
-D ENABLE_FAST_MATH=1 \
-D CUDA_FAST_MATH=1 \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D OPENCV_PC_FILE_NAME=opencv.pc \
-D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda \
-D CMAKE_LIBRARY_PATH=/usr/local/cuda-11.2/targets/x86_64-linux/lib/stubs \
-D WITH_CUBLAS=ON \
-D WITH_NVCUVID=ON \
-D BUILD_opencv_cudacodec=ON \
-D OPENCV_DNN_CUDA=ON \
-D WITH_CUDNN=ON \
-D OPENCV_ENABLE_NONFREE=ON\
-D WITH_GSTREAMER=ON \
-D BUILD_EXAMPLES=ON \
../opencv-4.5.5