# Debugging cuda code using visual studio

**URL:** <https://forums.developer.nvidia.com/t/debugging-cuda-code-using-visual-studio/596>\
**Category:** CUDA Programming and Performance\
**Created:** [April 19, 2007, 9:39am UTC](https://forums.developer.nvidia.com/t/debugging-cuda-code-using-visual-studio/596 "2007-04-19T09:39:20Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eri\_Rubin](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Eri\_Rubin](https://forums.developer.nvidia.com/u/Eri_Rubin)\
**Post date:** [April 19, 2007, 9:39am UTC](https://forums.developer.nvidia.com/t/debugging-cuda-code-using-visual-studio/596/1 "2007-04-19T09:39:20Z")

</div>

Hi, I just started developing some code for cuda. I’m running on an xp box using vs2005. For some reason i can’t get the debugger to step into the cuda code even when I’m running under EmuDebug. Can some one help me ?

Thanks

Eri

---

<div class="post-metadata">

**Author:** ![Mark\_Harris](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/mark_harris/32/23175_2.png) [@Mark\_Harris](https://forums.developer.nvidia.com/u/Mark_Harris)\
**Post date:** [April 19, 2007, 11:01am UTC](https://forums.developer.nvidia.com/t/debugging-cuda-code-using-visual-studio/596/2 "2007-04-19T11:01:10Z")

</div>

Put a breakpoint inside one of your **global** functions rather than trying to step into GPU code from the host code. I have found that I cannot step into a foo\<\<\<\>\>\>() function directly, but I can put a break inside it to debug it.

Mark

---

<div class="post-metadata">

**Author:** ![Eri\_Rubin](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Eri\_Rubin](https://forums.developer.nvidia.com/u/Eri_Rubin)\
**Post date:** [April 23, 2007, 7:22am UTC](https://forums.developer.nvidia.com/t/debugging-cuda-code-using-visual-studio/596/3 "2007-04-23T07:22:23Z")

</div>

> [@](#):
>
> Put a breakpoint inside one of your **global** functions rather than trying to step into GPU code from the host code.&nbsp; I have found that I cannot step into a foo\<\<\<\>\>\>() function directly, but I can put a break inside it to debug it.
> 
> Mark
> 
> [snapback]186930[/snapback]

thanks did the trick

---

<div class="post-metadata">

**Author:** ![thegallier](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@thegallier](https://forums.developer.nvidia.com/u/thegallier)\
**Post date:** [April 23, 2007, 11:29am UTC](https://forums.developer.nvidia.com/t/debugging-cuda-code-using-visual-studio/596/4 "2007-04-23T11:29:22Z")

</div>

Any suggestion for inspecting shared variables in visual studio 2005? They seem to give me a problem.

Thanks

> [@](#):
>
> thanks did the trick
> 
> [snapback]188454[/snapback]

---

<div class="post-metadata">

**Author:** ![Eri\_Rubin](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Eri\_Rubin](https://forums.developer.nvidia.com/u/Eri_Rubin)\
**Post date:** [April 23, 2007, 11:46am UTC](https://forums.developer.nvidia.com/t/debugging-cuda-code-using-visual-studio/596/5 "2007-04-23T11:46:11Z")

</div>

> [@](#):
>
> Any suggestion for inspecting shared variables in visual studio 2005?&nbsp; They seem to give me a problem.
> 
> Thanks
> 
> [snapback]188502[/snapback]

I had the same problem. It was solved after copeing the custom compile options from the sdk.

hope this helps

Eri

---

<div class="post-metadata">

**Author:** ![thegallier](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@thegallier](https://forums.developer.nvidia.com/u/thegallier)\
**Post date:** [April 24, 2007, 3:11pm UTC](https://forums.developer.nvidia.com/t/debugging-cuda-code-using-visual-studio/596/6 "2007-04-24T15:11:08Z")

</div>

I will check that out.

thanks

> [@](#):
>
> I had the same problem. It was solved after copeing the custom compile options from the sdk.
> 
> hope this helps
> 
> Eri
> 
> [snapback]188503[/snapback]

---

<div class="post-metadata">

**Author:** ![ccuser](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@ccuser](https://forums.developer.nvidia.com/u/ccuser)\
**Post date:** [February 28, 2008, 2:46am UTC](https://forums.developer.nvidia.com/t/debugging-cuda-code-using-visual-studio/596/7 "2008-02-28T02:46:12Z")

</div>

I have a similar problem but placing a breakpoint within the kernel doesn’t work. It will step into the kernel?

Here’s the setup:

A .cpp file launches a routine in a .cu file that then invokes a kernel call. The kernel is in this same .cu file. The .cpp files are compiled using msvc compiler and the .cu with nvcc.

It was built as a DLL using CUDA rules and setting the properties of the .cu file as follows:

```auto
nvcc.exe -ccbin "C:\Program Files\Microsoft Visual Studio 8\VC\bin" -deviceemu -c  -Xcompiler "/EHsc /W3 /nologo /Wp64 /O2 /Zi   /MDd /GR"  -o Debug\rtw_gpu_cu.obj rtw_gpu_cu.cu

```

Any ideas?

Thanks for your help!

---

<div class="post-metadata">

**Author:** ![sudoca](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@sudoca](https://forums.developer.nvidia.com/u/sudoca)\
**Post date:** [March 5, 2009, 3:24pm UTC](https://forums.developer.nvidia.com/t/debugging-cuda-code-using-visual-studio/596/8 "2009-03-05T15:24:48Z")

</div>

Hi all,

I am facing a problem with a new cuda dll project : when I am debugging my test project, the values displayed by the debugger are completely wrong for most of them, although the program works correctly (that values are ok when returned by the dll functions to the main program). I included two cuda dlls in the project, the first can be debugged but not the new one. Here is the command line :

```auto
"nvcc.exe" -ccbin "C:\Program Files\Microsoft Visual Studio 8\VC\bin" -c -D"WIN32" -D"_DEBUG" -D"_CONSOLE" -D_MBCS -Xcompiler "/EHsc /W3 /nologo /Wp64 /O2 /Zi /MTd " -I"C:\CUDA_2_0\include" -I"./" -I"C:\Program Files\NVIDIA Corporation\NVIDIA CUDA SDK\common\inc" -I"C:\Program Files\GnuWin32\include" -o "Debug\blabla.obj" blabla.cu

```

I used the cuda.rules file. I have been looking for the error since severall days so if anyone has an idea…

---

<div class="post-metadata">

**Author:** ![sudoca](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@sudoca](https://forums.developer.nvidia.com/u/sudoca)\
**Post date:** [March 5, 2009, 3:48pm UTC](https://forums.developer.nvidia.com/t/debugging-cuda-code-using-visual-studio/596/9 "2009-03-05T15:48:20Z")

</div>

I reply to my one question since I (finally) found the bug :

The compilation options must be the same for the visual compiler and the cuda compiler : in my case, I had /O2 option for cuda and /Od for visual.

---

<div class="post-metadata">

**Author:** ![derwolk](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@derwolk](https://forums.developer.nvidia.com/u/derwolk)\
**Post date:** [June 25, 2009, 12:21am UTC](https://forums.developer.nvidia.com/t/debugging-cuda-code-using-visual-studio/596/10 "2009-06-25T00:21:09Z")

</div>

> [@](#):
>
> I reply to my one question since I (finally) found the bug :
> 
> The compilation options must be the same for the visual compiler and the cuda compiler : in my case, I had /O2 option for cuda and /Od for visual.

Thank you for that tip, sudoca!

---

<div class="post-metadata">

**Author:** ![veltrop](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@veltrop](https://forums.developer.nvidia.com/u/veltrop)\
**Post date:** [June 25, 2009, 6:13am UTC](https://forums.developer.nvidia.com/t/debugging-cuda-code-using-visual-studio/596/11 "2009-06-25T06:13:59Z")

</div>

> [@](#):
>
> I reply to my one question since I (finally) found the bug :
> 
> The compilation options must be the same for the visual compiler and the cuda compiler : in my case, I had /O2 option for cuda and /Od for visual.

Thanks here, too!

---

<div class="post-metadata">

**Author:** ![tilo](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@tilo](https://forums.developer.nvidia.com/u/tilo)\
**Post date:** [August 24, 2010, 8:36am UTC](https://forums.developer.nvidia.com/t/debugging-cuda-code-using-visual-studio/596/12 "2010-08-24T08:36:07Z")

</div>

> [@](#):
>
> I reply to my one question since I (finally) found the bug :
> 
> The compilation options must be the same for the visual compiler and the cuda compiler : in my case, I had /O2 option for cuda and /Od for visual.

Thanks!

In my case I did not have any cpp files in my project but had the /O2 optimization option enabled. I disabled optimizations (/Od flag) and I worked fine.

---

<div class="post-metadata">

**Author:** ![tilo](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@tilo](https://forums.developer.nvidia.com/u/tilo)\
**Post date:** [August 24, 2010, 8:36am UTC](https://forums.developer.nvidia.com/t/debugging-cuda-code-using-visual-studio/596/13 "2010-08-24T08:36:07Z")

</div>

> [@](#):
>
> I reply to my one question since I (finally) found the bug :
> 
> The compilation options must be the same for the visual compiler and the cuda compiler : in my case, I had /O2 option for cuda and /Od for visual.

Thanks!

In my case I did not have any cpp files in my project but had the /O2 optimization option enabled. I disabled optimizations (/Od flag) and I worked fine.

---

<div class="post-metadata">

**Author:** ![salmanulhaq](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/salmanulhaq/32/73061_2.png) [@salmanulhaq](https://forums.developer.nvidia.com/u/salmanulhaq)\
**Post date:** [August 29, 2010, 4:58pm UTC](https://forums.developer.nvidia.com/t/debugging-cuda-code-using-visual-studio/596/14 "2010-08-29T16:58:10Z")

</div>

> [@](#):
>
> Thanks!
> 
> In my case I did not have any cpp files in my project but had the /O2 optimization option enabled. I disabled optimizations (/Od flag) and I worked fine.

You can try NSight but it does not allow debugging on a single GPU config (which I suppose is really absurd) and you need to have atleast 2 GPUs to debug your kernels on the device unlike the emuDebug, monitor global and shared memory etc.

Take a look: http://www.nvidia.com/nsight

---

<div class="post-metadata">

**Author:** ![salmanulhaq](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/salmanulhaq/32/73061_2.png) [@salmanulhaq](https://forums.developer.nvidia.com/u/salmanulhaq)\
**Post date:** [August 29, 2010, 4:58pm UTC](https://forums.developer.nvidia.com/t/debugging-cuda-code-using-visual-studio/596/15 "2010-08-29T16:58:10Z")

</div>

> [@](#):
>
> Thanks!
> 
> In my case I did not have any cpp files in my project but had the /O2 optimization option enabled. I disabled optimizations (/Od flag) and I worked fine.

You can try NSight but it does not allow debugging on a single GPU config (which I suppose is really absurd) and you need to have atleast 2 GPUs to debug your kernels on the device unlike the emuDebug, monitor global and shared memory etc.

Take a look: http://www.nvidia.com/nsight

---

<div class="post-metadata">

**Author:** ![Apue](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Apue](https://forums.developer.nvidia.com/u/Apue)\
**Post date:** [September 11, 2010, 8:59am UTC](https://forums.developer.nvidia.com/t/debugging-cuda-code-using-visual-studio/596/16 "2010-09-11T08:59:15Z")

</div>

> [@](#):
>
> You can try NSight but it does not allow debugging on a single GPU config (which I suppose is really absurd) and you need to have atleast 2 GPUs to debug your kernels on the device unlike the emuDebug, monitor global and shared memory etc.
> 
> Take a look: http://www.nvidia.com/nsight

Another trouble is that Nsight only works in Visata/win 7. I’m still with winXP, can’t use the software.

---

<div class="post-metadata">

**Author:** ![Apue](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Apue](https://forums.developer.nvidia.com/u/Apue)\
**Post date:** [September 11, 2010, 8:59am UTC](https://forums.developer.nvidia.com/t/debugging-cuda-code-using-visual-studio/596/17 "2010-09-11T08:59:15Z")

</div>

> [@](#):
>
> You can try NSight but it does not allow debugging on a single GPU config (which I suppose is really absurd) and you need to have atleast 2 GPUs to debug your kernels on the device unlike the emuDebug, monitor global and shared memory etc.
> 
> Take a look: http://www.nvidia.com/nsight

Another trouble is that Nsight only works in Visata/win 7. I’m still with winXP, can’t use the software.

---

<div class="post-metadata">

**Author:** ![Apue](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Apue](https://forums.developer.nvidia.com/u/Apue)\
**Post date:** [September 11, 2010, 8:59am UTC](https://forums.developer.nvidia.com/t/debugging-cuda-code-using-visual-studio/596/18 "2010-09-11T08:59:33Z")

</div>

Duplicated…

---

<div class="post-metadata">

**Author:** ![Apue](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Apue](https://forums.developer.nvidia.com/u/Apue)\
**Post date:** [September 11, 2010, 8:59am UTC](https://forums.developer.nvidia.com/t/debugging-cuda-code-using-visual-studio/596/19 "2010-09-11T08:59:33Z")

</div>

Duplicated…

---

<div class="post-metadata">

**Author:** ![Shodan2](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Shodan2](https://forums.developer.nvidia.com/u/Shodan2)\
**Post date:** [October 14, 2010, 4:39pm UTC](https://forums.developer.nvidia.com/t/debugging-cuda-code-using-visual-studio/596/20 "2010-10-14T16:39:31Z")

</div>

I’ve read this thread and applied all the suggested solutions but the execution still refuses to pause inside a **global** function, though pausing within a **host** function within the same .cu file…

VS makes any breadpoint inside my **global** function inactive once I press F5 and says:

“The breakpoint will not currently be hit. No executable code is assosiated with this line  
Possible causes include: preprocessor directives and compiler/linker optimizations.”

I’ve disabled all optimizations, both in VC++ and NVCC compilers, the linker doesn’t seem to be relevant to this…  
Of course, I have the -deviceemu activated in EmuDebug, and ‘Generate debug information’ set ‘-D\_DEBUG -D\_WIN32’

The only NVCC compilation type that builds is 'Generate object hybrid file (–compile / -c), other settings here either return a CUDA build rule error or even cause the linker to crash… Maybe this is relevant to the inactive kernel breakpoints?

[Next page](https://forums.developer.nvidia.com/t/debugging-cuda-code-using-visual-studio/596.md?page=2)
