Results 1 to 9 of 9

Thread: Can't create OpenCL context from OpenGL with specific device

  1. #1
    Junior Member
    Join Date
    Mar 2010
    Posts
    5

    Can't create OpenCL context from OpenGL with specific device

    Hi guys, I have a problem with creating and OpenCL context with specific OpenCL device (GPU).

    My specs: Mac Mini, latest Snow Leopard
    Code :
    ---> CL_PLATFORM_NAME:         Apple
    ---> CL_PLATFORM_VENDOR:       Apple
    ---> CL_PLATFORM_VERSION:      OpenCL 1.0 (Oct 16 2009 04:12:08)
    ---> CL_PLATFORM_PROFILE:      FULL_PROFILE
    ---> CL_PLATFORM_EXTENSIONS:   
     
    ---> CL_DEVICE_NAME:           GeForce 9400
    ---> CL_DEVICE_VENDOR:         NVIDIA
    ---> CL_DRIVER_VERSION:        CLH 1.0
    ---> CL_DEVICE_VERSION:        OpenCL 1.0 
    ---> CL_DEVICE_PROFILE:        FULL_PROFILE
    ---> CL_DEVICE_EXTENSIONS:     cl_khr_byte_addressable_store cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_APPLE_gl_sharing cl_APPLE_SetMemObjectDestructor cl_APPLE_ContextLoggingFunctions
    Code :
    err = clGetPlatformIDs(1, &pID, &num);
    err = clGetDeviceIDs(pID, CL_DEVICE_TYPE_GPU, 1, &dID, &num);
     
    // OpenCL context running atm...	
    CGLContextObj kCGLContext = CGLGetCurrentContext();              
    CGLShareGroupObj kCGLShareGroup = CGLGetShareGroup(kCGLContext);
     
    cl_context_properties akProperties[] = { 
    	CL_CONTEXT_PLATFORM, (cl_context_properties)pID,	
    	CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE, (cl_context_properties)kCGLShareGroup,
    	0
    };
     
    // here I pick my specific GPU
    // this works only with CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE disabled (but I need interop)
    // error is -31, CL_INVALID_DEVICE_TYPE
    context.context = clCreateContext(akProperties, 1, &dID, clLogMessagesToStdoutAPPLE, NULL, &err);
     
    // this works all the time, but i can't pick my GPU manually (value is zero) 
    context.context = clCreateContext(akProperties, 0, 0, clLogMessagesToStdoutAPPLE, NULL, &err);

    As you can see can int the code above I can't pick my GPU "manually" to create OpenCL context (with OpenGL). When I try that, i always get error -31, CL_INVALID_DEVICE_TYPE.
    I don't know where the problem is. The platform and device query works absolutely fine. I know this is not big deal especially in my case (master thesis), but I'd like to know what I could have done wrong.

  2. #2
    Junior Member
    Join Date
    Mar 2010
    Posts
    5

    Re: Can't create OpenCL context from OpenGL with specific device

    I tried also
    Code :
    clCreateContextFromType(akProperties, CL_DEVICE_TYPE_GPU, clLogMessagesToStdoutAPPLE, NULL, &err);
    But the result is the same - it does not work with the CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE context property enabled ;(

  3. #3
    Senior Member
    Join Date
    Jul 2009
    Location
    Northern Europe
    Posts
    311

    Re: Can't create OpenCL context from OpenGL with specific device

    How much memory do you have? I've had issues with Mac Mini's with only 1GB of RAM (128MB of VRAM) before. If that's the case I'd suggest trying it on a 2GB (256MB VRAM) config. If not, you should probably try some of the Apple sample demos unmodified, and if they fail, file a bug with them. Sorry I can't be of more help.

  4. #4
    Junior Member
    Join Date
    Apr 2009
    Posts
    8

    Re: Can't create OpenCL context from OpenGL with specific device

    There are relevant comments in (Apple's) cl_gl_ext.h header file (where CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE) is defined, which seem to confirm your observations.

    Since cl_APPLE_gl_sharing does not appear to be in the extension registry, you'll need to ask Apple for more information.

  5. #5
    Junior Member
    Join Date
    Mar 2010
    Posts
    5

    Re: Can't create OpenCL context from OpenGL with specific device

    Thank you guys.

  6. #6
    Junior Member
    Join Date
    Mar 2010
    Posts
    5

    Re: Can't create OpenCL context from OpenGL with specific device

    Quote Originally Posted by Chris244
    There are relevant comments in (Apple's) cl_gl_ext.h header file (where CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE) is defined, which seem to confirm your observations.

    Since cl_APPLE_gl_sharing does not appear to be in the extension registry, you'll need to ask Apple for more information.
    You were right, it's written there. I cannot use specific GPU. The OpenGL context device is selected by default. I don't know why, but it's like that.
    // Additional CL devices can also be specified using the <num_devices> and <devices> arguments.
    // These, however, cannot be GPU devices. On Mac OS X, you can add the CPU to the list of CL devices
    // (in addition to the CL compliant devices in the CGL share group) used to create the CL context.
    // Note that if a CPU device is specified, the CGL share group must also include the GL float renderer;
    // Otherwise CL_INVALID_DEVICE will be returned.

  7. #7
    Junior Member
    Join Date
    Mar 2010
    Posts
    3

    Re: Can't create OpenCL context from OpenGL with specific device

    It is possible to use a specific GPU device, however with this extension the choice is specified using CGL, not CL.

    This extension allows a CL context to be created containing the same devices as a GL share group; the GPU devices are specified when the related CGL context is created. Other non-GPU compute devices may be included in the CL context, these are specified in the other arguments to clCreateContext, but only if share group includes the GL software renderer.

    The CGL pixel format may be used to specify which devices to include in the GL context and share group, i.e. by creating a format which only matches a certain device (take a look at the CGL and CG documentation). Once a matching pixel format is found it is used to create a CGL context, from which the share group is obtained, and finally passed to clCreateContext.

  8. #8
    Senior Member
    Join Date
    Sep 2002
    Location
    Santa Clara
    Posts
    105

    Re: Can't create OpenCL context from OpenGL with specific device

    You need to make sure you create a CGLsharegroup which includes all the appropriate GPU devices in the system. Then you can create a CL context using the CGLsharegroup. The CL context will now include all GPUs. You can then use clGetGLContextInfoAPPLE to query the following:

    a) The cl_device_id value for the GPU associated with the virtual screen in your CGLcontext (created using the CGLsharegroup)

    b) The mapping of cl_device_id values to virtual screen(s) associated with the given CGLContext.

    You can then use this information to determine whether you want to use the same GPU for both GL & CL or different GPUs.

    Hopefully this answers your question.

  9. #9
    Junior Member
    Join Date
    Mar 2010
    Posts
    5

    Re: Can't create OpenCL context from OpenGL with specific device

    Thank you .

Similar Threads

  1. Replies: 1
    Last Post: 08-20-2010, 11:19 AM
  2. Unable to create OPENGL|ES context error 12293
    By mjabasolo in forum OpenGL ES general technical discussions
    Replies: 0
    Last Post: 05-07-2009, 05:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •