0

I am getting CUDA_ERROR_INVALID_DEVICE error when creating a cuda context via cuCtxCreate.

My code is creating a context and getting device from it and creating a new context.

Any idea why I can't create another context?

#include<cuda.h>
#include<assert.h>

int main(){
        cuInit(0);
        CUcontext ctx;
        CUdevice device;

        CUdevice dev2;
        CUcontext c2;

        assert(cuDeviceGet(&device,0) == 0 );
        assert(cuCtxCreate(&ctx, 0, device) == 0);
        assert(cuCtxGetDevice(&dev2) == 0);
        assert(cuCtxCreate(&c2,0,dev2) == 0);
        return 0;
}
einpoklum
  • 118,144
  • 57
  • 340
  • 684
user1205476
  • 391
  • 1
  • 3
  • 12
  • 2
    I'm pretty sure `device==dev2` here, so you are effectively creating two contexts for a single device from a single host thread. Why do you want to do this? – harrism Apr 24 '12 at 04:47
  • 2 threads can create different contexts on the same device. Then why not one thread create two different contexts? I am doing it to build a performance analysis f/w. I want to create a context on which performance analysis events live and don't get destroyed by user code destroying a context. – user1205476 Apr 24 '12 at 05:02
  • 2
    Have you verified that the device is not in exclusive mode? – harrism Apr 24 '12 at 06:14
  • Yes, that was the case. It worked find on a device which was not in exclusive mode. – user1205476 Apr 25 '12 at 04:22

1 Answers1

3

The problem was that the user had the device in exclusive mode, which prohibits creating two contexts on the single device.

harrism
  • 26,505
  • 2
  • 57
  • 88