Rocky Linux 8.5 安装带CUDA版本的Opencv4.5.5

本文详细介绍了CUDA 11.2的测试过程,包括两个GPU的性能指标,以及如何源码安装ffmpeg和opencv 4.5.5,重点展示了opencv的CUDA、TBB、FFmpeg和Python支持的配置步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

目录

一、CUDA测试

二、opencv安装

1、源码安装ffmpeg

2、安装一些依赖包

3、安装opencv


一、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

### 编译安装PHP 5.5Rocky Linux 8.5 #### 准备工作 确保系统已更新至最新状态,并安装必要的开发工具和依赖库。对于编译环境而言,GCC、Make以及其他一些辅助程序是必需的。 ```bash sudo dnf update -y sudo dnf groupinstall "Development Tools" -y sudo dnf install libxml2-devel openssl-devel bzip2-devel curl-devel libjpeg-devel libpng-devel freetype-devel gmp-devel readline-devel sqlite-devel libXpm-devel libc-client-devel libicu-devel oniguruma-devel -y ``` #### 下载PHP源码 访问官方存档页面获取指定版本的PHP源代码压缩文件[^1]。由于PHP官方网站可能不再提供如此旧版次的直接链接,建议通过互联网档案馆或其他可信渠道寻找确切资源。 假设已经找到合适的下载链接: ```bash cd /usr/local/src/ wget https://archive.php.net/php-5.5.38.tar.gz tar zxvf php-5.5.38.tar.gz cd php-5.5.38 ``` #### 配置编译选项 根据需求配置`./configure`命令参数来定制化构建过程。这里给出一个较为通用的例子作为参考: ```bash ./configure \ --prefix=/usr/local/php-5.5 \ --with-config-file-path=/etc/php-5.5 \ --enable-mbstring \ --enable-zip \ --enable-bcmath \ --enable-calendar \ --enable-exif \ --enable-ftp \ --enable-gd-jis-conv \ --enable-intl \ --enable-pcntl \ --enable-shmop \ --enable-soap \ --enable-sockets \ --enable-sysvmsg \ --enable-sysvsem \ --enable-sysvshm \ --enable-wddx \ --with-curl \ --with-freetype-dir \ --with-gd \ --with-gettext \ --with-iconv-dir \ --with-imap \ --with-imap-ssl \ --with-jpeg-dir \ --with-kerberos \ --with-libdir=lib64 \ --with-libxml-dir \ --with-mcrypt \ --with-mhash \ --with-mysql=mysqlnd \ --with-mysqli=mysqlnd \ --with-openssl \ --with-pdo-mysql=mysqlnd \ --with-png-dir \ --with-xsl \ --with-zlib ``` 请注意某些扩展模块可能会因为缺少相应的支持库而无法正常启用,在这种情况下需要额外安装这些库及其头文件。 #### 执行编译安装 一旦完成上述准备工作,则可以继续执行实际的编译操作以及最终的目标——将新编译好的PHP部署到目标位置。 ```bash make && sudo make install ``` 此步骤会消耗一定时间取决于机器性能;期间如果遇到任何错误提示,请仔细阅读报错信息并针对性解决后再尝试重新编译。 #### 完成后的设置 创建或编辑配置文件路径下的php.ini文件以适应具体的应用场景需求。通常可以从源码目录中的预定义模板复制一份过来修改即可满足大部分情况的要求。 ```bash cp php.ini-production /etc/php-5.5/php.ini ``` 最后别忘了验证一下刚装上的PHP解释器能否正常使用。 ```bash /usr/local/php-5.5/bin/php -v ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值