Vs2005:doesn't compile in EmuMode with /MD or /MDd

(I forwarded my earliere posting from [url=“http://forums.nvidia.com/index.php?showtopic=75531”]http://forums.nvidia.com/index.php?showtopic=75531[/url] to here, because it seems to be more appropiate…)


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