[osg-users] [3rdparty] osgCuda: Using CUDA in osg - Problem with Threading

Mick mick.svt at googlemail.com
Thu Mar 12 04:34:42 PDT 2009

Hi Robert.

Robert Osfield wrote:
> I do hope OpenCL fairs a bit better in this respect.

By the way: as I already mentioned in the first post the osgCuda ist based on a kit which we
call osgPipe. In the near future it should not be too difficult to add OpenCL with the help of the

Robert Osfield wrote:
> I'm curious, are you able to mix and match the Driver and Runtime API's?

No - it is not possible to mix the APIs. 

Robert Osfield wrote:
> Do you want to dive in a make changes to your local
> OpenSceneGraph/GraphicsThread classes get it working robustly for
> osgCuda and then post me your changes.

Our approach using osg::Operation is quite robust. So far we did not recognize any drawbacks or
a lack of stability. We evaluated different approaches to give the GraphicsThread the chance to clean
up its resources.
The easiest and simplest way is to call OperationThread::_operationQueue->releaseAllOperations()
right before the thread stops. It is just the one new line in GraphicsThread::run() - please see the code below
(in GraphicsThread.cpp):

void GraphicsThread::run()
    // make the graphics context current.
    GraphicsContext* graphicsContext = dynamic_cast<GraphicsContext*>(_parent.get());
    if (graphicsContext)



    if (graphicsContext)


This works fine without touching anything else of the core code. osgCuda takes care of adding a proper
osg::Operation to the operation-queue. Its operation then releases the CUDA resources in its release-method.
That's it.

osgCuda is already in a good shape and needs to be tested by the community but there is some documentation work left.

Best regards,

SVT Group

Read this topic online here:

More information about the osg-users mailing list