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:
- Is there any problem in my program?
- Why did I get the same results by setting cv::ocl::setUseOpenCL(true)
and
cv::ocl::setUseOpenCL(false)`? - Is there any way to monitor GPU through OpenCV3.0 OpenCL API or others?