Interoperation problem: all CUDA-capable devices busy or unavailable

Hi folks,

I’m following the CUDA-by-example book and the code provided with it. I am trying to get the Interoperation between CUDA and OpenGL working, but no matter what I do, I seem to be running into the “all CUDA-capable devices are busy or unavailable” error.

Here is the code I’m working with now (after the suggestions from StackOverflow about doing GLUT stuff first):

#include "common/gl_helper.h"
#include "cuda.h"
#include "cuda_gl_interop.h"
#include "common/book.h"

#define DIM 1024

PFNGLBINDBUFFERARBPROC    glBindBuffer     = NULL;
PFNGLDELETEBUFFERSARBPROC glDeleteBuffers  = NULL;
PFNGLGENBUFFERSARBPROC    glGenBuffers     = NULL;
PFNGLBUFFERDATAARBPROC    glBufferData     = NULL;

GLuint bufferObj;
cudaGraphicsResource *resource;

int main( void ) {
    cudaDeviceProp prop;
    int dev;	

    int c=1;
    char* dummy = "";
    glutInit( &c, &dummy );
    glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGBA );
    glutInitWindowSize( DIM, DIM );
    glutCreateWindow( "bitmap" );

    glBindBuffer    = (PFNGLBINDBUFFERARBPROC)GET_PROC_ADDRESS("glBindBuffer");
    glDeleteBuffers = (PFNGLDELETEBUFFERSARBPROC)GET_PROC_ADDRESS("glDeleteBuffers");
    glGenBuffers    = (PFNGLGENBUFFERSARBPROC)GET_PROC_ADDRESS("glGenBuffers");
    glBufferData    = (PFNGLBUFFERDATAARBPROC)GET_PROC_ADDRESS("glBufferData");

    glGenBuffers(1, &bufferObj);
    glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, bufferObj);
    glBufferData(GL_PIXEL_UNPACK_BUFFER_ARB, DIM*DIM*4, NULL, GL_DYNAMIC_DRAW_ARB);

    memset(&prop, 0, sizeof(cudaDeviceProp));
    prop.major = 1;
    prop.minor = 0;
    HANDLE_ERROR(cudaChooseDevice(&dev, &prop));
    HANDLE_ERROR(cudaGLSetGLDevice(dev));

    HANDLE_ERROR(cudaGraphicsGLRegisterBuffer(&resource, bufferObj, cudaGraphicsRegisterFlagsWriteDiscard));
}

Regardless, the problem occurs on the last line. I have tried running example code for CUDA-6.5 provided with the installation, but everything seems to result in this error. I can, however, render in OpenGL if I just swap the memory back to CPU (not do interoperation…). And normal kernels work fine as well.

I have tried closing all windows except VS2010, but same problem persists.

I am using Windows 7 x64, Visual Studio 2010, CUDA 6.5. I have a GTX650.

Please let me know if you have any clues as to why this is happening. Given that the book and all the code do not seem to cause other people problems (Google search turned up nothing), I’m guessing it is something I did.

Thanks in advance

I’m guessing that based on posting similarity this was cross-posted here:

[url]c++ - CUDA with OpenGL: all CUDA-capable devices are busy or unavailable - Stack Overflow

Based on that, it seems the solution was to use the NVIDIA GPU for the OpenGL/display rather than the integrated graphics.

Hah, yeah it was. But people on SO hate difficult questions, and choose to pick on stupid stuff instead (going as far as suggesting that the code repeatedly given by Nvidia is wrong). I found the solution myself.