Hi,
I'm having trouble creating an OpenCL context from an OpenGL ES context on an Odroid XU3 running Android 4.4.4. The following code works fine on other non-ARM graphics hardware, but on the Mali chip the call to clCreateContextFromType fails with the error: "CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR (-1000)"
cl_context_properties contextProps[] = {
CL_CONTEXT_PLATFORM, cl_context_properties(m_platform),
CL_GL_CONTEXT_KHR, (cl_context_properties)eglGetCurrentContext(),
CL_EGL_DISPLAY_KHR, (cl_context_properties)eglGetCurrentDisplay(),
0
};
clCreateContextFromType(contextProps, CL_DEVICE_TYPE_GPU, 0, &err);
We have checked the m_platform variable and the value is the correct platform id. Are there any special/additional steps in order to create the context, or is OpenCL/OpenGL interop not fully supported at this time on Android?
Thanks,
-Alex
Could you please double check all the properties you pass are actually valid and you actually have an active current context & display ? (Usually this error is returned when one of the three properties is invalid see clCreateContextFromType )
Maybe try to just render something in GLES first to see if it works.
Also could you please try to use clCreateContext instead of clCreateContextFromType to see if it changes anything ?
Hi Anthony,
I have checked the values for m_platform/eglGetCurrentContext()/eglGetCurrentDisplay() and they are all valid values. In addition, they are consistent with the values returned from EGL14.eglGetCurrentContext().getNativeHandle() and EGL14.eglGetCurrentDisplay().getNativeHandle() for the surface. Rendering in GLES works correctly.
Using the following code I get the same error message returned from the call to clCreateContext:
clGetDeviceIDs(m_platform, CL_DEVICE_TYPE_GPU, 1, &m_device, NULL);
clCreateContext(contextProps, 1, &m_device, NULL, NULL, &err);
Many thanks,
Alex
Hi akrolik
Just to keep you updated, we have not had much time to look at this recently, hence the lack of a reply. We hope to get to this soon, however cannot give you an ETA at this time.
In case this applies to you, if you are a partner/customer of ARM, you are most likely entitled to dedicated support through our support channel.
If you need a quicker response and are a partner of ours, please use the support channel rather than this public forum.
Kind Regards,
Michael McGeagh
Hi Alex,
I did some test on Nexus10, both clCreateContextFromType() and clCreateContext() work.
Can I have more information about this:
1. How do you build your application? (Header files, libraries, compiler)
2. Which extensions are supported in your platform?(call clGetPlatformInfo() to get CL_PLATFORM_EXTENSIONS related information )
BR,
Sheri
Hi Sheri,
There are two situations that might cause failure CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR (-1000) when creating cl context from gles context.
1. Invalid current context & display: You mentioned these two are valid, so won't caused by this.
2. Library linking issue: That's why I asked how you build your program. Please make sure -lGLES_mali(-lOpenCL) is before -lEGL -lGLESv2.
Please try again, thanks.
We were using the order -lEGL -lGLESv2 -lOpenCL originally.
Using the original order this gives the CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR error, the context and display were reported by eglGetCurrentContext/eglGetCurrentDisplay as
Using the order in your post (-lOpenCL -lEGL -lGLESv2) the error reported is CL_INVALID_PROPERTY since both the context and display are now invalid (both are reported as 0). However, we are still able to draw within the GL context.
Thanks for you feedback, can I ask what is your libOpenCL.so link to, is it directly link to libGLES_mali.so? Please try only link with libGLES_mali.so without libEGL.so and libGLESv2.so.
The symlinks for libOpenCL.so are:
libOpenCL.so -> libOpenCL.so.1
libOpenCL.so.1 -> libOpenCL.so.1.1
libOpenCL.so.1.1 -> /vendor/lib/egl/libGLES_mali.so
Without the -lEGL -lGLESv2 flags the build fails with undefined references for the egl* and gl* functions used in the project (for example eglGetCurrentContext)
That's odd: all the symbols are in libGLES_mali.so so it should work.
Can you try to create a symlink
/system/lib/libGLES_mali.so -> /vendor/lib/egl/libGLES_mali.so
And to link directly against libGLES_mali.so ?
Anthony
Do you get the same issues if you add -lGLES_mali as your first entry?
I have pulled libGLES_mali.so off the device, placed it in the ndk lib directory and replaced -lOpenCL -lEGL -lGLESv2 with -lGLES_mali as Michael indicated. This works! The shared context is created without error and CL/GL interop looks to be working.
Thank you all for your help,