具有多个GPU的OpenCL/OpenGL互操作 [英] OpenCL/OpenGL Interop with Multiple GPUs

查看:327
本文介绍了具有多个GPU的OpenCL/OpenGL互操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用OpenCL/OpenGL互操作的多个GPU时遇到问题.我正在尝试编写一个呈现密集计算结果的应用程序.最后,它将运行一个优化问题,然后根据结果将某些内容渲染到屏幕上.作为测试用例,我将从本课程的粒子模拟示例代码开始: http://web.engr .oregonstate.edu/〜mjb/sig13/

I'm having trouble using multiple GPUs with OpenCL/OpenGL interop. I'm trying to write an application which renders the result of an intensive computation. In the end it will run an optimization problem, and then, based on the result, render something to the screen. As a test case, I'm starting with the particle simulation example code from this course: http://web.engr.oregonstate.edu/~mjb/sig13/

示例代码创建一个OpenGL上下文,然后使用cl_khr_gl_sharing扩展创建一个共享状态的OpenCL上下文.当我使用单个GPU时,一切正常.创建上下文如下所示:

The example code creates and OpenGL context, then creates a OpenCL context that shares the state, using the cl_khr_gl_sharing extension. Everything works fine when I use a single GPU. Creating a context looks like this:

3. create an opencl context based on the opengl context:
  cl_context_properties props[ ] =
  {
      CL_GL_CONTEXT_KHR, (cl_context_properties) glXGetCurrentContext( ),
      CL_GLX_DISPLAY_KHR, (cl_context_properties) glXGetCurrentDisplay( ),
      CL_CONTEXT_PLATFORM, (cl_context_properties) Platform,
      0
  };

  cl_context Context = clCreateContext( props, 1, Device, NULL, NULL, &status );
  if( status != CL_SUCCESS) 
  {
      PrintCLError( status, "clCreateContext: " );
      exit(1);
  }

此后,该示例使用clCreateFromGLBuffer创建共享的CL/GL缓冲区.

Later on, the example creates shared CL/GL buffers with clCreateFromGLBuffer.

现在,我想从两个GPU设备创建一个上下文:

Now, I would like to create a context from two GPU devices:

cl_context Context = clCreateContext( props, 2, Device, NULL, NULL, &status );

我已经成功打开了设备,并可以查询它们都支持cl_khr_gl_sharing,并且它们都可以单独工作.但是,当尝试如上所述创建上下文时,我得到

I've successfully opened the devices, and can query that they both support cl_khr_gl_sharing, and both work individually. However, when attempting to create the context as above, I get

CL_INVALID_OPERATION 

这是cl_khr_gl_sharing扩展添加的错误代码.在扩展名描述(如上链接)中,它说

Which is an error code added by the cl_khr_gl_sharing extension. In the extension description (linked above) it says

  • CL_INVALID_OPERATION(如果上下文或共享组对象为 为CGL,EGL,GLX或WGL之一以及任何 符合以下条件:

  • CL_INVALID_OPERATION if a context or share group object was specified for one of CGL, EGL, GLX, or WGL and any of the following conditions hold:

  • OpenGL实现不支持窗口系统 上下文或共享组对象所针对的绑定API 指定.
  • 多个属性CL_CGL_SHAREGROUP_KHR之一, CL_EGL_DISPLAY_KHR,CL_GLX_DISPLAY_KHR和CL_WGL_HDC_KHR为 设置为非默认值.
  • 两个属性CL_CGL_SHAREGROUP_KHR和 CL_GL_CONTEXT_KHR设置为非默认值.
  • 参数中指定的任何设备都不能 支持共享OpenGL数据存储的OpenCL对象 对象,如第9.12节所述."
  • The OpenGL implementation does not support the window-system binding API for which a context or share group objects was specified.
  • More than one of the attributes CL_CGL_SHAREGROUP_KHR, CL_EGL_DISPLAY_KHR, CL_GLX_DISPLAY_KHR, and CL_WGL_HDC_KHR is set to a non-default value.
  • Both of the attributes CL_CGL_SHAREGROUP_KHR and CL_GL_CONTEXT_KHR are set to non-default values.
  • Any of the devices specified in the argument cannot support OpenCL objects which share the data store of an OpenGL object, as described in section 9.12."

该描述似乎与我的情况完全不符.不能与多个GPU进行OpenCL/OpenGL互操作吗?还是我具有异构硬件?我从枚举的设备中打印了一些参数.我刚刚拿了两个随机的GPU,可以动手使用.

That description doesn't seem to fit any of my cases exactly. Is it not possible to do OpenCL/OpenGL interop with multiple GPUs? Or is it that I have heterogeneous hardware? I printed out a few parameters from my enumerated devices. I've just taken two random GPUs that I could get my hands on.

PlatformID: 18483216
Num Devices: 2

-------- Device 00 ---------
CL_DEVICE_NAME: GeForce GTX 285
CL_DEVICE_VENDOR: NVIDIA Corporation
CL_DEVICE_VERSION: OpenCL 1.0 CUDA
CL_DRIVER_VERSION: 304.88
CL_DEVICE_MAX_COMPUTE_UNITS: 30
CL_DEVICE_MAX_CLOCK_FREQUENCY: 1476
CL_DEVICE_TYPE: CL_DEVICE_TYPE_GPU

-------- Device 01 ---------
CL_DEVICE_NAME: Quadro FX 580
CL_DEVICE_VENDOR: NVIDIA Corporation
CL_DEVICE_VERSION: OpenCL 1.0 CUDA
CL_DRIVER_VERSION: 304.88
CL_DEVICE_MAX_COMPUTE_UNITS: 4
CL_DEVICE_MAX_CLOCK_FREQUENCY: 1125
CL_DEVICE_TYPE: CL_DEVICE_TYPE_GPU

cl_khr_gl_sharing is supported on dev 0.
cl_khr_gl_sharing is supported on dev 1.

请注意,如果我创建没有互操作部分的上下文(使得props数组如下所示),那么它将成功创建上下文,但是显然不能与应用程序的OpenGL端共享缓冲区.

Note that if I create the context without the interop portion (such that the props array looks like below) then it successfully creates the context, but obviously cannot share buffers with the OpenGL side of the application.

cl_context_properties props[ ] =
{
   CL_CONTEXT_PLATFORM, (cl_context_properties) Platform,
   0
};

推荐答案

调用这两行时:

CL_GL_CONTEXT_KHR, (cl_context_properties) glXGetCurrentContext( ), CL_GLX_DISPLAY_KHR, (cl_context_properties) glXGetCurrentDisplay( ),

CL_GL_CONTEXT_KHR, (cl_context_properties) glXGetCurrentContext( ), CL_GLX_DISPLAY_KHR, (cl_context_properties) glXGetCurrentDisplay( ),

调用需要来自具有新OpenGL上下文的新线程内部.通常每个线程一次只能为一个设备将一个OpenCL上下文与一个OpenGL上下文关联.

the calls need to come from inside a new thread with a new OpenGL context. You can usually only associate one OpenCL context with one OpenGL context for one device at a time per thread.

这篇关于具有多个GPU的OpenCL/OpenGL互操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆