clCreateContext -> CL_INVALID_DEVICE (-33) in case of GPU usage from multiple threads

I just want to share problem I encountered with clarifying its reasons and thus - its fix :)

Situation:

  • clCreateContext returns CL_INVALID_DEVICE (-33)
  • Linux + multiple Tesla K40m

Reason:

  • GPUs were in Exclusive mode (nvidia-smi shows “E. Process” in bottom right corner)
  • App was trying to use each GPU from two threads for separate CUDA computations and so - exclusive mode led to failure of context creation

Fix:

  • Reset GPU to default mode: “nvidia-smi -i 239 -c 0” where 239 - GPU id. And now nvidia-smi should show “Default” in bottom right corner
  • Or use each GPU once in app