Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Using OpenCV 3.0 UMat on Odroid XU3

Hi all, I am trying comparing the performance between OpenCV 3.0 + OpenCL 1.1 and pure OpenCL1.1. I am encountering some real weird problems while implement performance test by OpenCV 3.0 OpenCL API.

Here is my platform and devices info which are derived by OpenCL1.1:

PlatformCount: 1
1. Device: Mali-T628
 1.1 Hardware version: OpenCL 1.1
 1.2 Software version: 1.1
 1.3 OpenCL C version: OpenCL C 1.1
 1.4 Parallel compute units: 4
2. Device: Mali-T628
 2.1 Hardware version: OpenCL 1.1
 2.2 Software version: 1.1
 2.3 OpenCL C version: OpenCL C 1.1
 2.4 Parallel compute units: 2

So I am pretty sure my device is supported by OpenCL 1.1

Hereafter, I am trying to get my device info through OpenCV3.0:

#include <opencv2/core/ocl.hpp>
#include <opencv2/opencv.hpp>
#include <iostream>
#include <string>

#define USE_OPENCL

double tic,toc;

int main(int argc, const char* argv[])
{
    if(argc < 0)
    {
        std::cerr << "Usage : UMatVideoSample <input video file>" << std::endl;
        return -1;
    }

    cv::VideoCapture reader("/oshare/test_02.avi");
    if(!reader.isOpened())
    {
        std::cerr << "Can't open input video file" << std::endl;
        return -1;
    }

    cv::Mat frame;
    cv::UMat gray;
    cv::UMat blur;
    cv::UMat edge;


#ifdef USE_OPENCL
    cv::ocl::setUseOpenCL(true);
#else
    cv::ocl::setUseOpenCL(false);
#endif

//Derive platform and devices info
    if(cv::ocl::haveOpenCL()){
            printf("OCL is avalible\n");

        cv::ocl::Device p;
        printf("Device avalible: %s\n" ,p.available()?"true":"false");
        printf("Use OCL: %s\n" ,cv::ocl::useOpenCL?"true":"false");
        printf("version: %d\n", p.deviceVersionMajor());
        std::cout<<"OCL version: "<< p.OpenCLVersion().c_str()<<std::endl; 

        cv::ocl::PlatformInfo plat;
        int d;
        printf("Device number: %d\n", plat.deviceNumber());
        std::string str = cv::String(plat.name());
        std::cout<<"platform name: "<<str<<std::endl;
        printf("Is platform name empty: %s\n", plat.name().empty()?"true":"false");
    }

//Do some processing and watch
    for(int i = 1;; ++i)
    {
        reader >> frame;
        if(frame.empty())
        {
            std::cout << "Stop" << std::endl;
            break;
        }

        tic =  (double)cv::getTickCount();
        cv::cvtColor(frame, gray, cv::COLOR_BGR2GRAY);
        //cv::GaussianBlur(gray, blur, cv::Size(1,1), 1.5, 1.5);
        cv::Canny(blur, edge, 0, 30, 3);
        toc = (double)cv::getTickCount();
        std::cout << "[" << i << "] " << double((toc-tic)/cv::getTickFrequency()) << "(ms)" << std::endl;
    }

    return 0;
}

For cv::ocl::setUseOpenCL(true), I got following results:

OCL is avalible
Device avalible: false
Use OCL: true
version: 0
OCL version:
Device number: 0
platform name:
Is platform name empty: true
[1] 0.00115638(ms)
[2] 0.00041775(ms)
[3] 0.000372(ms)
[4] 0.00036825(ms)
[5] 0.000367667(ms)
[6] 0.000366334(ms)
[7] 0.000375417(ms)
[8] 0.000366709(ms)
[9] 0.000364875(ms)
[10] 0.000431208(ms)

For cv::ocl::setUseOpenCL(false), I got following results:

OCL is avalible
Device avalible: false
Use OCL: true
version: 0
OCL version:
Device number: 0
platform name:
Is platform name empty: true
[1] 0.00119063(ms)
[2] 0.000422458(ms)
[3] 0.000380375(ms)
[4] 0.000369459(ms)
[5] 0.000371417(ms)
[6] 0.000372333(ms)
[7] 0.000364792(ms)
[8] 0.000364208(ms)
[9] 0.000367334(ms)
[10] 0.0003565(ms)

As you can see, the results are merely no differences no matter cv::ocl::setUseOpenCL(true) or cv::ocl::setUseOpenCL(false). Moreover, cv::ocl::useOpenCL is always true.

Please let me clarify my question:

  1. Is there any problem in my program?
  2. Why did I get the same results by setting cv::ocl::setUseOpenCL(true)andcv::ocl::setUseOpenCL(false)`?
  3. Is there any way to monitor GPU through OpenCV3.0 OpenCL API or others?

Using OpenCV 3.0 UMat on Odroid XU3

Hi all, I am trying comparing the performance between OpenCV 3.0 + OpenCL 1.1 and pure OpenCL1.1. to use OpenCV3.0 OpenCL API on my Odroid XU3. Unfortunately, I am encountering some real weird problems while implement performance test by OpenCV 3.0 OpenCL API.problems.

Here The following is my platform and devices info information which are is derived by OpenCL1.1:OpenCL 1.1:

PlatformCount: 1
1. Device: Mali-T628
 1.1 Hardware version: OpenCL 1.1
 1.2 Software version: 1.1
 1.3 OpenCL C version: OpenCL C 1.1
 1.4 Parallel compute units: 4
2. Device: Mali-T628
 2.1 Hardware version: OpenCL 1.1
 2.2 Software version: 1.1
 2.3 OpenCL C version: OpenCL C 1.1
 2.4 Parallel compute units: 2

So I am pretty sure my device is supported tried to using do some performance test on Odroid by OpenCL 1.1

Hereafter, OpenCV3.0 OpenCL API, so I am trying to get my device info through OpenCV3.0:wrote following code:

#include <opencv2/core/ocl.hpp>
#include <opencv2/opencv.hpp>
#include <iostream>
#include <string>

#define USE_OPENCL

#include <iterator>
#include <opencv2/opencv.hpp>
#include <opencv2/core/ocl.hpp>

using namespace std;

int main(){
     if (!cv::ocl::haveOpenCL())
        {
            cout << "OpenCL is not avaiable..." << endl;
            return 0;
        }
        cv::ocl::Context context;
        if (!context.create(cv::ocl::Device::TYPE_GPU))
        {
            cout << "Failed creating the context..." << endl;
            return 0;
        }

    // In OpenCV 3.0.0 beta, only a single device is detected.
        cout << context.ndevices() << " GPU devices are detected." << endl;


    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;
    break;
        }
    double tic,toc;

int main(int argc, const char* argv[])
{
    if(argc < 0)
    {
        std::cerr << "Usage : UMatVideoSample <input video file>" << std::endl;
        return -1;
    }

    cv::VideoCapture reader("/oshare/test_02.avi");
    if(!reader.isOpened())
    {
        std::cerr << "Can't open input video file" << std::endl;
        return -1;
    }
tic, toc;

    cv::Mat frame;
mat_src = cv::imread("img_1.png", 0);
    cv::Mat mat_dst;

    cv::UMat gray;
umat_src = mat_src.getUMat(cv::ACCESS_READ, cv::USAGE_ALLOCATE_DEVICE_MEMORY);
    cv::UMat blur;
    cv::UMat edge;


#ifdef USE_OPENCL
    cv::ocl::setUseOpenCL(true);
#else
    cv::ocl::setUseOpenCL(false);
#endif

//Derive platform and devices info
    if(cv::ocl::haveOpenCL()){
            printf("OCL is avalible\n");

        cv::ocl::Device p;
        printf("Device avalible: %s\n" ,p.available()?"true":"false");
        printf("Use OCL: %s\n" ,cv::ocl::useOpenCL?"true":"false");
        printf("version: %d\n", p.deviceVersionMajor());
        std::cout<<"OCL version: "<< p.OpenCLVersion().c_str()<<std::endl; 

        cv::ocl::PlatformInfo plat;
        int d;
        printf("Device number: %d\n", plat.deviceNumber());
        std::string str umat_dst;

    tic = cv::String(plat.name());
        std::cout<<"platform name: "<<str<<std::endl;
        printf("Is platform name empty: %s\n", plat.name().empty()?"true":"false");
    }

//Do some processing and watch
(double)cv::getTickCount();
    for(int i = 1;; ++i)
    {
        reader >> frame;
        if(frame.empty())
        {
            std::cout << "Stop" << std::endl;
            break;
    0 ; i<1000; i++){
        cv::Canny(umat_src, umat_dst, 0, 50);
    }

        tic =  (double)cv::getTickCount();
        cv::cvtColor(frame, gray, cv::COLOR_BGR2GRAY);
        //cv::GaussianBlur(gray, blur, cv::Size(1,1), 1.5, 1.5);
        cv::Canny(blur, edge, 0, 30, 3);
        toc = (double)cv::getTickCount();
        std::cout << "[" << cout<<"UMat X Canny Time: "<<(double)((toc-tic)/cv::getTickFrequency())<<endl;

    tic = (double)cv::getTickCount();
        for(int i << "] " << double((toc-tic)/cv::getTickFrequency()) << "(ms)" << std::endl;
= 0 ; i<1000; i++){
                cv::Canny(mat_src, mat_dst, 0, 50);
        }
        toc = (double)cv::getTickCount();
        cout<<"Mat X Canny Time: "<<(double)((toc-tic)/cv::getTickFrequency())<<endl;

    return 0;
 }

For cv::ocl::setUseOpenCL(true), and I got following results:results on my Odroid:

OCL is avalible
Device avalible: false
Use OCL: true
version: 0
OCL version:
Device number: 0
platform name:
Is platform 1 GPU devices are detected.
name empty: true
[1] 0.00115638(ms)
[2] 0.00041775(ms)
[3] 0.000372(ms)
[4] 0.00036825(ms)
[5] 0.000367667(ms)
[6] 0.000366334(ms)
[7] 0.000375417(ms)
[8] 0.000366709(ms)
[9] 0.000364875(ms)
[10] 0.000431208(ms)

For cv::ocl::setUseOpenCL(false), I got following results:

OCL is avalible
Device avalible: false
Use OCL: true
version: 0
OCL version:
Device number: 0
platform name:
Is platform name empty: true
[1] 0.00119063(ms)
[2] 0.000422458(ms)
[3] 0.000380375(ms)
[4] 0.000369459(ms)
[5] 0.000371417(ms)
[6] 0.000372333(ms)
[7] 0.000364792(ms)
[8] 0.000364208(ms)
[9] 0.000367334(ms)
[10] 0.0003565(ms)
                : Mali-T628
available            : 1
imageSupport         : 1
OpenCL_C_Version     : OpenCL C 1.1
UMat X Canny Time: 44.6943
Mat X Canny Time: 44.0222

As you can see, the results are merely no differences no matter whether use UMat or not. To ensure UMat really did some effect to performance, I try the exactly same code on my PC, and I got following results:

cv::ocl::setUseOpenCL(true)1 GPU devices are detected.
name                 : Intel(R) HD Graphics 4600
available            : 1
imageSupport         : 1
OpenCL_C_Version     : OpenCL C 1.2

UMat X Canny Time: 4.8207
Mat X Canny Time: 11.6929
 or cv::ocl::setUseOpenCL(false). Moreover, cv::ocl::useOpenCL is always true.

The result showed that performance was dramatically improved by OpenCL.

Please let me clarify my question:So, why OpenCL API not work on Odroid? Is it related to the version of OpenCL?

  1. Is there any problem in my program?
  2. Why did I get the same results by setting cv::ocl::setUseOpenCL(true)andcv::ocl::setUseOpenCL(false)`?
  3. Is there any way to monitor GPU through OpenCV3.0 OpenCL API or others?