# simplest Optix code:unable to set CUDA device

**URL:** <https://forums.developer.nvidia.com/t/simplest-optix-code-unable-to-set-cuda-device/34183>\
**Category:** OptiX\
**Created:** [July 24, 2014, 7:23pm UTC](https://forums.developer.nvidia.com/t/simplest-optix-code-unable-to-set-cuda-device/34183 "2014-07-24T19:23:32Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![lang](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@lang](https://forums.developer.nvidia.com/u/lang)\
**Post date:** [July 24, 2014, 7:23pm UTC](https://forums.developer.nvidia.com/t/simplest-optix-code-unable-to-set-cuda-device/34183/1 "2014-07-24T19:23:32Z")

</div>

Optix SDK examples cannot run on my Computer.

Then I tested with the below simple code.

```auto
#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;
  RT_CHECK_ERROR(rtContextCreate(&context));
  /*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));
  RT_CHECK_ERROR(rtVariableSetObject(var_buffer,buffer));

  /*EntryPoint and Raytype*/
  RT_CHECK_ERROR(rtContextSetRayTypeCount(context,1));
  RT_CHECK_ERROR(rtContextSetEntryPointCount(context,1));

  /*Program*/
  char path_to_ptx[512];
  RTprogram ray_gen_program;
  RTvariable draw_color;
  sprintf(path_to_ptx, "%s/%s", sutilSamplesPtxDir(), "sample3_generated_draw_color.cu.ptx");//draw_color.cu 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));
  RT_CHECK_ERROR(rtVariableSet3f(draw_color,0.462f,0.725f,0.0f));
  RT_CHECK_ERROR(rtContextSetRayGenerationProgram(context,0,ray_gen_program));

  /*Run*/
  RT_CHECK_ERROR(rtContextValidate(context));
  RT_CHECK_ERROR(rtContextCompile(context));

  RT_CHECK_ERROR(rtContextDestroy(context));
  return 0;
}

```

Without,

```auto
RT_CHECK_ERROR(rtContextCompile(context));

```

, 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])  
(/home/jlmiao/NVIDIA-OptiX-SDK-3.6.0-linux64/SDK/sample3/sample3.c:147)

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

> [@](#):
>
> Generally please provide the following information when reporting issues:  
> OS version, OS bitness, installed GPU(s), display driver version, OptiX version, CUDA version.

How to view the display driver version?

EDIT  
$ 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 |  
±----------------------------------------------------------------------------+

---

<div class="post-metadata">

**Author:** ![nljones](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/nljones/32/10329_2.png) [@nljones](https://forums.developer.nvidia.com/u/nljones)\
**Post date:** [July 24, 2014, 8:03pm UTC](https://forums.developer.nvidia.com/t/simplest-optix-code-unable-to-set-cuda-device/34183/2 "2014-07-24T20:03:16Z")

</div>

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](http://stackoverflow.com/questions/13125714/how-to-get-the-nvidia-driver-version-from-the-command-line%5B/url%5D) for example.

---

<div class="post-metadata">

**Author:** ![lang](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@lang](https://forums.developer.nvidia.com/u/lang)\
**Post date:** [July 24, 2014, 8:47pm UTC](https://forums.developer.nvidia.com/t/simplest-optix-code-unable-to-set-cuda-device/34183/3 "2014-07-24T20:47:18Z")

</div>

> [@nljones](#):
>
> Just out of curiosity, do you still get the error if you set rtContextSetDevices to use only device 0? How about only device 1?

Yes, I still get the error.

---

<div class="post-metadata">

**Author:** ![nljones](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/nljones/32/10329_2.png) [@nljones](https://forums.developer.nvidia.com/u/nljones)\
**Post date:** [July 24, 2014, 10:32pm UTC](https://forums.developer.nvidia.com/t/simplest-optix-code-unable-to-set-cuda-device/34183/4 "2014-07-24T22:32:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lang](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@lang](https://forums.developer.nvidia.com/u/lang)\
**Post date:** [July 25, 2014, 3:42am UTC](https://forums.developer.nvidia.com/t/simplest-optix-code-unable-to-set-cuda-device/34183/5 "2014-07-25T03:42:36Z")

</div>

> [@nljones](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![lang](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@lang](https://forums.developer.nvidia.com/u/lang)\
**Post date:** [July 26, 2014, 2:01pm UTC](https://forums.developer.nvidia.com/t/simplest-optix-code-unable-to-set-cuda-device/34183/6 "2014-07-26T14:01:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![angry\_octet](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@angry\_octet](https://forums.developer.nvidia.com/u/angry_octet)\
**Post date:** [July 30, 2014, 12:34am UTC](https://forums.developer.nvidia.com/t/simplest-optix-code-unable-to-set-cuda-device/34183/7 "2014-07-30T00:34:02Z")

</div>

Hi,  
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).

Thanks

---

<div class="post-metadata">

**Author:** ![juanjgon](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@juanjgon](https://forums.developer.nvidia.com/u/juanjgon)\
**Post date:** [July 31, 2014, 4:46pm UTC](https://forums.developer.nvidia.com/t/simplest-optix-code-unable-to-set-cuda-device/34183/8 "2014-07-31T16:46:07Z")

</div>

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  
NVIDIA DRIVER: 331.38

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

-Juanjo

---

<div class="post-metadata">

**Author:** ![juanjgon](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@juanjgon](https://forums.developer.nvidia.com/u/juanjgon)\
**Post date:** [August 1, 2014, 9:56am UTC](https://forums.developer.nvidia.com/t/simplest-optix-code-unable-to-set-cuda-device/34183/9 "2014-08-01T09:56:50Z")

</div>

I fixed my problem after install the 331.89 drivers

---

<div class="post-metadata">

**Author:** ![TomNVIDIA](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/tomnvidia/32/14181_2.png) [@TomNVIDIA](https://forums.developer.nvidia.com/u/TomNVIDIA)\
**Post date:** [June 14, 2022, 9:11pm UTC](https://forums.developer.nvidia.com/t/simplest-optix-code-unable-to-set-cuda-device/34183/10 "2022-06-14T21:11:53Z")

</div>

Closed on June 14, 2022, 9:11pm UTC


