Application crash when using CUDA

I’ve recently installed CUDA 2.1 and wanted to add CUDA background extraction implementation to my computer vision application (that uses also IPP and OpenCV with it’s gui). But when I add even one line of CUDA-related code (even something simple like “cudaSetDevice(0)”), application crashes on exit in __crtExitProcess with the following message: “Unhandled exception at 0x064ab809 in Prototype.exe: 0xC0000005: Access violation reading location 0x06996804”. With any calls to CUDA removed application works just fine. That’s not only sad but it also prevents me from using CUDA visual debugger.

Have you ever face something like that? Any suggestions?

Btw, SDK samples work just fine.

Thanks in advance.

Today I’ve decided to investigate what’s happening.
First of all, I’ve removed all the code except of cudaSetDevice(0) from my program. It had crashed still.
Next, I’ve changed all the project settings to the same as in SDK cppIntegration project assuming there is something wrong with code generation or linking in my project. It hadn’t helped at all.

Looking closer to the crash call stack I’ve found that actual crash happens in module nvd3dum.dll. That’s call stack print:

[Frames below may be incorrect and/or missing, no symbols loaded for nvd3dum.dll]	

msvcr90d.dll!doexit(int code=0, int quick=0, int retcaller=0) Line 644 + 0x9 bytes C
msvcr90d.dll!exit(int code=0) Line 412 + 0xd bytes C

The strangest thing about all this stuff is that my project crashes on exit even when it is almost similar to the cppIntegration sample. I can’t understand where is the difference between the projects.

Please, I need some good advice. Solving this problem is quite important for me right now.

Btw, I’m using VS2008 SP1 to compile my project.

Have you tried copying the template project and using that as a base for your CUDA code? I found it rather hard to get CUDA running when compiling from VS, after adding CUDA code to an existing project.

My actual CUDA project is lib, not an application. So I can’t use an existing template =(