Hello Guest

[CLOSED] OpenCL performance degrades over time with shared context

  • 2 Replies
If I create an OpenCL context shared with the OpenGL context, my framerate drops from about 120 to about 30. This does not happen if the drawable is not shared.
The framerate then continues to fall over time, and appears to be CPU bottlenecked.

This is without actually doing anything with the context. Just creating it when the program starts up.

Edit: Creating the context with either no devices, or with a CPU device does not cause the slowdown.
« Last Edit: June 21, 2012, 16:20:23 by thogil »

Re: [BUG] OpenCL performance degrades over time with shared context
« Reply #1 on: June 22, 2012, 10:36:55 »
I've tried switching to the version of jocl from jocl.org, but have the exactl same issue. The really strange thing is that there doesn't appear to be any bottleneck anywhere.

My engine reports timers for both CPU and GPU code as it is executed each frame, and it's showing a uniform increase in both CPU and GPU execution times, as if both processors were slowing down. There no bottlenecks appearing, and no gaps in the timers as if some external code is running at some point in the frame..

Re: [BUG] OpenCL performance degrades over time with shared context
« Reply #2 on: June 22, 2012, 13:21:48 »
Right, well after some more investigation, I've found that if sharing CL and GL contexts, creating a texture and then attaching it to a framebuffer causes all operations on both the GPU and the CPU to slow down until that texture is deleted.

Using this CL setup code:
Code: [Select]
// find platform
List<CLPlatform> platforms = CLPlatform.getPlatforms();
if ( platforms == null || platforms.size() == 0 ) {
   throw new RuntimeException( "No OpenCL platforms found." );

CLPlatform platform = platforms.get( 0 );

// find devices
Filter<CLDevice> sharingFilter = new Filter<CLDevice>()
   public boolean accept( CLDevice device )
      CLDeviceCapabilities capabilities = CLCapabilities.getDeviceCapabilities( device );
      return capabilities.CL_KHR_gl_sharing;

this.devices = platform.getDevices( CL10.CL_DEVICE_TYPE_GPU, sharingFilter );
if ( devices == null || devices.size() == 0 ) {
   throw new RuntimeException( "No OpenCL devices found with OpenGL sharing support." );

// create context
this.context = CLContext.create( platform, devices, new CLContextCallback()
   protected void handleMessage( String error, ByteBuffer privateInfo )
      logger.error( error );
}, drawable, null );

Placing this code on initialisation causes a significant framerate drop (but only when a shared CL context has been created):
Code: [Select]
int fbo = glGenFramebuffers();
glBindFramebuffer( GL_FRAMEBUFFER, fbo );

for ( int i = 0; i < 10000; i++ ) {
   int id = glGenTextures();

   glActiveTexture( GL_TEXTURE0 );
   glBindTexture( GL_TEXTURE_2D, id );

   glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
   glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, (ByteBuffer)null );


   glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, id, 0 );

   //glDeleteTextures( id );

glDeleteFramebuffers( fbo );

Uncommenting the glDeleteTextures call restores the framerate to normal.
This may well be a driver bug (running a 6870). I don't suppose anyone else can reproduce this?

Edit: I updated my drivers to the latest beta version (Catalyst 12.6 Beta), and it seems to be fixed.
« Last Edit: June 22, 2012, 13:40:50 by thogil »