OPENCV:实际启用了OpenCL

OpenCV: is OpenCL actually enabled?

本文关键字:OpenCL 启用 OPENCV      更新时间:2023-10-16

我正在尝试使用OpenCL加快缝合算法的特征的研究。我正在使用此处提供的示例的代码:https://github.com/opencv/opencv/blob/master/master/samples/cpp/stitching_detailed.cpp我在网上读到,我唯一要做的就是将垫子更改为UMAT。我做到了。

但是,我不确定我的代码实际上正在使用OpenCL。

  • 首先:我正在研究Ubuntu 16.04使用相似之处的虚拟机MacBook Pro上的桌面。所以OpenCL支持的唯一设备将是CPU(无GPU(。我安装了正确的驱动程序,SDK等,CPU应该正确工作。您可以在下面的Ubuntu Shell中看到命令" Clinfo"的结果。与CPU合作,我不期望提高性能。我的计划只是为了解决我的虚拟机器并将代码部署在真正的Ubuntu机器。
  • 第二:代码没有改进(如预期,见上文(。实际上,所需的时间似乎是相同的。这样对吗?我的意思是,我知道我仍在CPU上工作,但我期望有一些差异。此外,查看使用grof and gprof2dot介绍的呼叫图,没有差异(对于从未听说过GPROF的人,这只是一个代码profiler,可以生成一个呼叫图表的呼叫图:功能调用其他功能,依此类推(。是否可以?有或没有OpenCL的OpenCV应该致电恰好相同的函数?

我如何确保代码实际上与OpenCL一起使用?我在线阅读了OpenCL上的功能查找的一些错误,因此我想检查一下自己。而且,显然,我想工作和编辑代码,这只是开始。

我正在使用此代码检查OpenCL是否在工作:

void checkOpenCL() {
    if (!cv::ocl::haveOpenCL())
    {
        cout << "OpenCL is not available..." << endl;
        //return;
    }
    cv::ocl::Context context;
    if (!context.create(cv::ocl::Device::TYPE_ALL))
    {
        cout << "Failed creating the context..." << endl;
        //return;
    }
    cout << context.ndevices() << " CPU devices are detected." << endl; //This bit provides an overview of the OpenCL devices you have in your computer
    for (int i = 0; i < context.ndevices(); i++)
    {
        cv::ocl::Device device = context.device(i);
        cout << "name:              " << device.name() << endl;
        cout << "available:         " << device.available() << endl;
        cout << "imageSupport:      " << device.imageSupport() << endl;
        cout << "OpenCL_C_Version:  " << device.OpenCL_C_Version() << endl;
        cout << endl;
    }
    cv::ocl::Device(context.device(0)); //Here is where you change which GPU to use (e.g. 0 or 1)
}

它打印:

1 CPU devices are detected.
name:              Intel(R) Core(TM) i7-4850HQ CPU @ 2.30GHz
available:         1
imageSupport:      1
OpenCL_C_Version:  OpenCL C 1.2 

在Ubuntu Shell报告中运行Clinfo

Number of platforms                               1
  Platform Name                                   Intel(R) OpenCL
  Platform Vendor                                 Intel(R) Corporation
  Platform Version                                OpenCL 1.2 LINUX
  Platform Profile                                FULL_PROFILE
  Platform Extensions                             cl_khr_icd cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_byte_addressable_store cl_khr_depth_images cl_khr_3d_image_writes cl_intel_exec_by_local_thread cl_khr_spir cl_khr_fp64 
  Platform Extensions function suffix             INTEL
  Platform Name                                   Intel(R) OpenCL
Number of devices                                 1
  Device Name                                     Intel(R) Core(TM) i7-4850HQ CPU @ 2.30GHz
  Device Vendor                                   Intel(R) Corporation
  Device Vendor ID                                0x8086
  Device Version                                  OpenCL 1.2 (Build 25)
  Driver Version                                  1.2.0.25
  Device OpenCL C Version                         OpenCL C 1.2 
  Device Type                                     CPU
  Device Profile                                  FULL_PROFILE
  Max compute units                               4
  Max clock frequency                             2300MHz
  Device Partition                                (core)
    Max number of sub-devices                     4
    Supported partition types                     by counts, equally, by names (Intel)
  Max work item dimensions                        3
  Max work item sizes                             8192x8192x8192
  Max work group size                             8192
  Preferred work group size multiple              128
  Preferred / native vector sizes                 
    char                                                 1 / 32      
    short                                                1 / 16      
    int                                                  1 / 8       
    long                                                 1 / 4       
    half                                                 0 / 0        (n/a)
    float                                                1 / 8       
    double                                               1 / 4        (cl_khr_fp64)
  Half-precision Floating-point support           (n/a)
  Single-precision Floating-point support         (core)
    Denormals                                     Yes
    Infinity and NANs                             Yes
    Round to nearest                              Yes
    Round to zero                                 No
    Round to infinity                             No
    IEEE754-2008 fused multiply-add               No
    Support is emulated in software               No
    Correctly-rounded divide and sqrt operations  No
  Double-precision Floating-point support         (cl_khr_fp64)
    Denormals                                     Yes
    Infinity and NANs                             Yes
    Round to nearest                              Yes
    Round to zero                                 Yes
    Round to infinity                             Yes
    IEEE754-2008 fused multiply-add               Yes
    Support is emulated in software               No
    Correctly-rounded divide and sqrt operations  No
  Address bits                                    64, Little-Endian
  Global memory size                              6103834624 (5.685GiB)
  Error Correction support                        No
  Max memory allocation                           1525958656 (1.421GiB)
  Unified memory for Host and Device              Yes
  Minimum alignment for any data type             128 bytes
  Alignment of base address                       1024 bits (128 bytes)
  Global Memory cache type                        Read/Write
  Global Memory cache size                        262144
  Global Memory cache line                        64 bytes
  Image support                                   Yes
    Max number of samplers per kernel             480
    Max size for 1D images from buffer            95372416 pixels
    Max 1D or 2D image array size                 2048 images
    Max 2D image size                             16384x16384 pixels
    Max 3D image size                             2048x2048x2048 pixels
    Max number of read image args                 480
    Max number of write image args                480
  Local memory type                               Global
  Local memory size                               32768 (32KiB)
  Max constant buffer size                        131072 (128KiB)
  Max number of constant args                     480
  Max size of kernel argument                     3840 (3.75KiB)
  Queue properties                                
    Out-of-order execution                        Yes
    Profiling                                     Yes
    Local thread execution (Intel)                Yes
  Prefer user sync for interop                    No
  Profiling timer resolution                      1ns
  Execution capabilities                          
    Run OpenCL kernels                            Yes
    Run native kernels                            Yes
    SPIR versions                                 1.2
  printf() buffer size                            1048576 (1024KiB)
  Built-in kernels                                
  Device Available                                Yes
  Compiler Available                              Yes
  Linker Available                                Yes
  Device Extensions                               cl_khr_icd cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_byte_addressable_store cl_khr_depth_images cl_khr_3d_image_writes cl_intel_exec_by_local_thread cl_khr_spir cl_khr_fp64 
NULL platform behavior
  clGetPlatformInfo(NULL, CL_PLATFORM_NAME, ...)  No platform
  clGetDeviceIDs(NULL, CL_DEVICE_TYPE_ALL, ...)   No platform
  clCreateContext(NULL, ...) [default]            No platform
  clCreateContext(NULL, ...) [other]              Success [INTEL]
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_CPU)  No platform
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_GPU)  No platform
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_ACCELERATOR)  No platform
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_CUSTOM)  No platform
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_ALL)  No platform

编译并从openCV的t-api文件夹中运行 facedetect.cpp,它将告诉您是否已打开/opencl,在渲染的窗口上显示。

这是运行命令的方法:

./ufacedetect --cascade=/home/user/opencv/data/haarcascades/haarcascade_frontalface_alt.xml /dev/video5 --scale=1.3