OpenCV编译C++测试程序获取CUDA设备信息
2026-04-15 来源:EEWorld 论坛
OpenCV编译C++测试程序获取CUDA设备信息
本文介绍如何编译一个OpenCV C++测试程序,以获取CUDA设备信息。测试代码基于OpenCV库,使用g++编译器进行编译,并运行在支持CUDA的设备上。
测试代码
首先,创建一个C++源文件(例如test-cv.cpp),包含以下代码:
#include <opencv2/opencv.hpp>
#include <opencv2/cudaimgproc.hpp>
#include <iostream>
using namespace cv;
using namespace cv::cuda;
using namespace std;
int main(int argc, char **argv) {
cuda::printCudaDeviceInfo(cuda::getDevice());
int cnt = getCudaEnabledDeviceCount();
printf("Now get CUDA device count:%d \r\n", cnt);
return 0;
}编译步骤
手动编译的OpenCV安装目录在/usr/local下(根据CMake参数 -DCMAKE_INSTALL_PREFIX=/usr/local 设定)。因此,使用g++编译时需要指定头文件目录和动态库位置:
- 使用
-I参数指定OpenCV头文件目录,例如-I/usr/local/include/opencv4。 - 使用
-L参数指定动态库位置,例如-L/usr/local/lib。 - 链接必要的OpenCV库,基础库为
-lopencv_core,其他可能用到的库包括-lopencv_highgui、-lopencv_imgproc等。
编译命令示例:
g++ test-cv.cpp -o test-cv -I/usr/local/include/opencv4 -L/usr/local/lib -lopencv_core运行结果
运行编译后的程序,输出CUDA设备信息:
./test-cv
*** CUDA Device Query (Runtime API) version (CUDART static linking) ***
Device count: 1
Device 0: "Orin"
CUDA Driver Version / Runtime Version 11.40 / 11.40
CUDA Capability Major/Minor version number: 8.7
Total amount of global memory: 7471 MBytes (7834177536 bytes)
GPU Clock Speed: 0.62 GHz
Max Texture Dimension Size (x,y,z) 1D=(131072), 2D=(131072,65536), 3D=(16384,16384,16384)
Max Layered Texture Size (dim) x layers 1D=(32768) x 2048, 2D=(32768,32768) x 2048
Total amount of constant memory: 65536 bytes
Total amount of shared memory per block: 49152 bytes
Total number of registers available per block: 65536
Warp size: 32
Maximum number of threads per block: 1024
Maximum sizes of each dimension of a block: 1024 x 1024 x 64
Maximum sizes of each dimension of a grid: 2147483647 x 65535 x 65535
Maximum memory pitch: 2147483647 bytes
Texture alignment: 512 bytes
Concurrent copy and execution: Yes with 2 copy engine(s)
Run time limit on kernels: No
Integrated GPU sharing Host Memory: Yes
Support host page-locked memory mapping: Yes
Concurrent kernel execution: Yes
Alignment requirement for Surfaces: Yes
Device has ECC support enabled: No
Device is using TCC driver mode: No
Device supports Unified Addressing (UVA): Yes
Device PCI Bus ID / PCI location ID: 0 / 0
Compute Mode:
Default (multiple host threads can use ::cudaSetDevice() with device simultaneously)
deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 11.40, CUDA Runtime Version = 11.40, NumDevs = 1
Now get CUDA device count:1以上内容根据原帖子整理,保留了核心逻辑和代码示例。更多详细步骤、视频讲解和其他资源,请阅读 原帖子:OpenCV编译C++测试程序获取cuda设备信息。
原帖子内容来源:https://bbs.eeworld.com.cn/thread-1270395-1-1.html
相关文章
- Mujoco仿真相机内参标定方法详解
- RV1106平台InspireFace人脸识别库的交叉编译与部署实践
- RV1106开发板驱动ST7789屏幕实现手写数字识别
- Jetson Orin Nano使用OpenCV获取视频帧率和帧数的方法
- Jetson Orin Nano安装OpenCV带CUDA加速版本完整教程
- OpenCV读取摄像头窗口变大卡顿解决方法
- RISC-V MUSE Pi Pro使用OpenCV和Gstreamer实时显示CSI摄像头教程
- iTOP4412开发板-QtE-opencv-UVC摄像头测试文档
- 如何在米尔RK3576开发板上板端编译OpenCV并搭建应用
- Jetson GPU Burn烤机测试与PTX编程详解
- 构建具有网络弹性的嵌入式系统:来自行业领袖的洞见
- 矽典微ONELAB开发系列:为毫米波算法开发者打造的全栈工具链
- 从进迭时空K3看RISC-V CPU与Imagination GPU协同: 如何构建高性能SoC能力
- RISC-V中断处理复杂原因与ARM对比分析
- Micropython实现天气预报和闹钟项目详解
- 2025年度回顾:珍藏我们的技术高光时刻
- 消息称谷歌正与 Marvell 洽谈合作开发两款 AI 芯片,挑战英伟达霸主地位
- 桌面天气预报小时钟制作教程:基于Raspberry Pi Pico和MicroPython
- Adafruit ESP32-S3 TFT Feather Follow me第2期任务速通教学
最新频道文章




