GPU computing Stay up to date in OpenCL, DirectCompute, CUDA, CAL and OpenGL information

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Friday, 23 October 2009

About OpenCL OpenGL interop..

Posted on 14:44 by Unknown
Right now the only way of getting it, is in Apple implementation in Snow Leopard and works for Nvidia and AMD cards (GPUs)..
For other platforms (OSs) seems that is getting more time than hoped but finally the promising OpenGL interop is coming soon..
as in the last week the cl_gl_khr_sharing was published in Khronos registry and was also added to the specification document now at revision 48..

Right now seems that the support of OpenGL OpenCL in Snow is not source code stable as per the new release as the property for context creation changes from CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE to CL_CGL_SHAREGROUP_KHR and also requires to pass
in addition the current GL context CL_GL_CONTEXT_KHR..
Note that seems that OpenGL interop cannot created on contexts having CPU devices attached on this platform..

On all platforms this interop requires first creating an OpenGL context and then creating a OpenCL context passing info about the OpenGL context with is windowing system dependant (and also some info about the drawable associated to the OpenGL context in non Apple platforms).

On Apple platform a context with OpenGL interop is created by getting the CGL share group associated to the wished OpenGL context, and passing that to clCreateContext via the property (in first parameter) CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE.

See the following code snippet from Procedural Grass demo in compute_engine.cpp:
if(bUseOpenGLContext)
{
printf(SEPARATOR);
printf("Compute Engine: Using active OpenGL context...\n");

CGLContextObj kCGLContext = CGLGetCurrentContext();
CGLShareGroupObj kCGLShareGroup = CGLGetShareGroup(kCGLContext);

cl_context_properties akProperties[] = {
CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE,
(cl_context_properties)kCGLShareGroup, 0
};

// Create a context from a CGL share group
//
m_kContext = clCreateContext(akProperties, 0, 0, clLogMessagesToStdoutAPPLE, 0, 0);
}
else
{
uint uiAvailableDeviceCount = 0;
iError = clGetDeviceIDs(NULL, kRequestedDeviceType, uiCount, akAvailableDeviceIds, &uiAvailableDeviceCount);
if (iError != CL_SUCCESS)
{
printf("Error: Failed to locate compute device!\n");
return false;
}

m_kContext = clCreateContext(0, uiAvailableDeviceCount, akAvailableDeviceIds, NULL, NULL, &iError);
}

Also note that per new spec code below (defining cl_context_properties akProperties[]) should be changed to:
cl_context_properties akProperties[] = {
CL_GL_CONTEXT_KHR,
(cl_context_properties)wglGetCurrentContext(),
CL_WGL_HDC_KHR,
(cl_context_properties)wglGetCurrentDC(), 0
};
cl_context_properties akProperties[] = {
CL_GL_CONTEXT_KHR,
kCGLContext
CL_CGL_SHAREGROUP_KHR,
(cl_context_properties)kCGLShareGroup, 0
};

Some Apple demos use it as Nbody, Displacament mapping, Grass..
all you have to do to enable disable the support in it is via defining USE_GL_ATTACHMENT to 1 or 0.

If I remember correctly in Apple also there is a flag when creating a OpenGL context for specifying that we want that device where is created it supports OpenCL contexts also..
(for other OSes is similar functionality provided by the extension..)
I will try to update it with more info and perhaps provide samples for every OSs..

For more info see (perhaps you have to login in ADC): "Using OpenCL with OpenGL” section of "OpenCL Programming Guide for Mac OS X"
which is currently no avaiable.. (PDF)
Also seems that for AMD cards 10.6.2 update will make them finally robust and stable in OpenCL..

Also I have found bits in AMD SDK 2.0beta4 showing cl_gl_amd_sharing and also CAL GL interop..
The case of CAL GL interop is at least for smiling since it's reported as supported by the CAL API extensions reporting function since at least a year (see Everest builds in Windows which provide CAL information..) But noneless is in the Catalyst 9.11 (fglrx 8.67 in Linux )release
where finally we can find bits of calGLAssociate function and others as this.. Still not working as they aren't exported by CAL libraries..
Also the GL header (cl_gl.h) in AMD OpenCL SDK includes the bits of the extension..

The Nvidia OpenCL library shows no signs of OpenGL interop but you have to remind that the latest version released in late September 2009 was the same as released by 10 September to registered developers and the driver is dated 28 August 2009 so almost two months old now..
Also Nvidia is aware that this is a current limitation as it list with the release notes
This no precludes Nvidia SDK demos from having support for it/ making use of it..
You have to use #define GL_INTEROP in the source code or compile with -DGL_INTEROP..
Anyway this won't fully enable the demos as the context must be created with OpenGL interop,
basically:

(windows)
cl_context_properties akProperties[] = {
CL_GL_CONTEXT_KHR,
HGLRC handle,
CL_WGL_HDC_KHR,
(cl_context_properties)HDC handle, 0
};
(linux)
cl_context_properties akProperties[] = {
CL_GL_CONTEXT_KHR,
GLXContext handle,
CL_WGL_HDC_KHR,
(cl_context_properties)Display handle, 0
};
(windows&linux)
m_kContext = clCreateContext(akProperties, 0, 0, 0, 0, 0);

Interesting is how this will mix with say frameworks as GLUT, SDL, specific window creation code for OpenGL 3.0 contexts, etc..

If I had a cristall ball and made money predicting the future :-) I will say OpenGL interop is coming in Nvidia 195.xx series.. Yes that are supposed (by me) to have also CUDA 3.0 support and also Fermi support.. so is I think dependent on Fermi release but say before of the year
and perhaps in very late November/early December..
Note that I expect OpenGL interop improving in CUDA also with that release namely that CUDA supports texture interop (texture buffer object support) in addition to existing VBO, PBO to direct interop also (right now I think the interop is get copying buffers in GPU memory which is anyway fast (but reduces memory with buffer duplication))..
Note that this support was by error saying as supported by CUDA 2.2 beta release for registered develeopers back in March 2009 with first Nvidia 185.xx drivers..

For AMD I will be surprised if they have before end of the year (as they have much work left see my post on OpenCL exntesinos) and I will be happy if they have by late February or March 2009..

In the meantime I will try to provide OpenGL emulation in my OpenCL wrapper library for SDKs with image support..
I will update the post to show how to modify demos from AMD, Nvidia and Apple OpenCL SDKs to use
this extension..
Also the coming soon Windows demos of the Apple demos will have this enabled..
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Posted in | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • Porting CUDA to OpenCL!
    Well so you want to port CUDA code to OpenCL: you are in AMD GPU competition of porting Cuda codes to opencl (see previous post) or you are ...
  • Megapost!
    Today fools{ *GTX 485 is 512 cores 3gbytes gddr5 and 850/1750 shaders.. *ati 5990 has 4 gpus in board.. *bulldozer benchmarks }end fools.. A...
  • About ATI and Nvidia drivers (OCL included)!
    Hi I have been investigating AMD and Nvidia drivers.. for 10.3 there are 3d hooks support for 120hz monitors but is d3d9 d3d10 or d3d11 enab...
  • things found in CUDA forums
    Also some CUDA news: Mandelbulb stereo angalyph -> have to port to 3D Vision http://forums.nvidia.com/index.php?showtopic=150985&st=2...
  • opencl/opengl linux interop! seen in opencl cuda 3.0 sdk samples
    Following my OpenCL/OpenGL Window interop work: now has come to Linux  for Nvidia GPU computing registered developers via 195.17 driver! Als...
  • State of the blog..
    Sorry for the delay guys of posting code of Apple OpenCL demos port.. the blog has been with no updated for more than 2 weeks in this rapid ...
  • Optix and OpenCL SDKs with Visual Studio 2010
    Optix 1.0 ========= install cg download Cmake 2.80 cmake says error dumpbin not found and it is cuda doesn't work with vc2010 so copy pt...
  • CUDA 3.0 forums stuff!
    1.Getting CUBIN instead of ELF If you need the older text format, you can disable ELF cubins in nvcc.profile by changing "CUBINS_ARE_EL...
  • News from the web!
    Some things learned in AMD forums: 1.Why 3xxx no OpenCL: Compute shader mode is a hardware feature that did not exist in the HD38XX line of ...
  • Shaders: measuring perf, source translation and parsing different languages!
    Hi, I hope to be pretty exhaustive of options for parsing and translating between graphics and compute shaders ( some open source) For DX sh...

Blog Archive

  • ►  2013 (5)
    • ►  September (1)
    • ►  March (3)
    • ►  February (1)
  • ►  2012 (1)
    • ►  December (1)
  • ►  2010 (46)
    • ►  July (4)
    • ►  May (1)
    • ►  April (3)
    • ►  March (9)
    • ►  February (15)
    • ►  January (14)
  • ▼  2009 (125)
    • ►  December (51)
    • ►  November (53)
    • ▼  October (21)
      • IBM OpenCL support!
      • Whises for OpenCL 1.1 and more!
      • 3D Vision and Direct3D 11
      • H264 harware decoding/ encoding GPUs
      • Interop GPU computing graphics apis stuff
      • 3D vision good stuff
      • Getting PTX, AMD_IL from languages:
      • Updated CUBLAS before CUDA 3.0
      • ATI and Nvidia extensions for DX11 and 10.1 ARBs
      • OpenGL 5870 extensions
      • Nvidia 195
      • News from the web!
      • Mem export in OpenCL
      • Double precision support in GPU computing APIs and...
      • Support 3d image write on CUDA and with OpenCL wra...
      • About OpenCL OpenGL interop..
      • Improved OpenCL-Z!
      • About binary compatiblity on OpenCL..
      • AMD IL backend for LLVM and getting AMD IL in MacOS?
      • Building OpenCL kernels from AMD IL code or device...
      • A CAL wrapper for getting AMD IL from OpenCL AMD G...
Powered by Blogger.

About Me

Unknown
View my complete profile