This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Any info on OpenCL for Tinker
#11
(01-12-2018, 10:07 AM)unskulledman Wrote:
(01-12-2018, 02:29 AM)cathy_chuang Wrote: Hi rtisys,

RK3288 support OpenCL 1.1 not 1.2. You can refer to this site: https://en.wikipedia.org/wiki/Rockchip_RK3288
The stub libOpenCL.a provide an interface that can dynamic link the opencl library in different platform(Apple, Android, Linux, Win32). So it's fine that use the libOpenCL.so on the Tinker OS directly without the stub.

1. Copy the CL directory from https://github.com/krrishnarraj/libopencl-stub to path /usr/include/
2. Add -lOpenCL as one of flag to compile your opencl program on Tinker Board
  ex:
      $ g++ opencl_test.cpp  -o opencl_test -lOpenCL

I thought that the Mali-T760 MP4 GPU of the Tinker Board supported OpenCL 1.1 and 1.2 full profile? 
I used the hardware acceleration feature of the OpenCV library (which requires OpenCL 1.2 full profile) and it works.

link: https://developer.arm.com/products/graph...i-t760-gpu

Hi unskulledman,

After confirming with the vendor, we konw that RK3288 does support to OpenCL 1.2 Full profile.
Thank you for your feedback.
Reply
#12
(01-05-2018, 12:14 PM)unskulledman Wrote: I have been running OpenCV in combination with OpenCL and it works like a charm.
The only thing you have to do is to enable OpenCL while compiling OpenCV

If you dont  use OpenCV and you only want to call OpenCL, than there is a Python library (https://documen.tician.de/pyopencl/) available that you can use to do the API calls to OpenCL.

Hi!

Do you have to install the Mali drivers too? Or is it just sufficient to build open with the -DWITH_OPENCL=ON flag?

Thanks

Gerard
Reply
#13
you dont have to install the mali drivers, for OpenCV atleast.

I did the following steps and it worked for Python:

Retreive the OpenCV sources form github:
wget -O opencv.zip https://github.com/Itseez/opencv/archive/3.3.0.zip

Retreive the contrib sources from Github (has to be included to compile OpenCL)
wget -O opencv_contrib.zip https://github.com/Itseez/opencv_contrib.../3.3.0.zip

After unzipping both the files, make a build directory and execute the followign CMake commando:

Code:
$ cmake
-D CMAKE_BUILD_TYPE=RELEASE
-D CMAKE_INSTALL_PREFIX=/usr/local
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-3.3.0/modules
-D ENABLE_NEON=ON
-D WITH_LIBV4L=ON
-D WITH_OPENCL=ON
-D CMAKE_INSTALL_PREFIX=$(python -c "import sys; print(sys.prefix)")
-D PYTHON3_EXECUTABLE:FILEPATH=$(which python)
-D PYTHON3_INCLUDE_DIR:PATH=$(python -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())")
-D PYTHON3_PACKAGES_PATH=$(python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") ..

After the setup, execute "make -j4" so that the files will be installed on your computer.

You can test if OpenCL works by executing:

Code:
import cv2

if cv2.ocl.haveOpenCL:
 print("OpenCL enabled")
else:
 print("OpenCL disabled")

Sources I used:
https://www.pyimagesearch.com/2017/10/09...pberry-pi/
https://docs.opencv.org/2.4/modules/ocl/...ction.html
Reply
#14
I followed the same procedure, and built OpenCV along with the extra modules and when examining the output of cmake it states : OpenCL : Yes (1.2). However when examining the performance I compiled the following code with g++

 
Code:
#include <opencv2/features2d.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/opencv.hpp>
#include <opencv2/core/ocl.hpp>
#include <vector>
#include <iostream>
#include <stdio.h>

using namespace std;
using namespace cv;

void print_ocl_device_name() {
   vector<ocl::PlatformInfo> platforms;
   ocl::getPlatfomsInfo(platforms);

   for (size_t i = 0; i < platforms.size(); i++) {
       const cv::ocl::PlatformInfo* platform = &platforms[i];
       cout << "Platform Name: " << platform->name().c_str() << "\n";

       for (int j = 0; j < platform->deviceNumber(); j++) {
           cv::ocl::Device current_device;
           platform->getDevice(current_device, j);
           int deviceType = current_device.type();
           cout << "Device " << j << ": " << current_device.name() << "\n";
       }
   }

   ocl::Device default_device = ocl::Device::getDefault();
   cout << "Used device: " << default_device.name() << "\n";
}

int main(void) {
   print_ocl_device_name();

   RNG r(239);
   Mat desc1(5100, 64, CV_32F);
   Mat desc2(5046, 64, CV_32F);
   r.fill(desc1, RNG::UNIFORM, Scalar::all(0.0), Scalar::all(1.0));
   r.fill(desc2, RNG::UNIFORM, Scalar::all(0.0), Scalar::all(1.0));

   for (int i = 0; i < 10; i++) {
       BFMatcher matcher(NORM_L2);

       UMat udesc1, udesc2;
       desc1.copyTo(udesc1);
       desc2.copyTo(udesc2);
       vector< vector<DMatch> > nn_matches;

       matcher.knnMatch(udesc1, udesc2, nn_matches, 2);

       printf("%d\n", i);
   }

   return 0;
}

And the timed the code with using a clock_t type variable, initializing the variable (clock_t start = clock())) before the for loop and examining the result of double result = clock() - start/(double)CLOCKS_PER_SEC after the termination of the loop. It returned similar times (5%) when either using UMat or Mat type variables. 

I also monitored the CPU usage in both cases and for both the CPU usage was above 90% for the execution of the program, which makes me think the GPU was not involved in doing any processing. 

This is further backed up by the fact that I compiled the same code for my Ubuntu desktop, and for CPU (Mat) only, all cores were maxed out to 90% for the duration of the program execution. However when using UMat and taking advantage of my NVIDIA card, only one core was involved in the program execution and the rest idled (assuming one core handled the memory transfer to the OpenCL device). 

I think a driver needs to be installed for the MALI GPU (as I did in Ubuntu on my desktop for the NVIDIA card). 


Which OS are you running on the tinker board? I was using the latest Armbian.

EDIT : So after getting no results from clinfo and stumbling upon this [url=https://brian.digitalmaddox.com/blog/?p=484] and seeing no OpenCL directory in /etc I assumed the driver was not part of Armbian. As such I moved to TinkerOS and after fixing the incorrectly named directory as mentioned in the post above, clinfo returned all the information. However, when trying to implement even a simple function call from using OpenCV's Tapi, this error [url=https://stackoverflow.com/questions/50289324/clenqueuendrangekernel-failed-with-error-out-of-resources-5] occurs which I attempted to fix but with no luck.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)