OpenCL on Ubuntu?

Post Reply
User avatar
streetboy
Posts: 196
Joined: Tue Feb 26, 2013 6:43 pm
languages_spoken: english
ODROIDs: ODROID-X,U2,XU3-Lite
C1, XU4
Contact:

OpenCL on Ubuntu?

Unread post by streetboy » Wed Jul 09, 2014 3:43 pm

First of all... XU3 seems to be a great product.

I could run the OpenCL programs on Android platform of XU. It was very useful for my projects.
But I would like to use Ubuntu platform for my new projects.
Is there any evidence of real world running OpenCL on the Ubuntu platform for XU3? :D

I don't trust IMG PVR driver.. But I wish ARM Mali driver support is much better. :mrgreen:

User avatar
odroid
Site Admin
Posts: 30015
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID
Contact:

Re: OpenCL on Ubuntu?

Unread post by odroid » Wed Jul 09, 2014 4:38 pm

Here is the evidence. ;)

I've downloaded the Mali OpenCL SDK from ARM website.
http://malideveloper.arm.com/develop-fo ... pencl-sdk/

Extracted it and changed the platform.mk line 9~10 like this.

Code: Select all

CC:=arm-linux-gnueabihf-g++
AR=arm-linux-gnueabihf-ar
Here is the 64bit Integer computing GPGPU OpenCL example code(CL kernel).

Code: Select all

/*
 * This confidential and proprietary software may be used only as
 * authorised by a licensing agreement from ARM Limited
 *    (C) COPYRIGHT 2013 ARM Limited
 *        ALL RIGHTS RESERVED
 * The entire notice above must be reproduced on all authorised
 * copies and copies may only be made to the extent permitted
 * by a licensing agreement from ARM Limited.
 */

/**
 * \brief  Long data type (64-bit integer) kernel.
 * \details This kernel loads 8 pixel values to calculate the square of each pixel value. Then it accumulates the
 * square of pixels and the sum of pixels values in the respective accumulators.
 * \param[in] imagePixels Input array with image pixels.
 * \param[in] squareOfPixels Sum of the square of pixel values.
 * \param[out] sumOfPixels Sum of pixel values.
 */

/* [Enable atom_add extension] */
#pragma OPENCL EXTENSION cl_khr_int64_base_atomics : enable
/* [Enable atom_add extension] */

__kernel void long_vectors(__global uchar* restrict imagePixels,
                           __global ulong* restrict squareOfPixels,
                           __global ulong* restrict sumOfPixels)
{
    /*
     * Set i to be the ID of the kernel instance.
     * If the global work size (set by clEnqueueNDRangeKernel) is n,
     * then n kernels will be run and i will be in the range [0, n - 1].
     */
    int i = get_global_id(0);

    /* [Squares and sums]*/
    /* Load 8 pixels (char) and convert them to shorts to calculate the square.*/
    ushort8 pixelShort = convert_ushort8(vload8(i, imagePixels));
    /* Square of 255 < 2 ^ 16. */
    ushort8 newSquareShort = pixelShort * pixelShort;

    /*
     * Convert original pixel value and the square to longs to sum
     * all the vectors together and add the final values to the
     * respective accumulators.
     */
    ulong8 pixelLong = convert_ulong8(pixelShort);
    ulong8 newSquareLong = convert_ulong8(newSquareShort);

    /*
     * Use vector data type suffixes (.lo and .hi) to get smaller vector types,
     * until we obtain one single value.
     */
    ulong4 sumLongPixels1 = pixelLong.hi + pixelLong.lo;
    ulong2 sumLongPixels2 = sumLongPixels1.hi + sumLongPixels1.lo;
    ulong sumLongPixels3 = sumLongPixels2.hi + sumLongPixels2.lo;

    ulong4 sumLongSquares1 = newSquareLong.hi + newSquareLong.lo;
    ulong2 sumLongSquares2 = sumLongSquares1.hi + sumLongSquares1.lo;
    ulong sumLongSquares3 = sumLongSquares2.hi + sumLongSquares2.lo;
    /* [Squares and sums]*/

    /*
     * As all the kernels are accessing sumOfPixels
     * and squareOfPixels at the same time,
     * we use atom_add to ensure only one kernel
     * at a time can access the given variables.
     * This means that this operation is very expensive,
     * so we want to use it only when necessary.
     */
    /* [Atomic transaction] */
    atom_add(sumOfPixels, sumLongPixels3);
    atom_add(squareOfPixels, sumLongSquares3);
    /* [Atomic transaction] */
}
C++ code to utilize the CL kernel.

Code: Select all

/*
 * This confidential and proprietary software may be used only as
 * authorised by a licensing agreement from ARM Limited
 *    (C) COPYRIGHT 2013 ARM Limited
 *        ALL RIGHTS RESERVED
 * The entire notice above must be reproduced on all authorised
 * copies and copies may only be made to the extent permitted
 * by a licensing agreement from ARM Limited.
 */

#include "common.h"
#include "image.h"

#include <CL/cl.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstddef>
#include <cmath>

using namespace std;

/**
 * \brief  Long data type (64-bit integer) OpenCL example.
 * \details An example to calculate, for an image:
 *          - the sum of the squares of the pixels values
 *          - sum of the pixels values.
 *          Makes use of the long data type and 64-bit atomics.
 *          The main calculation code is in an OpenCL kernel which is executed on a GPU device.
 * \return The exit code of the application, non-zero if a problem occurred.
 */
int main(void)
{
    string filename = "assets/input.bmp";

    cl_context context = 0;
    cl_command_queue commandQueue = 0;
    cl_program program = 0;
    cl_device_id device = 0;
    cl_kernel kernel = 0;
    const int numberOfMemoryObjects = 3;
    /* Index values for the memory objects. */
    const unsigned int imagePixelsIndex = 0;
    const unsigned int squareIndex = 1;
    const  unsigned int sumIndex = 2;
    cl_mem memoryObjects[3] = {0, 0, 0};
    cl_int errorNumber;


    if (!createContext(&context))
    {
        cleanUpOpenCL(context, commandQueue, program, kernel, memoryObjects, numberOfMemoryObjects);
        cerr << "Failed to create an OpenCL context. " << __FILE__ << ":"<< __LINE__ << endl;
        return 1;
    }

    if (!createCommandQueue(context, &commandQueue, &device))
    {
        cleanUpOpenCL(context, commandQueue, program, kernel, memoryObjects, numberOfMemoryObjects);
        cerr << "Failed to create the OpenCL command queue. " << __FILE__ << ":"<< __LINE__ << endl;
        return 1;
    }

    /* Checking 64-bit integer atomics extension support. */
    if (!isExtensionSupported (device, "cl_khr_int64_base_atomics"))
    {
        cleanUpOpenCL(context, commandQueue, program, kernel, memoryObjects, numberOfMemoryObjects);
        cerr << "cl_khr_int64_base_atomics is not supported on this device. " << __FILE__ << ":"<< __LINE__ << endl;
        return 1;
    }

    if (!createProgram(context, device, "assets/64_bit_integer.cl", &program))
    {
        cleanUpOpenCL(context, commandQueue, program, kernel, memoryObjects, numberOfMemoryObjects);
        cerr << "Failed to create OpenCL program." << __FILE__ << ":"<< __LINE__ << endl;
        return 1;
    }

    kernel = clCreateKernel(program, "long_vectors", &errorNumber);
    if (!checkSuccess(errorNumber))
    {
        cleanUpOpenCL(context, commandQueue, program, kernel, memoryObjects, numberOfMemoryObjects);
        cerr << "Failed to create OpenCL kernel. " << __FILE__ << ":"<< __LINE__ << endl;
        return 1;
    }

    /* Load 24-bits per pixel RGB data from a bitmap. */
    cl_int width;
    cl_int height;
    unsigned char* loadedRGBData = NULL;
    if (!loadFromBitmap(filename, &width, &height, &loadedRGBData))
    {
        cleanUpOpenCL(context, commandQueue, program, kernel, memoryObjects, numberOfMemoryObjects);
        cerr << "Failed loading bitmap. " << __FILE__ << ":"<< __LINE__ << endl;
        return 1;
    }

    /* Buffer for the image pixels. */
    size_t bufferSizeChar = width * height * sizeof(unsigned char);
    /* Buffer for the accumulators*/
    size_t bufferSizeLong = sizeof(cl_ulong);

    /*
     * Ask the OpenCL implementation to allocate buffers for the data.
     * We ask the OpenCL implementation to allocate memory rather than allocating
     * it on the CPU to avoid having to copy the data later.
     * The read/write flags relate to accesses to the memory from within the kernel.
     */
    bool createMemoryObjectsSuccess = true;

    memoryObjects[imagePixelsIndex] = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_ALLOC_HOST_PTR, bufferSizeChar, NULL, &errorNumber);
    createMemoryObjectsSuccess &= checkSuccess(errorNumber);

    memoryObjects[squareIndex] = clCreateBuffer(context, CL_MEM_READ_WRITE| CL_MEM_ALLOC_HOST_PTR, bufferSizeLong, NULL, &errorNumber);
    createMemoryObjectsSuccess &= checkSuccess(errorNumber);

    memoryObjects[sumIndex] = clCreateBuffer(context, CL_MEM_READ_WRITE| CL_MEM_ALLOC_HOST_PTR, bufferSizeLong, NULL, &errorNumber);
    createMemoryObjectsSuccess &= checkSuccess(errorNumber);

    if (!createMemoryObjectsSuccess)
    {
        cleanUpOpenCL(context, commandQueue, program, kernel, memoryObjects, numberOfMemoryObjects);
        cerr << "Failed to create OpenCL buffer. " << __FILE__ << ":"<< __LINE__ << endl;
        return 1;
    }

    /* Map the input memory objects to a host side pointers. */
    bool mapMemoryObjectsSuccess = true;
    cl_uchar* inputImagePixels = (cl_uchar*)clEnqueueMapBuffer(commandQueue, memoryObjects[imagePixelsIndex], CL_TRUE, CL_MAP_WRITE, 0, bufferSizeChar, 0, NULL, NULL, &errorNumber);
    mapMemoryObjectsSuccess &= checkSuccess(errorNumber);
    cl_ulong* inputSquareOfPixels = (cl_ulong*)clEnqueueMapBuffer(commandQueue, memoryObjects[squareIndex], CL_TRUE, CL_MAP_WRITE, 0, bufferSizeLong, 0, NULL, NULL, &errorNumber);
    mapMemoryObjectsSuccess &= checkSuccess(errorNumber);
    cl_ulong* inputSumOfPixels = (cl_ulong*)clEnqueueMapBuffer(commandQueue, memoryObjects[sumIndex], CL_TRUE, CL_MAP_WRITE, 0, bufferSizeLong, 0, NULL, NULL, &errorNumber);
    mapMemoryObjectsSuccess &= checkSuccess(errorNumber);

    if (!mapMemoryObjectsSuccess)
    {
        cleanUpOpenCL(context, commandQueue, program, kernel, memoryObjects, numberOfMemoryObjects);
        cerr << "Mapping memory objects failed " << __FILE__ << ":"<< __LINE__ << endl;
        return 1;
    }

    /*
     * Convert 24-bits per pixel RGB into 8-bits per pixel luminance data
     * and fill the array for the kernel.
     */
    RGBToLuminance(loadedRGBData, inputImagePixels, width, height);
    delete [] loadedRGBData;

    /* Ensure the accumulators are initialized to zero. */
    *inputSquareOfPixels = 0;
    *inputSumOfPixels = 0;

    /* Unmap the memory so we can pass it to the kernel. */
    bool unmapMemoryObjectsSuccess = true;
    unmapMemoryObjectsSuccess &= checkSuccess(clEnqueueUnmapMemObject(commandQueue, memoryObjects[imagePixelsIndex], inputImagePixels, 0, NULL, NULL));
    unmapMemoryObjectsSuccess &= checkSuccess(clEnqueueUnmapMemObject(commandQueue, memoryObjects[squareIndex], inputSquareOfPixels, 0, NULL, NULL));
    unmapMemoryObjectsSuccess &= checkSuccess(clEnqueueUnmapMemObject(commandQueue, memoryObjects[sumIndex], inputSumOfPixels, 0, NULL, NULL));

    if (!unmapMemoryObjectsSuccess)
    {
        cleanUpOpenCL(context, commandQueue, program, kernel, memoryObjects, numberOfMemoryObjects);
        cerr << "Unmapping memory objects failed " << __FILE__ << ":"<< __LINE__ << endl;
        return 1;
    }

    /* Set the kernel arguments */
    bool setKernelArgumentsSuccess = true;
    setKernelArgumentsSuccess &= checkSuccess(clSetKernelArg(kernel, imagePixelsIndex, sizeof(cl_mem), &memoryObjects[imagePixelsIndex]));
    setKernelArgumentsSuccess &= checkSuccess(clSetKernelArg(kernel, squareIndex, sizeof(cl_mem), &memoryObjects[squareIndex]));
    setKernelArgumentsSuccess &= checkSuccess(clSetKernelArg(kernel, sumIndex, sizeof(cl_mem), &memoryObjects[sumIndex]));

    if (!setKernelArgumentsSuccess)
    {
        cleanUpOpenCL(context, commandQueue, program, kernel, memoryObjects, numberOfMemoryObjects);
        cerr << "Failed setting OpenCL kernel arguments. " << __FILE__ << ":"<< __LINE__ << endl;
        return 1;
    }

    /* An event to associate with the Kernel. Allows us to retrieve profiling information later. */
    cl_event event = 0;

    /*
      * Each instance of the kernel operates on a 8 * 1 portion of the image.
     * Therefore, the global work size must be 1.
     */
    size_t globalWorksize[1] = {(width * height) / 8};
    int work_dim = 1;
    /* Enqueue the kernel */
    if (!checkSuccess(clEnqueueNDRangeKernel(commandQueue, kernel, work_dim, NULL, globalWorksize, NULL, 0, NULL, &event)))
    {
        cleanUpOpenCL(context, commandQueue, program, kernel, memoryObjects, numberOfMemoryObjects);
        cerr << "Failed enqueuing the kernel. " << __FILE__ << ":"<< __LINE__ << endl;
        return 1;
    }

    /* Wait for kernel execution completion. */
    if (!checkSuccess(clFinish(commandQueue)))
    {
        cleanUpOpenCL(context, commandQueue, program, kernel, memoryObjects, numberOfMemoryObjects);
        cerr << "Failed waiting for kernel execution to finish. " << __FILE__ << ":"<< __LINE__ << endl;
        return 1;
    }

    /* Print the profiling information for the event. */
    printProfilingInfo(event);
    /* Release the event object. */
    if (!checkSuccess(clReleaseEvent(event)))
    {
       cleanUpOpenCL(context, commandQueue, program, kernel, memoryObjects, numberOfMemoryObjects);
       cerr << "Failed releasing the event object. " << __FILE__ << ":"<< __LINE__ << endl;
       return 1;
    }

    /* Get pointers to the output data. */
    mapMemoryObjectsSuccess = true;
    cl_ulong* squareOfPixels = (cl_ulong*)clEnqueueMapBuffer(commandQueue, memoryObjects[squareIndex], CL_TRUE, CL_MAP_READ, 0, bufferSizeLong, 0, NULL, NULL, &errorNumber);
    mapMemoryObjectsSuccess &= checkSuccess(errorNumber);

    cl_ulong* sumOfPixels = (cl_ulong*)clEnqueueMapBuffer(commandQueue, memoryObjects[sumIndex], CL_TRUE, CL_MAP_READ, 0, bufferSizeLong, 0, NULL, NULL, &errorNumber);
    mapMemoryObjectsSuccess &= checkSuccess(errorNumber);
    if (!mapMemoryObjectsSuccess)
    {
       cleanUpOpenCL(context, commandQueue, program, kernel, memoryObjects, numberOfMemoryObjects);
       cerr << "Failed to map buffer. " << __FILE__ << ":"<< __LINE__ << endl;
       return 1;
    }

    /* [Output the results] */
    cout << "Square of the pixel values = " <<  *squareOfPixels << "\n";
    cout << "Sum of the pixel values = " <<  *sumOfPixels << endl;
    /* [Output the results] */

    /* Unmap the memory object as we are finished using them from the CPU side. */
    unmapMemoryObjectsSuccess = true;
    unmapMemoryObjectsSuccess &= checkSuccess(clEnqueueUnmapMemObject(commandQueue, memoryObjects[squareIndex], squareOfPixels, 0, NULL, NULL));
    unmapMemoryObjectsSuccess &= checkSuccess(clEnqueueUnmapMemObject(commandQueue, memoryObjects[sumIndex], sumOfPixels, 0, NULL, NULL));

    if (!unmapMemoryObjectsSuccess)
    {
       cleanUpOpenCL(context, commandQueue, program, kernel, memoryObjects, numberOfMemoryObjects);
       cerr << "Unmapping memory objects failed " << __FILE__ << ":"<< __LINE__ << endl;
       return 1;
    }

    /* Release OpenCL objects. */
    cleanUpOpenCL(context, commandQueue, program, kernel, memoryObjects, numberOfMemoryObjects);
}
And I built it.

Code: Select all

odroid@odroid:~/Mali_OpenCL_SDK_v1.1.0/samples/64_bit_integer$ make
arm-linux-gnueabihf-g++ -c -Wall -I../../include -I../../common -I. 64_bit_integer.cpp -o 64_bit_integer.o
64_bit_integer.cpp: In function 'int main()':
64_bit_integer.cpp:187:50: warning: narrowing conversion of '((width * height) / 8)' from 'cl_int {aka int}' to 'size_t {aka unsigned int}' inside { } is ill-formed in C++11 [-Wnarrowing]
     size_t globalWorksize[1] = {(width * height) / 8};
                                                  ^
cd ../../lib ; make libOpenCL.so
make[1]: Entering directory `/home/odroid/Mali_OpenCL_SDK_v1.1.0/lib'
make[1]: `libOpenCL.so' is up to date.
make[1]: Leaving directory `/home/odroid/Mali_OpenCL_SDK_v1.1.0/lib'
cd ../../common/ ; make libCommon.a
make[1]: Entering directory `/home/odroid/Mali_OpenCL_SDK_v1.1.0/common'
make[1]: `libCommon.a' is up to date.
make[1]: Leaving directory `/home/odroid/Mali_OpenCL_SDK_v1.1.0/common'
arm-linux-gnueabihf-g++ 64_bit_integer.o -o 64_bit_integer -L../../lib -L../../common -lOpenCL -lCommon
It ran well like this.

Code: Select all

odroid@odroid:~/Mali_OpenCL_SDK_v1.1.0/samples/64_bit_integer$ ./64_bit_integer Profiling information:
Queued time: 	0.176ms
Wait time: 	0.873757ms
Run time: 	0.230723ms
Square of the pixel values = 914239116
Sum of the pixel values = 9365464

User avatar
streetboy
Posts: 196
Joined: Tue Feb 26, 2013 6:43 pm
languages_spoken: english
ODROIDs: ODROID-X,U2,XU3-Lite
C1, XU4
Contact:

Re: OpenCL on Ubuntu?

Unread post by streetboy » Wed Jul 09, 2014 6:37 pm

Oh! You guys made it.. I've been waiting for this for over 10 months.
Take my money! :twisted:

Giedroid
Posts: 3
Joined: Wed Sep 24, 2014 12:21 pm
languages_spoken: english
ODROIDs: U2, XU, XU3
Contact:

Re: OpenCL on Ubuntu?

Unread post by Giedroid » Sun Oct 05, 2014 7:49 am

I did download the OpenCL SDK from the said Mali website to my XU3, and tried to compile the sample 64_bit_integer. However, I get this error:
OpenCL error: Unknown error
Retrieving OpenCL platforms failed. common.cpp:233
Failed to create an OpenCL context. 64_bit_integer.cpp:53
Any ideas? :?:

Thanks

mdrjr
Site Admin
Posts: 11698
Joined: Fri Feb 22, 2013 11:34 pm
languages_spoken: english, portuguese
ODROIDs: -
Location: Brazil
Contact:

Re: OpenCL on Ubuntu?

Unread post by mdrjr » Mon Oct 06, 2014 6:21 pm

What image you are using? Any updates? Have you built the OpenCL DDK? How?
Why revive a 3 month thread to post a question that isn't much todo with the original author question ?

ulrichard
Posts: 1
Joined: Fri Dec 12, 2014 7:08 pm
languages_spoken: english, german, spanish
ODROIDs: none yet
Contact:

Re: OpenCL on Ubuntu?

Unread post by ulrichard » Mon Dec 15, 2014 11:32 pm

Is there som more information about OpenCL with ubuntu?
Does it still work when ubuntu is upgraded to the latest version?

I bought a cubox-i4 last year because it was advertised with OpenCL. Then I was very disappointed to find out that OpenCL worked only if you used some outdated anstrom image.

mdrjr
Site Admin
Posts: 11698
Joined: Fri Feb 22, 2013 11:34 pm
languages_spoken: english, portuguese
ODROIDs: -
Location: Brazil
Contact:

Re: OpenCL on Ubuntu?

Unread post by mdrjr » Mon Dec 15, 2014 11:53 pm

OpenCL is working on latest Ubuntu.. I've just tested.

bensch128
Posts: 20
Joined: Tue Dec 02, 2014 8:08 pm
languages_spoken: english
ODROIDs: odroid-xu3
odroid-c1
Contact:

Re: OpenCL on Ubuntu?

Unread post by bensch128 » Tue Dec 30, 2014 7:01 pm

Giedroid wrote:I did download the OpenCL SDK from the said Mali website to my XU3, and tried to compile the sample 64_bit_integer. However, I get this error:
OpenCL error: Unknown error
Retrieving OpenCL platforms failed. common.cpp:233
Failed to create an OpenCL context. 64_bit_integer.cpp:53
Any ideas? :?:

Thanks
You need link to /usr/lib/arm-gnusomethingsomethinghf/mali-egl/libOpenCL.so, not ../../lib/libOpenCL.so
Run

Code: Select all

ldd 64_bit_integer
and check that it's using the correct libOpenCL.so

Cheers
Ben

HerbsMix
Posts: 63
Joined: Fri Dec 05, 2014 7:51 am
languages_spoken: english
ODROIDs: ODROID-XU3
Contact:

Re: OpenCL on Ubuntu?

Unread post by HerbsMix » Wed Dec 31, 2014 5:08 am

I have been also waiting for this. Will it be included in the Kernel or installation instructions provided soon?

User avatar
odroid
Site Admin
Posts: 30015
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID
Contact:

Re: OpenCL on Ubuntu?

Unread post by odroid » Wed Dec 31, 2014 10:36 am

OpenCL driver & libraries are already included in our image.
Just install the ARM Mali SDK as described in this thread.

alf
Posts: 2
Joined: Thu Feb 05, 2015 3:00 am
languages_spoken: english
ODROIDs: XU3, U3
Contact:

Re: OpenCL on Ubuntu?

Unread post by alf » Thu Feb 05, 2015 5:27 am

Hi,

I'm having some issues using OpenCL under OpenCV. I was able to reproduce the results in this thread; running the tests from the Mali SDK worked after changing the platform.mk file and setting LD_LIBRARY_PATH=/usr/lib/arm-linux-gnueabihf/mali-egl/.

I downloaded the latest OpenCV source from github (https://github.com/Itseez/opencv) and compiled it with default settings. After building I tried to run some OpenCV tests using OpenCL by running the following command:

Code: Select all

...../opencv/build/bin/opencv_perf_imgproc -gtest_filter=*OCL*
This fails with the following error:
OpenCV version: 3.0.0-dev
OpenCV VCS version: 3.0.0-beta-479-g4c52dfc
Build type: release
Parallel framework: openmp
CPU features:
Failed to load OpenCL runtime (expected version 1.1+)
Exception. Can't dump OpenCL info
OpenCL device not available
NB: should I worry about this bug report: http://code.opencv.org/issues/4010, or do you know if this issue is fixed?

mdrjr
Site Admin
Posts: 11698
Joined: Fri Feb 22, 2013 11:34 pm
languages_spoken: english, portuguese
ODROIDs: -
Location: Brazil
Contact:

Re: OpenCL on Ubuntu?

Unread post by mdrjr » Thu Feb 05, 2015 9:09 am

You try try add the library path as well to the application execution?

alf
Posts: 2
Joined: Thu Feb 05, 2015 3:00 am
languages_spoken: english
ODROIDs: XU3, U3
Contact:

Re: OpenCL on Ubuntu?

Unread post by alf » Thu Feb 05, 2015 9:27 pm

Yes I have, but I found an error in my test-script. Apparently OpenCl is unable to load if you define the OPENCV_OPENCL_RUNTIME environment variable. I removed this and the test were able to run.

The bad news is that 1176/1539 test fail when running

Code: Select all

...../opencv/build/bin/opencv_perf_imgproc -gtest_filter=*OCL*
, and I guess that a lot of the errors reported are related to the bug-report I posted.

lzy
Posts: 7
Joined: Tue Apr 15, 2014 4:02 pm
languages_spoken: english
Contact:

Re: OpenCL on Ubuntu?

Unread post by lzy » Sat Apr 25, 2015 6:29 pm

I don't have this folder /usr/lib/arm-linux-gnueabihf/mali-egl/ and I am using this image Ubuntu 14.04 Robotics Edition for ODROID-XU3.

Should I use another image in order to use OpenCL?

rui278
Posts: 3
Joined: Mon Apr 27, 2015 7:17 am
languages_spoken: english
ODROIDs: Xu3
Contact:

Re: OpenCL on Ubuntu?

Unread post by rui278 » Mon Apr 27, 2015 7:23 am

Guys!

I've been trying to run a kernel with multiple dimensions, and I haven't been able to...

These are my total and local size vectors,

Code: Select all

size_t totalSize[3] = {64, 64, 64};
size_t localSize[3] = {32, 32, 32};
CL_WRAPPER(clEnqueueNDRangeKernel(maliOCL.mainGroupQueue, maliOCL.clKernels[0], 3, offsetKernel, totalSize, localSize, 1, &maliOCL.MaliFencUnMapEvent, &kernelEvent));
The thing is, when i query the device properties, this comes up:

Code: Select all

  Max. Work Item Dimensions  :3
  Max. Work Item Sizes       :(256, 256, 256)
  Max. Work Group Sizes      :(256, 256, 256)
But when i try to run the kernel i get error -54 (invalid work group size)... If i run with only 1 dimension it runs no problem...
Any one knows if there is a limitation on work item dimension, size or group size that doesn't show up in the device querys?

Thanks
Rui

User avatar
odroid
Site Admin
Posts: 30015
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID
Contact:

Re: OpenCL on Ubuntu?

Unread post by odroid » Mon Apr 27, 2015 1:53 pm

You can have an answer more quickly when you post the Mali related questions on the official forum of ARM Mali developers.
http://community.arm.com/groups/arm-mali-graphics

rui278
Posts: 3
Joined: Mon Apr 27, 2015 7:17 am
languages_spoken: english
ODROIDs: Xu3
Contact:

Re: OpenCL on Ubuntu?

Unread post by rui278 » Mon Apr 27, 2015 8:06 pm

Thanks!

I think i figured out the "problem".

The thing is, each shader core has 1024 registers and each kernel needs at least 4 registers. So, the 256 threads limit is in all dimensions. Meaning that if i have 256 in one dimension I need to have 0 in the other two.

Basically ItemSize(0)*ItemSize(1)*ItemSize(2) <= 256 has to be true and the same for work groups...

At least that's what seems to happen when i test different sizes...

But thanks for the tip! From now on I'll try the mali forums as well!

onda
Posts: 10
Joined: Thu Oct 26, 2017 6:15 am
languages_spoken: english
Contact:

Re: OpenCL on Ubuntu?

Unread post by onda » Wed Nov 08, 2017 3:54 am

Where can I find the platform.mk file ?

Oung1981
Posts: 1
Joined: Wed Jan 03, 2018 4:36 am
languages_spoken: english
ODROIDs: Odroid XU4
Contact:

Re: OpenCL on Ubuntu?

Unread post by Oung1981 » Wed Jan 03, 2018 4:40 am

onda wrote:Where can I find the platform.mk file ?
question that has been here for some months without any answers... sadly... because i need an answer to it.

rubberduck
Posts: 10
Joined: Mon Dec 25, 2017 7:37 pm
languages_spoken: german, english
ODROIDs: ODROID-HC1
Location: Germany
Contact:

Re: OpenCL on Ubuntu?

Unread post by rubberduck » Wed Jan 03, 2018 5:29 am

Is it possible to use OpenCL on the HC1, too? This one has no HDMI Out and so no GUI for the driver...

User avatar
memeka
Posts: 4230
Joined: Mon May 20, 2013 10:22 am
languages_spoken: english
ODROIDs: XU rev2 + eMMC + UART
U3 + eMMC + IO Shield + UART
Contact:

Re: OpenCL on Ubuntu?

Unread post by memeka » Wed Jan 03, 2018 6:03 am

Yes, hdmi output doesn’t matter.
Just ssh and run your openCL program.

rubberduck
Posts: 10
Joined: Mon Dec 25, 2017 7:37 pm
languages_spoken: german, english
ODROIDs: ODROID-HC1
Location: Germany
Contact:

Re: OpenCL on Ubuntu?

Unread post by rubberduck » Wed Jan 03, 2018 6:02 pm

Thank you for the answer. I cannot find out how to compile the opencl sdk. Is there a step-by-step howto available?

User avatar
odroid
Site Admin
Posts: 30015
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID
Contact:

Re: OpenCL on Ubuntu?

Unread post by odroid » Wed Jan 03, 2018 6:27 pm

Refer this document. Download the latest source package from ARM's github and build the library natively.
https://arm-software.github.io/ComputeLibrary/latest/

I've just started to build the latest ARM's OpenCL library on XU4 Ubuntu & Kernel 4.14.11 now. I will check the result tomorrow.

Code: Select all

wget https://github.com/ARM-software/ComputeLibrary/archive/v17.12.tar.gz
tar xvfx v17.12.tar.gz
cd ComputeLibrary-17.12
sudo apt install scons
scons Werror=1 -j8 debug=0 neon=1 opencl=1 embed_kernels=1 os=linux arch=armv7a build=native

User avatar
odroid
Site Admin
Posts: 30015
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID
Contact:

Re: OpenCL on Ubuntu?

Unread post by odroid » Thu Jan 04, 2018 12:08 pm

Library compiling completed without error.
So I've installed the compiled shared-library manually.

Code: Select all

sudo cp build/*.so /usr/lib/.
Time to learn how to compile and run a CL example.

User avatar
odroid
Site Admin
Posts: 30015
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID
Contact:

Re: OpenCL on Ubuntu?

Unread post by odroid » Thu Jan 04, 2018 1:08 pm

I've built and run cl_convolusion example.

Code: Select all

g++ examples/cl_convolution.cpp utils/Utils.cpp -I. -Iinclude -std=c++11 -mfpu=neon -L. -larm_compute -larm_compute_core -lOpenCL -o cl_convolution -DARM_COMPUTE_CL

Code: Select all

odroid@odroid:~/ComputeLibrary-17.12$ time ./cl_convolution start_2.ppm                                                                             
./cl_convolution                                                                                                                                    
Test passed                                                                                                                                         
                                                                                                                                                    
real    0m0.465s                                                                                                                                    
user    0m0.382s                                                                                                                                    
sys     0m0.052s 
Convolution computing for 800x600 resolution image took 465msec.
I have no idea wheather it is fast or not.

Left side picture is the original one and right side picture has been generated by the convolution computing.
Image
https://dn.odroid.com/5422/cl_example.png

rubberduck
Posts: 10
Joined: Mon Dec 25, 2017 7:37 pm
languages_spoken: german, english
ODROIDs: ODROID-HC1
Location: Germany
Contact:

Re: OpenCL on Ubuntu?

Unread post by rubberduck » Sat Jan 06, 2018 5:35 am

Where can i find a libOpenCL.so for my applications?

User avatar
odroid
Site Admin
Posts: 30015
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID
Contact:

Re: OpenCL on Ubuntu?

Unread post by odroid » Sat Jan 06, 2018 11:08 am

It should be /usr/lib/arm-linux-gnueabihf/

rubberduck
Posts: 10
Joined: Mon Dec 25, 2017 7:37 pm
languages_spoken: german, english
ODROIDs: ODROID-HC1
Location: Germany
Contact:

Re: OpenCL on Ubuntu?

Unread post by rubberduck » Sat Jan 06, 2018 8:12 pm

Sorry - there is no libOpenCL.so there...

mdrjr
Site Admin
Posts: 11698
Joined: Fri Feb 22, 2013 11:34 pm
languages_spoken: english, portuguese
ODROIDs: -
Location: Brazil
Contact:

Re: OpenCL on Ubuntu?

Unread post by mdrjr » Sat Jan 06, 2018 9:43 pm

rubberduck wrote:Sorry - there is no libOpenCL.so there...
What OS image you are using?

rubberduck
Posts: 10
Joined: Mon Dec 25, 2017 7:37 pm
languages_spoken: german, english
ODROIDs: ODROID-HC1
Location: Germany
Contact:

Re: OpenCL on Ubuntu?

Unread post by rubberduck » Sun Jan 07, 2018 9:08 pm

Ubuntu 16.04 LTS

mdrjr
Site Admin
Posts: 11698
Joined: Fri Feb 22, 2013 11:34 pm
languages_spoken: english, portuguese
ODROIDs: -
Location: Brazil
Contact:

Re: OpenCL on Ubuntu?

Unread post by mdrjr » Sun Jan 07, 2018 9:43 pm

rubberduck wrote:Ubuntu 16.04 LTS
Minimal? Mate? downloaded from us?

rubberduck
Posts: 10
Joined: Mon Dec 25, 2017 7:37 pm
languages_spoken: german, english
ODROIDs: ODROID-HC1
Location: Germany
Contact:

Re: OpenCL on Ubuntu?

Unread post by rubberduck » Mon Jan 08, 2018 5:50 pm

Minimal. Downloaded from the wiki.
Have not found a libOpenCL.so with apt-file, too

User avatar
odroid
Site Admin
Posts: 30015
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID
Contact:

Re: OpenCL on Ubuntu?

Unread post by odroid » Mon Jan 08, 2018 5:54 pm

You had to install the mali GPU driver for the minimal image.

Code: Select all

apt install mali-fbdev
https://wiki.odroid.com/odroid-xu4/os_i ... .9/minimal

rubberduck
Posts: 10
Joined: Mon Dec 25, 2017 7:37 pm
languages_spoken: german, english
ODROIDs: ODROID-HC1
Location: Germany
Contact:

Re: OpenCL on Ubuntu?

Unread post by rubberduck » Tue Jan 09, 2018 6:41 pm

Thank you very much.

I'm still unable to compile a simple hello world in OpenCL.

root@odroid:~/opencl# gcc -o hello hello.c
In file included from hello.c:11:0:
/usr/include/arm_compute/core/CL/OpenCL.h:27:18: fatal error: string: No such file or directory
compilation terminated.

It seems that OpenCL.h is not for C but for C++.
But i cannot find other header files in the sdk defining functions like "clGetPlatformIDs".

Another hello example (in cpp):

root@odroid:~/opencl/hello# make
g++ -std=c++0x -o hello hello.cpp -lOpenCL
In file included from hello.cpp:6:0:
/usr/include/CL/cl.hpp: In function ‘void cl::detail::fence()’:
/usr/include/CL/cl.hpp:1041:38: error: ‘_mm_mfence’ was not declared in this scope
inline void fence() { _mm_mfence(); }
^
Makefile:2: recipe for target 'hello' failed
make: *** [hello] Error 1
Last edited by rubberduck on Tue Jan 09, 2018 6:49 pm, edited 1 time in total.

User avatar
odroid
Site Admin
Posts: 30015
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID
Contact:

Re: OpenCL on Ubuntu?

Unread post by odroid » Tue Jan 09, 2018 6:43 pm

Did you build and run cl_convolution example successfully?

rubberduck
Posts: 10
Joined: Mon Dec 25, 2017 7:37 pm
languages_spoken: german, english
ODROIDs: ODROID-HC1
Location: Germany
Contact:

Re: OpenCL on Ubuntu?

Unread post by rubberduck » Tue Jan 09, 2018 6:53 pm

Yes, that is working.

root@odroid:~/opencl/ComputeLibrary-17.12# time ./cl_convolution

./cl_convolution

Usage: ./build/cl_convolution [input_image.ppm]

No input_image provided, creating a dummy 640x480 image

Test passed

real 0m0.242s
user 0m0.143s
sys 0m0.036s

User avatar
odroid
Site Admin
Posts: 30015
Joined: Fri Feb 22, 2013 11:14 pm
languages_spoken: English
ODROIDs: ODROID
Contact:

Re: OpenCL on Ubuntu?

Unread post by odroid » Tue Jan 09, 2018 7:07 pm

I have no idea since we have no OpenCL experienced developer internally.

Post your questions on ARM Mali community.
https://community.arm.com/graphics/

ASword
Posts: 148
Joined: Fri Aug 04, 2017 12:48 pm
languages_spoken: english
ODROIDs: XU4, HC1
Contact:

Re: OpenCL on Ubuntu?

Unread post by ASword » Fri Jan 12, 2018 9:52 am

OpenCL is fundamentally a C API, therefore if you include it from C++ (as with any C API not properly set up for C++) you need to wrap it with

extern "C" {
#include <...>
};


The other hello.cpp example you are trying relies on a C++ binding header that is published alongside OpenCL. Portability of that header isn't guaranteed, nor do I believe it is very well maintained. It was created as a side project by a committee member, IIRC.

1dbup
Posts: 4
Joined: Tue Jan 16, 2018 12:37 am
languages_spoken: english
ODROIDs: XU4
Contact:

Re: OpenCL on Ubuntu?

Unread post by 1dbup » Wed Jan 17, 2018 12:30 am

Just to confirm that your timing results for cl_convolution look ok. I've run the same on my XU4 with Arm Compute Library and get much the same results

odroid@odroid:~/ComputeLibrary-17.12/build/examples$ time LD_LIBRARY_PATH=~/ComputeLibrary-17.12/build ./cl_convolution

./cl_convolution

Usage: ./build/cl_convolution [input_image.ppm]

No input_image provided, creating a dummy 640x480 image

Test passed

real 0m0.247s
user 0m0.154s
sys 0m0.028s

For reference. Performing it on a real image 1920x1080 as provided in the Compute Library installation gives the following result:
odroid@odroid:~/ComputeLibrary-17.12/build/examples$ time LD_LIBRARY_PATH=~/ComputeLibrary-17.12/build ./cl_convolution ../../data/images/1920x1080.ppm

./cl_convolution


Test passed

real 0m0.966s
user 0m0.764s
sys 0m0.118s

Post Reply

Return to “Ubuntu”

Who is online

Users browsing this forum: Bing [Bot] and 2 guests