Using OpenCV 3.0 UMat on Odroid XU3

asked 2015-10-06 21:40:13 -0600

JesseCh gravatar image

updated 2015-10-07 02:51:25 -0600

Hi all, I am trying to use OpenCV3.0 OpenCL API on my Odroid XU3. Unfortunately, I am encountering some real weird problems.

The following is my devices information which is derived by 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

I tried to using do some performance test on Odroid by OpenCV3.0 OpenCL API, so I wrote following code:

#include <iostream>
#include <string>
#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;

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

    cv::UMat umat_src = mat_src.getUMat(cv::ACCESS_READ, cv::USAGE_ALLOCATE_DEVICE_MEMORY);
    cv::UMat umat_dst;

    tic = (double)cv::getTickCount();
    for(int i = 0 ; i<1000; i++){
        cv::Canny(umat_src, umat_dst, 0, 50);
    }
    toc = (double)cv::getTickCount();
    cout<<"UMat X Canny Time: "<<(double)((toc-tic)/cv::getTickFrequency())<<endl;

    tic = (double)cv::getTickCount();
        for(int i = 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;


}

and I got following results on my Odroid:

1 GPU devices are detected.
name                 : 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 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:

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

The result showed that performance was dramatically improved by OpenCL.

So, why OpenCL API not work on Odroid? Is it related to the version of OpenCL?

edit retag flag offensive close merge delete

Comments

Did you build OpenCV from source with OpenCL enabled? Afaik OpenCL embedded is not the same as OpenCL for desktops, and the first one is not supported in OpenCV I thimk. Read that somewhere in another topic :)

StevenPuttemans gravatar imageStevenPuttemans ( 2015-10-07 05:46:23 -0600 )edit

Hi Steven, thanks for your reply. I did build OpenCV3 with OpenCL enable. In the other way, I think OpenCL on Odroid is supported by OpenCL, because I can derived devices information by OpenCV API. Am I correct or not?

JesseCh gravatar imageJesseCh ( 2015-10-07 20:00:43 -0600 )edit

Well what I do know about it is that the basic OpenCL functionality is the same between the normal and the embedded version, but deep down specifics are different, meaning that some functions will do different things. But we might need a more experienced person on the matter.

StevenPuttemans gravatar imageStevenPuttemans ( 2015-10-08 03:40:19 -0600 )edit
1

Ok, thanks for your help. I will keep working on this, and post my answer here if I got one.

JesseCh gravatar imageJesseCh ( 2015-10-11 21:36:37 -0600 )edit