simplest Optix code:unable to set CUDA device

Optix SDK examples cannot run on my Computer.

Then I tested with the below simple code.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <optix.h>
#include <sutil.h>

int main(int argc, char *argv[])

  RTcontext context;
  RTbuffer buffer;
  RTvariable var_buffer;
  RT_CHECK_ERROR(rtBufferCreate(context, RT_BUFFER_OUTPUT, &buffer));
  RT_CHECK_ERROR(rtBufferSetFormat(buffer, RT_FORMAT_FLOAT4));
  RT_CHECK_ERROR(rtBufferSetSize2D(buffer, 256u, 256u));
  RT_CHECK_ERROR(rtContextDeclareVariable(context, "result_buffer", &var_buffer));

  /*EntryPoint and Raytype*/

  char path_to_ptx[512];
  RTprogram ray_gen_program;
  RTvariable draw_color;
  sprintf(path_to_ptx, "%s/%s", sutilSamplesPtxDir(), "");// is copied from SDK sample1
  RT_CHECK_ERROR(rtProgramCreateFromPTXFile(context,path_to_ptx, "draw_solid_color",&ray_gen_program));
  RT_CHECK_ERROR(rtProgramDeclareVariable(ray_gen_program, "draw_color",&draw_color));


  return 0;



, the code compiles and runs normally. But with that line, the code compiles normally but runs with the error:

OptiX Error: Invalid context (Details: Function “RTresult _rtContextCompile(RTcontext)” caught exception: Unable to set the CUDA device., [3735714])

OS: Linux smithwick 3.5.0-51-generic #76-Ubuntu SMP Thu May 15 21:19:10 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
CPU: Intel(R) Xeon(R) CPU E5620 @ 2.40GHz
GPU: GeForce GTX 480; Tesla C2070
OptiX: 3.6.0
CUDA: release 5.5, V5.5.0

How to view the display driver version?

$ nvidia-smi
Thu Jul 24 16:45:59 2014
| NVIDIA-SMI 5.319.82 Driver Version: 319.82 |
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
| 0 Tesla C2070 Off | 0000:06:00.0 Off | Off |
| 45% 83C P8 N/A / N/A | 11MB / 6143MB | 0% Default |
| 1 GeForce GTX 480 Off | 0000:0A:00.0 N/A | N/A |
| 44% 47C N/A N/A / N/A | 81MB / 1535MB | N/A Default |

| Compute processes: GPU Memory |
| GPU PID Process name Usage |
| 1 Not Supported |

Just out of curiosity, do you still get the error if you set rtContextSetDevices to use only device 0? How about only device 1?

To get your display driver version, see [url]linux - How to get the nvidia driver version from the command line? - Stack Overflow for example.

Yes, I still get the error.

Does this problem only occur with OptiX? Can you run the CUDA samples that came with the CUDA toolkit?

Yes, the problem only occurs with Optix.
I can run other cuda programs normally.

Problem solved. I just install latest driver for the GPUs and updated cuda toolkit to 6.0. Thanks guys!

Having similar problems, can you provide some more info on your working config? For example:

  • kernel

uname -a

  • packages

dpkg -i | grep nvidia

  • nvidia hw

nvidia-smi -q

Optix docs say CUDA 5.5 not 6, so curious to see if there is compatibility (source or binary).


I have also this problem, can’t run the OptiX demo programs under Ubuntu 14.04. I get the “Unable to set the CUDA device., [3735714]” error.

OS: Linux 3.13.0-32-generic #57-Ubuntu SMP Tue Jul 15 03:51:08 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
GPU: GeForce GTX 780
OptiX: 3.6.0
CUDA: release 5.5, V5.5.0

I also tried to compile using CUDA 6.0, but I have the same problem.
Any help?


I fixed my problem after install the 331.89 drivers