Vs2005:doesn't compile in EmuMode with /MD or /MDd Do i get memleaks etc.. with /MD[d] ???

Hi,

I am developing a C++ DLL in Visual Studio 2005 (SP1) which uses some Cuda functions, and am using the Cuda 2.0 (Beta) version.

For some reasons, I have the link against the ‘Multithreaded (Debug) DLL’ Runtime, so in my DLL project setting I have set ‘Multithreaded (Debug) DLL’ (/MD resp. /MDd).

In the custom build step for my .cu file, I have also set to link against ‘Multithreaded (Debug) DLL’. My command line for my CudaInternal.cu file is (e.g. for configuration ‘EmuDebug’)
“$(CUDA_BIN_PATH)\nvcc.exe” -ccbin “$(VCInstallDir)bin” -deviceemu -c -D_DEBUG -DWIN32 -D_CONSOLE -D_MBCS -Xcompiler /EHsc,/W3,/nologo,/Wp64,/Od,/Zi,/RTC1,/MDd -I"$(CUDA_INC_PATH)" -o $(ConfigurationName)\CudaInternal.obj src/CudaInternal.cu
(Note the ‘/MDd’ flag instead of ‘/MTd’ which is typically used).

Now, when I am compiling the native cuda configurations ‘Debug/Release’, everything’s fine. But when I am compiling the emulation configurations ‘EmuDebug/EmuRelease’, I am getting the following compiler errors:

1>h:\thirdparty\cuda\toolkit2.0\include\math_functions.h(160) : error C2201: ‘__cuda_floor’ : must have external linkage in order to be exported/imported
1>h:\thirdparty\cuda\toolkit2.0\include\math_functions.h(202) : error C2201: ‘__cuda_ldexp’ : must have external linkage in order to be exported/imported
1>h:\thirdparty\cuda\toolkit2.0\include\math_functions.h(229) : error C2201: ‘__cuda_frexp’ : must have external linkage in order to be exported/imported
1>h:\thirdparty\cuda\toolkit2.0\include\math_functions.h(271) : error C2201: ‘__cuda_ceil’ : must have external linkage in order to be exported/imported
1>h:\thirdparty\cuda\toolkit2.0\include\math_functions.h(308) : error C2201: ‘__cuda_hypot’ : must have external linkage in order to be exported/imported
1>h:\thirdparty\cuda\toolkit2.0\include\math_functions.h(325) : error C2201: ‘__cuda_modf’ : must have external linkage in order to be exported/imported
1>h:\thirdparty\cuda\toolkit2.0\include\math_functions_dbl_ptx1.h(92) : error C2491: ‘__cuda_ceil’ : definition of dllimport function not allowed
1>h:\thirdparty\cuda\toolkit2.0\include\math_functions_dbl_ptx1.h(103) : error C2491: ‘__cuda_floor’ : definition of dllimport function not allowed
1>h:\thirdparty\cuda\toolkit2.0\include\math_functions_dbl_ptx1.h(229) : error C2491: ‘__cuda_hypot’ : definition of dllimport function not allowed
1>h:\thirdparty\cuda\toolkit2.0\include\math_functions_dbl_ptx1.h(261) : error C2491: ‘__cuda_ldexp’ : definition of dllimport function not allowed
1>h:\thirdparty\cuda\toolkit2.0\include\math_functions_dbl_ptx1.h(277) : error C2491: ‘__cuda_frexp’ : definition of dllimport function not allowed
1>h:\thirdparty\cuda\toolkit2.0\include\math_functions_dbl_ptx1.h(283) : error C2491: ‘__cuda_modf’ : definition of dllimport function not allowed

I solved this issue in a very ‘rough’ way by modifying the Cuda header files: I modified the ‘math_functions.h’ and removed the protottypes which made problems. I removed also the ‘implementation’ of the functions in the ‘math_functions_dbl_ptx1.h’.
As i don’t need the double versions of floor, ldexp, frexp, ceil, hypot, modf, this is no problem for me.
After modifying the two files, i could compile my DLL also for the ‘EmuDebug/EmuRelease’ configurations.

Now my questions:

  • My workaround solves the problem for me, but I don’t think this can be the best way to do this - my modifying Cuda header files (!!) ?
  • Is there a possible problem (memleaks etc…) in using my DLL, as I read in some threads (http://forums.nvidia.com/lofiversion/index.php?t66402.html, http://forums.nvidia.com/index.php?act=ST&f=71&t=67877) that this could lead to possible Memleaks etc.
  • I think the ‘cudart’ is compilied with the ‘/MT’ flag. Why is there no version of the ‘cudart’ which is compiled with ‘/MD’ ?
  • Previously, i was using the ‘Cuda1.1’ runtime library, where the DLL was compiling without doing these ‘rough’ modifications. Why did it work out of the box for 1.1 and not for 2.0 ?

best, Hannes

I’ve got exactly the same problem, is there a better solution to it, than editing the cuda include files?

I do not have the same exact problem you described, but I do have a case where my code compiles and runs fine in Debug/Release but generates errors when compiling in EmuDebug/EmuRelease. The errors I get aren’t related to one of my own header files, but rather a VC include:

1>C:\Program Files\Microsoft Visual Studio 8\VC\INCLUDE\iosfwd(652) : error C2039: ‘__SO__Si’ : is not a member of ‘std’

1>C:\Program Files\Microsoft Visual Studio 8\VC\INCLUDE\iosfwd(652) : error C2146: syntax error : missing ‘;’ before identifier ‘_ZSt8__SO__Si’

1>C:\Program Files\Microsoft Visual Studio 8\VC\INCLUDE\iosfwd(652) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

1>C:\Program Files\Microsoft Visual Studio 8\VC\INCLUDE\iosfwd(652) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

I looked up the first two compile errors on MSDN:

Compiler Error C2039: The code incorrectly calls or refers to a member of a structure, class, or union.

Compiler Error C2146: The compiler expected token and found identifier instead.

I do not see how this makes sense given my code compiles fine except for Emu. Also, this is code I am adapting for CUDA and the original source code compiles fine in Visual Studio itself as well. I suspect this is a problem with the CUDA compiler?

Has anyone else ran into a problem where they could not compile EmuDebug/EmuRelease as they could normal Debug/Release in CUDA?

Hi, I`ve got the same Problem as HannesF99. Does anyone know to solve this without editing Cuda header files.

Please post a reply. I`ve to finish an assignment and being able to use DebugMode would really help.

best regards

Pascal

As far as i know, there is currently no other solution to it. You can have the modified header files from me on request.
best regards,