Fatal error as soon as I link my .cu file with C++ project. Please, can anybody help me?

I’ve built my first Cuda application in Visual Studio Express 2008, using C++.
Although I’ve been a C/C++ developer for over 25 years, this is my first attempt at Cuda
development.

I can build a Win32 CLR app successfully, and add my .cu source file to the project, and when I do a
clean/rebuild, it builds successfully. But immediately upon running or debugging it, I get the
run-time crash error Debug Assertion Failed! Expression:_CrtlsValidHeapPointer(pUserData)
This is with no calls to the actual Cuda functions; in fact I’ve disabled all of the actual code in
the Cuda functions, so all they do right now is simply return, as I didn’t want to have too many possible
causes for the crash.

I’ve installed the cuda.rules, and set what I believe are the appropriate include
and lib paths. The Cuda command line created by the cuda.rules looks like this:

/Od /I “C:\CUDA\include” /I “./” /I “…/…/common/inc” /I “…/…/…/shared/inc” /D “WIN32” /D “_DEBUG” /D “_UNICODE” /D “UNICODE” /FD /EHa /MDd /Yu"stdafx.h" /Fp"Debug\CudaWin2.pch" /Fo"Debug\" /Fd"Debug\vc90.pdb" /W3 /nologo /c /Zi /clr /TP /errorReport:prompt /FU “c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll” /FU “c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll” /FU “c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll” /FU “c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll” /FU “c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.XML.dll”

My linker command line is as follows:
/OUT:“C:\Users\Rich\Documents\Visual Studio 2008\Projects\CF3\Debug\CudaWin2.exe” /INCREMENTAL /NOLOGO /LIBPATH:“C:\CUDA\lib/…/lib” /LIBPATH:"…/…/common/lib" /LIBPATH:"…/…/…/shared/lib" /MANIFEST /MANIFESTFILE:“Debug\CudaWin2.exe.intermediate.manifest” /MANIFESTUAC:“level=‘asInvoker’ uiAccess=‘false’” /DEBUG /ASSEMBLYDEBUG /PDB:“c:\Users\Rich\Documents\Visual Studio 2008\Projects\CF3\Debug\CudaWin2.pdb” /SUBSYSTEM:WINDOWS /ENTRY:“main” /DYNAMICBASE /FIXED:No /NXCOMPAT /MACHINE:X86 /ERRORREPORT:PROMPT cudart.lib

And my CudaRules command line is:

“C:\CUDA\bin\nvcc.exe”
-gencode=arch=compute_10,code=“sm_10,compute_10”
-gencode=arch=compute_20,code=“sm_20,compute_20”
-ccbin “C:\Program Files\Microsoft Visual Studio 9.0\VC\bin”
-I"C:\CUDA\include" -I"./" -I"…/…/common/inc"
-I"…/…/…/shared/inc"
-Xcompiler "/EHsc /W3 /nologo /Od /Zi /MDd /GR "
-maxrregcount=32
-gencode=arch=compute_10,code=“sm_10,compute_10”
-gencode=arch=compute_20,code=“sm_20,compute_20”
–compile -o “Debug\CudaWin2.cu.obj” “c:\Users\Rich\Documents\Visual Studio 2008\Projects\CF3\CudaWin2\CudaWin2.vcproj”

All project source has the Runtime Library set as /MDd, so I don’t believe there’s
an inconsistency there, as seems to be indicated when I Google the error I get.

The kernel code is at the top of my .cu file, with c++ methods at the bottom which call
the kernel functions. As far as I know this is legal, but if you can’t call a kernel
function from within a cpp function, could someone please let me know?

The run-time error described above comes up immediately as soon as I try to run the
application using either “Debug / Start Debugging” or “Debug / Start without Debugging”
from within Visual Studio C++ 2008.

The Output window reports the following when I try to run it and click Ignore, etc, when the error
occurs:[b]
‘CudaWin2.exe’: Loaded ‘C:\Users\Rich\Documents\Visual Studio 2008\Projects\CF3\Debug\CudaWin2.exe’, Symbols loaded.
‘CudaWin2.exe’: Loaded ‘C:\Windows\System32\ntdll.dll’
‘CudaWin2.exe’: Loaded ‘C:\Windows\System32\mscoree.dll’
‘CudaWin2.exe’: Loaded ‘C:\Windows\System32\kernel32.dll’
‘CudaWin2.exe’: Loaded ‘C:\CUDA\bin\cudart32_31_9.dll’, Binary was not built with debug information.
‘CudaWin2.exe’: Loaded ‘C:\Windows\winsxs\x86_microsoft.vc90.debugcrt_1fc8b3b9a1e18e3b_9.0.30729.1_none_bb1f6aa1308c35eb\msvcr90d.dll’
‘CudaWin2.exe’: Loaded ‘C:\Windows\winsxs\x86_microsoft.vc90.debugcrt_1fc8b3b9a1e18e3b_9.0.30729.1_none_bb1f6aa1308c35eb\msvcm90d.dll’
‘CudaWin2.exe’: Loaded ‘C:\Windows\System32\ole32.dll’
‘CudaWin2.exe’: Loaded ‘C:\Windows\System32\msvcrt.dll’
‘CudaWin2.exe’: Loaded ‘C:\Windows\System32\gdi32.dll’
‘CudaWin2.exe’: Loaded ‘C:\Windows\System32\user32.dll’
‘CudaWin2.exe’: Loaded ‘C:\Windows\System32\advapi32.dll’
‘CudaWin2.exe’: Loaded ‘C:\Windows\System32\rpcrt4.dll’
‘CudaWin2.exe’: Loaded ‘C:\Windows\System32\imm32.dll’
‘CudaWin2.exe’: Loaded ‘C:\Windows\System32\msctf.dll’
‘CudaWin2.exe’: Loaded ‘C:\Windows\System32\lpk.dll’
‘CudaWin2.exe’: Loaded ‘C:\Windows\System32\usp10.dll’
‘CudaWin2.exe’: Loaded ‘C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscoreei.dll’
‘CudaWin2.exe’: Loaded ‘C:\Windows\System32\shlwapi.dll’
‘CudaWin2.exe’: Loaded ‘C:\Windows\winsxs\x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.6002.18305_none_5cb72f2a088b0ed3\comctl32.dll’
‘CudaWin2.exe’: Loaded ‘C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll’
‘CudaWin2.exe’: Loaded ‘C:\Windows\winsxs\x86_microsoft.vc80.crt_1fc8b3b9a1e18e3b_8.0.50727.4053_none_d08d7da0442a985d\msvcr80.dll’
‘CudaWin2.exe’: Loaded ‘C:\Windows\System32\shell32.dll’
‘CudaWin2.exe’: Loaded ‘C:\Windows\Microsoft.NET\Framework\v2.0.50727\Culture.dll’
‘CudaWin2.exe’: Unloaded ‘C:\Windows\Microsoft.NET\Framework\v2.0.50727\Culture.dll’
‘CudaWin2.exe’: Loaded ‘C:\Windows\assembly\NativeImages_v2.0.50727_32\mscorlib\98bbdd8c400493ad228b8283665cc9da\mscorlib.ni.dll’
‘CudaWin2.exe’ (Managed): Loaded ‘C:\Windows\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll’
‘CudaWin2.exe’: Loaded ‘C:\Windows\System32\uxtheme.dll’
‘CudaWin2.exe’ (Managed): Loaded ‘c:\Users\Rich\Documents\Visual Studio 2008\Projects\CF3\Debug\CudaWin2.exe’, Symbols loaded.
‘CudaWin2.exe’: Loaded ‘C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorjit.dll’
‘CudaWin2.exe’: Loaded ‘C:\Windows\Microsoft.NET\Framework\v2.0.50727\diasymreader.dll’
‘CudaWin2.exe’: Loaded ‘C:\Windows\System32\rsaenh.dll’
‘CudaWin2.exe’ (Managed): Loaded ‘C:\Windows\WinSxS\x86_microsoft.vc90.debugcrt_1fc8b3b9a1e18e3b_9.0.30729.1_none_bb1f6aa1308c35eb\msvcm90d.dll’
‘CudaWin2.exe’: Loaded ‘C:\Windows\assembly\NativeImages_v2.0.50727_32\System\ed6ae2749d12c4729ee43ff339de4bb8\System.ni.dll’
‘CudaWin2.exe’ (Managed): Loaded ‘C:\Windows\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll’
First-chance exception at 0x770d128a in CudaWin2.exe: 0xC0000005: Access violation reading location 0xc1172128.
First-chance exception at 0x61e51079 in CudaWin2.exe: 0xC0000005: Access violation reading location 0xc117213d.
A first chance exception of type ‘System.AccessViolationException’ occurred in CudaWin2.exe

Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

A first chance exception of type ‘.ModuleLoadException’ occurred in msvcm90d.dll

Additional information: The C++ module failed to load during native initialization.

First-chance exception at 0x76d7fbae in CudaWin2.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000…
An unhandled exception of type ‘System.TypeInitializationException’ occurred in Unknown Module.

Additional information: The type initializer for ‘’ threw an exception.

The thread ‘Main Thread’ (0x10f0) has exited with code 0 (0x0).
The thread ‘Win32 Thread’ (0x2f8) has exited with code 0 (0x0).
The thread ‘Win32 Thread’ (0x17e8) has exited with code 0 (0x0).
The program ‘[4424] CudaWin2.exe: Managed’ has exited with code 0 (0x0).
The program ‘[4424] CudaWin2.exe: Native’ has exited with code 0 (0x0).

[/b]

Is there a specific runtime debug library that I need to link with instead of cudart.lib?
I ask this because in the Output window I always see
“C:\CUDA\bin\cudart32_31_9.dll not built with debugging information”.
Or is it a problem with system.dll, as the following line is where the First Chance exception occurs?

I’ve run out of ideas and am finding nothing that works when I Google the errors. I’ve seen some other
solutions which say that the project needs to be a Console app, but in my case I need interaction
with the user so it must be a Windows app, apparently using /clr.

Also, I find it odd that the program runs fine until I simply link the .cu file with the project, even
when no Cuda routines are called.

Any help would be greatly appreciated. I’ve been at this now for days with no progress.
~Rich