Problem with opencv+opencl odroid

asked 2017-01-25 05:52:13 -0500

vasu12360 gravatar image

I am working on odroid ux4 which comprise of Mali-T628.

When I run my simple canny edge detection algorithum for cpu and opencl on my laptop opencl came to be 2-2.5 times faster than cpu version.

However when i run the same code on odroid opencl code is much slower than cpu.

This is not only with the case of canny but also with many other algorithums like haar detection and many more.

can anyone tell me what can be the problem and how to solve it.

code:

#include <iostream>
#include <string>
#include <iterator>
//Program for testing CPU and openCL performance when canny algorithum is applied on the Image.
/*

1 GPU devices are detected.
name                 : Mali-T628
available            : 1
imageSupport         : 1
OpenCL_C_Version     : OpenCL C 1.1 

UMat X Canny Time: 5.28345
Mat X Canny Time: 4.39179

*/

#include <opencv2/opencv.hpp>
#include <opencv2/core/ocl.hpp>
//#include <CL/cl.h>
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;
        }

//   cv::ocl::setUseOpenCL(true);
    // 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;
        }
 //   cv::ocl::Device(context.device(0));
    double tic, toc;

    cv::Mat mat_src = cv::imread("/home/vasu/opencv_opencl/DSC_0231.JPG", 0);
    cv::Mat mat_dst;
    cv::UMat umat_src = mat_src.getUMat(cv::ACCESS_READ, cv::USAGE_ALLOCATE_DEVICE_MEMORY);
    cv::UMat umat_dst;
if(!mat_src.data)
{
cout<<"no data available";
}
else
{
    cv::imshow("Input",mat_src);
    cv::waitKey(0);
}

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


}
edit retag flag offensive close merge delete