PDA

View Full Version : Visual Studio's Intellisense and .cu files (a simple solution)


Panajev2001a
28-Nov-2008, 09:33
Without even some manual knob-turning the C/C++ syntax in the .cu files is not even highlighted, but what about functions and variables names completion? What about Intellisense (VS)?

Let's start by having a project that already works as far as compiling the .cu files with NVCC (using the custom build rule for the .cu files [if needed I can post the one used in nVIDIA's sample projects]).

Well, the basic idea is to write your .cu code (for the main file and for the kernels) in nice .C files (C++ syntax) and set those "would be .cu files" to compile using a custom build rule (check that this rules comes before the CUDA/NVCC one in the build tools order for your project).

The custom build rule for these "dummy" .C files, thanks to VS's Macros (env. vars), is not tough to write...

Command Line:

rm $(InputName).cu
cp $(InputFileName) $(InputName).cu


Description (nice console output):

$(InputFileName) --> $(InputName).cu


Outputs:

$(InputName).cu


The idea is to basically have a .C file for each .cu file and set those .C files compilation step appropriately to just "transform" them into .cu files for you giving you back Intellisense (for your code and for CUDA SDK's functions and macros too) at a very minor cost.

If I have explained myself poorly, please do ask any question you might have and I'll try to answer it.

P.S.:

say you have your main .cu file named MatTest.cu (when you split in one main .cu file and several kernel files then the kernel files are usually excluded from the build process, included by the main .cu file itself, and referenced in the custom build process of the main .cu file)... and this file references a MatTest_kernel.cu

If you just created it, then you might have to set the Custom Build process for it (it cannot just use NVCC directly as Visual Studio attempts it to do automatically)... so you right click on the file and click on Properties...

You set it to use a Custom Build Tool (General), you click on Apply, and then you configure the custom build process...

Command Line:

"$(CUDA_BIN_PATH)\nvcc.exe" -ccbin "$(VCInstallDir)bin" -c -D_DEBUG -DWIN32 -D_CONSOLE -D_MBCS -Xcompiler /EHsc,/W3,/nologo,/Wp64,/Od,/Zi,/RTC1,/MTd -I"$(CUDA_INC_PATH)" -I./ -I../../common/inc -o $(ConfigurationName)\MatTest.obj MatTest.cu


Outputs:

$(ConfigurationName)\MatTest.obj


Additional Dependencies:

MatTest_kernel.cu

ban25
29-Nov-2008, 09:23
You might be able to write a VS plugin to handle the intellisense. We have a scripting language we'd like to support in VS with code completion, and we're considering a plugin approach. Not sure how feasible it is, but we'll find out soon.

Panajev2001a
29-Nov-2008, 14:02
You might be able to write a VS plugin to handle the intellisense. We have a scripting language we'd like to support in VS with code completion, and we're considering a plugin approach. Not sure how feasible it is, but we'll find out soon.

The better thing would be a plugin yes, or to have users write code in regular .C/.cpp files with a particular #define at the very beginning of the file identifying it as a CUDA project file and handle the conversion into .cu, if necessary, and the compiler errors/debugger interaction (a problem with my approach is related to errors in the compile phase --> click on the error --> the .cu file is opened instead of the .C file you are working from).

Richard
29-Nov-2008, 14:10
I have a question, are you posting about getting to compile .cu files with VS or asking about how to implement highlighting/autocomplete in the IDE? Or both? This (http://sarathc.wordpress.com/2008/09/26/how-to-integrate-cuda-with-visual-c/) (and a link to the other article) seems to cover both.

Panajev2001a
29-Nov-2008, 16:26
I have a question, are you posting about getting to compile .cu files with VS or asking about how to implement highlighting/autocomplete in the IDE? Or both? This (http://sarathc.wordpress.com/2008/09/26/how-to-integrate-cuda-with-visual-c/) (and a link to the other article) seems to cover both.

I am trying to use the auto-complete/code-tools features in VS (Intellisense).

This "trick" also enables syntax highlighting in a way, but does more than that... I do not see how the link you posted and the article it references does fix the lack of auto-complete/Intellisense issue.

lithiumx
17-Feb-2010, 00:44
I am confused on one thing...

How do i ensure that the Custom Build Rule occurs before the CUDA build rule?

I created the custom build rule. Everything is done as you instructed and when I try to build, it gives me a build error where there was not one before.

This is what I did specifically:

1. Right click the Project and click Properties
2. Click on Custom Build Step
--Under each category, copy and paste the information as instructed earlier, command line, description, and output.

lithiumx
17-Feb-2010, 00:46
Error 1 error PRJ0019: A tool returned an error code from "CUDAWinApp1.vcproj --> CUDAWinApp1.cu" CUDAWinApp1 CUDAWinApp1

Davros
21-Feb-2010, 13:07
is this any good to you
http://www.geeks3d.com/20080825/intelishade-beta-v30/