Access violations when using CUDA3.0 with VC++2008

Hi everyone,

I’m using VC++2008 and CUDA3.0. I can compile and run the SDK stuff just fine, but now I have created a small application that computes some stuff which has both a CPU and a GPU computation option. It compiles without errors or warnings. Whenever I run it though, I get the following access violations (regardless of whether I’m running it as Administrator or as a normal user). These happen before the program even does anything (I set a breakpoint in the first line of main(), but the violation happens while loading libraries, it seems).

I really don’t know why this happens. When I take out the GPU stuff (i.e. when I remove the GPU code and don’t link cudart into the project) everything is fine and works as expected. I have compared my build configuration with the ones that the SDK projects have and the only thing that’s different is that I’m using CLR (Common Language Runtime) since I’m using Windows Forms (and hence .NET), but that shouldn’t hurt, right?

Any help/ideas are appreciated a lot.

Debug (error message):

Debug assertion failed

Program: [name of .exe file]

File: F:\dd\vctools\crt_bld\self_x86\crt\src\dbgheap.c

Line: 1511

Expression: _CrtIsValidHeapPointer(pUserData)[code]

Debugging output: (the first one is using /MD (Multi-threaded DLL Runtime Library), the second one /MDd (Multi-threaded DLL debug Runtime Library))

[code]'cuda_genetic.exe': Loaded 'D:\Dokumente und Einstellungen\Unpriv\Eigene Dateien\Visual Studio 2008\Projects\cuda_genetic\Release\cuda_genetic.exe', Symbols loaded.

'cuda_genetic.exe': Loaded 'D:\WINDOWS\system32\ntdll.dll'

'cuda_genetic.exe': Loaded 'D:\WINDOWS\system32\mscoree.dll'

'cuda_genetic.exe': Loaded 'D:\WINDOWS\system32\kernel32.dll'

'cuda_genetic.exe': Loaded 'D:\WINDOWS\system32\advapi32.dll'

'cuda_genetic.exe': Loaded 'D:\WINDOWS\system32\rpcrt4.dll'

'cuda_genetic.exe': Loaded 'D:\WINDOWS\system32\secur32.dll'

'cuda_genetic.exe': Loaded 'D:\CUDA\bin\cudart32_30_14.dll', Binary was not built with debug information.

'cuda_genetic.exe': Loaded 'D:\WINDOWS\WinSxS\x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.30729.4148_

x-ww_d495ac4e\msvcr90.dll'

'cuda_genetic.exe': Loaded 'D:\WINDOWS\WinSxS\x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.30729.4148_

x-ww_d495ac4e\msvcm90.dll'

'cuda_genetic.exe': Loaded 'D:\WINDOWS\system32\ole32.dll'

'cuda_genetic.exe': Loaded 'D:\WINDOWS\system32\gdi32.dll'

'cuda_genetic.exe': Loaded 'D:\WINDOWS\system32\user32.dll'

'cuda_genetic.exe': Loaded 'D:\WINDOWS\system32\msvcrt.dll'

'cuda_genetic.exe': Loaded 'D:\WINDOWS\system32\shlwapi.dll'

'cuda_genetic.exe': Loaded 'D:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll'

'cuda_genetic.exe': Loaded 'D:\WINDOWS\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.4053_

x-ww_e6967989\msvcr80.dll'

'cuda_genetic.exe': Loaded 'D:\WINDOWS\system32\shell32.dll'

'cuda_genetic.exe': Loaded 'D:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83\comctl32.dll'

'cuda_genetic.exe': Loaded 'D:\WINDOWS\system32\comctl32.dll'

'cuda_genetic.exe': Loaded 'D:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Culture.dll'

'cuda_genetic.exe': Unloaded 'D:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Culture.dll'

'cuda_genetic.exe': Loaded 'D:\WINDOWS\assembly\NativeImages_v2.0.50727_32\mscorlib124a40b9998f7b63c86bd1a2125ce26\mscorlib.ni.dll'

'cuda_genetic.exe' (Managed): Loaded 'D:\WINDOWS\assembly\GAC_32\mscorlib.0.0.0__b77a5c561934e089\mscorlib.dll'

'cuda_genetic.exe' (Managed): Loaded 'd:\Dokumente und Einstellungen\Unpriv\Eigene Dateien\Visual Studio 2008\Projects\cuda_genetic\Release\cuda_genetic.exe', Symbols loaded.

'cuda_genetic.exe': Loaded 'D:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorjit.dll'

'cuda_genetic.exe': Loaded 'D:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\diasymreader.dll'

'cuda_genetic.exe': Loaded 'D:\WINDOWS\system32\rsaenh.dll'

'cuda_genetic.exe' (Managed): Loaded 'D:\WINDOWS\WinSxS\x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.30729.4148_

x-ww_d495ac4e\msvcm90.dll'

First-chance exception at 0x7c97e478 in cuda_genetic.exe: 0xC0000005: Access violation reading location 0xc514f894.

First-chance exception at 0x7858ce29 in cuda_genetic.exe: 0xC0000005: Access violation writing location 0xc514f895.

'cuda_genetic.exe' (Managed): Loaded 'D:\WINDOWS\assembly\GAC_MSIL\mscorlib.resources.0.0.0_de_b77a5c561934e089\mscorlib.resources.dll'

A first chance exception of type 'System.AccessViolationException' occurred in cuda_genetic.exe

A first chance exception of type '<CrtImplementationDetails>.ModuleLoadException' occurred in msvcm90.dll

First-chance exception at 0x7c812afb in cuda_genetic.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000..

An unhandled exception of type 'System.TypeInitializationException' occurred in Unknown Module.
'cuda_genetic.exe': Loaded 'D:\Dokumente und Einstellungen\Unpriv\Eigene Dateien\Visual Studio 2008\Projects\cuda_genetic\Release\cuda_genetic.exe', Symbols loaded.

'cuda_genetic.exe': Loaded 'D:\WINDOWS\system32\ntdll.dll'

'cuda_genetic.exe': Loaded 'D:\WINDOWS\system32\mscoree.dll'

'cuda_genetic.exe': Loaded 'D:\WINDOWS\system32\kernel32.dll'

'cuda_genetic.exe': Loaded 'D:\WINDOWS\system32\advapi32.dll'

'cuda_genetic.exe': Loaded 'D:\WINDOWS\system32\rpcrt4.dll'

'cuda_genetic.exe': Loaded 'D:\WINDOWS\system32\secur32.dll'

'cuda_genetic.exe': Loaded 'D:\CUDA\bin\cudart32_30_14.dll', Binary was not built with debug information.

'cuda_genetic.exe': Loaded 'D:\WINDOWS\WinSxS\x86_Microsoft.VC90.DebugCRT_1fc8b3b9a1e18e3b_9.0.30729.

1_x-ww_f863c71f\msvcr90d.dll'

'cuda_genetic.exe': Loaded 'D:\WINDOWS\WinSxS\x86_Microsoft.VC90.DebugCRT_1fc8b3b9a1e18e3b_9.0.30729.

1_x-ww_f863c71f\msvcm90d.dll'

'cuda_genetic.exe': Loaded 'D:\WINDOWS\system32\ole32.dll'

'cuda_genetic.exe': Loaded 'D:\WINDOWS\system32\gdi32.dll'

'cuda_genetic.exe': Loaded 'D:\WINDOWS\system32\user32.dll'

'cuda_genetic.exe': Loaded 'D:\WINDOWS\system32\msvcrt.dll'

'cuda_genetic.exe': Loaded 'D:\WINDOWS\system32\shlwapi.dll'

'cuda_genetic.exe': Loaded 'D:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll'

'cuda_genetic.exe': Loaded 'D:\WINDOWS\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.4053_

x-ww_e6967989\msvcr80.dll'

'cuda_genetic.exe': Loaded 'D:\WINDOWS\system32\shell32.dll'

'cuda_genetic.exe': Loaded 'D:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83\comctl32.dll'

'cuda_genetic.exe': Loaded 'D:\WINDOWS\system32\comctl32.dll'

'cuda_genetic.exe': Loaded 'D:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Culture.dll'

'cuda_genetic.exe': Unloaded 'D:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Culture.dll'

'cuda_genetic.exe': Loaded 'D:\WINDOWS\assembly\NativeImages_v2.0.50727_32\mscorlib124a40b9998f7b63c86bd1a2125ce26\mscorlib.ni.dll'

'cuda_genetic.exe' (Managed): Loaded 'D:\WINDOWS\assembly\GAC_32\mscorlib.0.0.0__b77a5c561934e089\mscorlib.dll'

'cuda_genetic.exe' (Managed): Loaded 'd:\Dokumente und Einstellungen\Unpriv\Eigene Dateien\Visual Studio 2008\Projects\cuda_genetic\Release\cuda_genetic.exe', Symbols loaded.

'cuda_genetic.exe': Loaded 'D:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorjit.dll'

'cuda_genetic.exe': Loaded 'D:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\diasymreader.dll'

'cuda_genetic.exe': Loaded 'D:\WINDOWS\system32\rsaenh.dll'

'cuda_genetic.exe' (Managed): Loaded 'D:\WINDOWS\WinSxS\x86_Microsoft.VC90.DebugCRT_1fc8b3b9a1e18e3b_9.0.30729.

1_x-ww_f863c71f\msvcm90d.dll'

'cuda_genetic.exe': Loaded 'D:\WINDOWS\assembly\NativeImages_v2.0.50727_32\Systemde5bd01124463d7862bd173af90bc83\System.ni.dll'

'cuda_genetic.exe' (Managed): Loaded 'D:\WINDOWS\assembly\GAC_MSIL\System.0.0.0__b77a5c561934e089\System.dll'

First-chance exception at 0x7c97e478 in cuda_genetic.exe: 0xC0000005: Access violation reading location 0x69abed92.

'cuda_genetic.exe': Loaded 'D:\WINDOWS\system32\uxtheme.dll'

'cuda_genetic.exe': Loaded 'D:\WINDOWS\system32\MSCTF.dll'

cuda_genetic.exe has triggered a breakpoint

Usually an access violation is triggered when you are trying to read memory where you are not supposed to do so. So in order to find the problem, I suggest that you comment all the CUDA code out, but keep the include files, and then try adding the CUDA code line by line. See if you can find the line that it is causing the problem.

DarkTerror

Beyond the acces violation, to solve probleme with Heap Line 1511 the solution for me was to change Application setting from WindowsForms Application to Console under Liner->System->SubSystem