Hi Cuda Fans,
I am new to Cuda, and am trying to get Cuda functionality inside an MFC application in VS2005. I first tried just adding a .cu file to an existing MFC dialog app, then set the build properties using the build rules in one of the examples. The .cu file seems to compile ok, but I get about 25 link errors related to multiply defined symbols (error LNK2005: _malloc already defined in LIBCMT.lib(malloc.obj) libcmtd.lib). I do have the $(CUDA_LIB_PATH) value set in the linker options along with the cudart.lib dependency.
Anyone have a clue what this means? Is there some fundamental incompatibility between MFC and Cuda? The same code compiles, links and runs fine in a console application.
To get around this, I tried using Kaiyong Zhao’s VS Wizard 2.0 (Thanks for making that available!) to add a dll project to an existing MFC project. I then call the dll from the MFC code, this seems to work pretty well. I have two questions about this though:
- Using the sample.cu that is generated by the wizard, I get a compile error in the next to last line:
since argc and argv aren’t defined in the code. If I comment out that line the code compiles, links, and runs fine.
- If I run my MFC app in debug or emudebug mode and execute the .cu sample code twice, it will throw an error on the second execution. It doesn’t do this in release or emurelease mode. The error seems thread related
Unhandled exception at 0x7835b701 (mfc80ud.dll) in CudaProj.exe: 0xC0000005: Access violation reading location 0xf78d86d8.
The error is in the file afxtls.cpp at the last line copied here:
/ special version of CThreadSlotData::GetData that only works with
// thread local storage (and not process local storage)
// this version is inlined and simplified for speed
inline void* CThreadSlotData::GetThreadValue(int nSlot)
ASSERT(nSlot != 0 && nSlot < m_nMax);
ASSERT(m_pSlotData != NULL);
ASSERT(m_pSlotData[nSlot].dwFlags & SLOT_USED); //error on this line
Is this because a thread isn’t exiting properly because I commented out the CUT_EXIT function? If so, how do I get that function to properly compile? I have looked in the 2.1 programming guide and 2.1 reference manual but I don’t see this function or some of the others in the sample. Where are these documented?
Any help appreciated!