Monday, April 11, 2011

Debugging Software Crashes in C and C++ - II

Debugging Software Crashes in C and C++ - II

Sunday, April 3, 2011

Setup eclipse for CUDA development

After two weeks playing with Visual Studio, I found that it's very sux, the intellisense is not working all times...maybe I need to install Visual Assist...and for a linux die-hard you'll found eclipse should be more suitable for you.

BTW, here is how to setup eclipse for CUDA development on Windows, although there're several errors
1) Download & install Visual Studio 2005/2008 Express Edition
2) Download & install DirectX SDK
3) Download & install Microsoft Platform SDK
4) Download & install CUDA SDK & Toolkit :-)
5) Download & install eclipse CDT (for sure :p)
6) Download the project template at http://public.procoders.net/cuda_template/minimal_cuda.zip

Now ready to go, create a project using above template, then edit the MAKEFILE change following
Change VC_HOME point to the place that you installed the VC express edition
i.e. VC_HOME= C:\Program Files\Microsoft Visual Studio 9.0\VC
Add SDK_HOME and point to the place that you installed the Platform SDK
i.e. SDK_HOME= C:\Program Files\Microsoft Platform SDK
Change the CUDA_COMMON_HOME point to the location of the CUDA SDK
i.e. CUDA_COMMON_HOME= C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 3.2\C\common
Find in the MAKEFILE, the place that set nvcc_par and add -I "$(CUDA_INC_PATH)"
i.e. SET nvcc_par= -I "$(CUDA_INC_PATH)" -I "$(CUDA_COMMON_HOME)\inc" -ccbin "$(CL_EXE)"  \
-Xcompiler $(XCOMPILER_FLAGS) -c $*.cu
The CUDA_INC_PATH is set during the setup of CUDA toolkit
Find the line start with $(LINK_EXE)" and add /LIBPATH:"$(SDK_HOME)\lib"
i.e. "$(LINK_EXE)" /OUT:$(MAIN) /LIBPATH:"$(VC_HOME)\lib" /LIBPATH:"$(SDK_HOME)\lib" $(OBJECTS) \
"$(CUDA_LIB_PATH)\cudart.lib" "$(CUDA_COMMON_HOME)\lib\cutil32.lib"

You will also need to setup the PATH environment variable point to  $(VC_HOME)\BIN before starting eclipse.

Further change is inside the OBJECTS, and MAIN to adapt with your custom project i.e.
OBJECTS= helloWorld.obj
MAIN=helloWorld.exe
Ctrl+B and it will be built :-)
Have fun.

I think I don't need NSight as i'll use cuda-gdb for this feature, that's cool. You might also need to setup eclipse include file to search for CUDA SDK so that the intellisense will work.

BTW, there's a sux thing here, the sal.h get error during the compile inside Eclipse but doing a nmake from console work well. What's happen??!!!  X.X

Enable CUDA syntax highlight & intellisense for Visual Studio

Syntax highlighting like __global__...
Goto "C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 3.2\C\doc\syntax_highlighting"
Read the readme.txt there, basically there is simple step as following
Want pretty syntax highlighting when editing your .cu files in Visual Studio?
Here's how:

---
Visual Studio .Net 2005 / Visual Studio 8:

1. If you don't have a usertype.dat file in your "Microsoft Visual Studio 8\Common7\IDE" folder, then copy the included usertype.dat file there.  If you do, append the contents of the included usertype.dat onto the end of the "Microsoft Visual Studio 8\Common7\IDE\usertype.dat"

2. Start Visual Studio 8.  Select the menu "Tools->Options...".  Open "Text Editor" in the tree view on the left, and click on "File Extension".  Type cu in the "Extension" box, set the editor to "Microsoft Visual C++" and click "Add".  Click "OK" on the dialog box. 

3. Restart Visual Studio and your CUDA code should now have syntax highlighting.


For intellisense support
Go to C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v3.2\extras\visual_studio_integration, read the NvCudaRules.README.txt or run the .reg there, it will append the cu, cuh into registry entry as following
Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\8.0\Languages\Language Services\C/C++]
"NCB Default C/C++ Extensions"=".cpp;.cxx;.c;.cc;.h;.hh;.hxx;.hpp;.inl;.tlh;.tli;.cu;.cuh;.cl"

[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\Languages\Language Services\C/C++]
"NCB Default C/C++ Extensions"=".cpp;.cxx;.c;.cc;.h;.hh;.hxx;.hpp;.inl;.tlh;.tli;.cu;.cuh;.cl"
Last but not least, you'll need to include following header files in your CUDA project in order to get intellisense read those headers.
#include "cuda.h"
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
I really recognize that VS is sux and eclipse should be better. But Nsight only on VS :-(

Saturday, April 2, 2011

CUDA app wizard for Visual Studio 2008

http://sourceforge.net/projects/cudavswizard/files/

There's few errors, set following environment variable in order to get it works
NVSDKCUDA_ROOT=C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 3.2\C
PATH=$PATH;C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 3.2\C\common\lib