CUDA with C++

Hello,

I’m trying to call my CUDA kernels in C++ code.
I use the cppIntegration example but it 's not running.
My CUDA code is considered as C++ code.

Someone could explain me what the way to correct that?!

Thanks

edit: I use Visual Studio 2005

You should just name your file as “.cu” and compile it with custom-build rule using “nvcc” either into OBJ (-c option) or into EXE file – as you wish.

–edit–
I am not sure about the cppIntegration example… have not seen it yet. so, if my answr above could be un-related… sorry bout that.

How do you use the custom-build rule

Excuse me if my question appears stupid but I’m a newbie with VC++

Right click the “.cu” file in your project and click “properties”

In the ensuing dialog box you will find a place where you can set your “custom build” command.

You should also specify what your final executable would be (in case of linking with other objects) – so that VC++ environment will know what is your output of your custom build and how it can link it with other objects and so on.

Kindly note that this will NOT help you call CUDA kernel from .CPP file.

I am assuming you are a newbie and you want to get your first CUDA program compiled… IF thats the case, then its fine!

but if u r trying to do something jazzy like calling CUDA kernel from a file with extension .cpp then I really dont know.

Thanks, I’m trying to call a function of a file.cu which calls a CUDA kernels (like the SDK example about the CUDA integration in a C++ program)

I use the CUDA CUSTOM BUILD RULE but there is a problem of linking after the compilation.

So can you say to me how correct this problem? I don’t know where I can specify what my final executable would be.

Just below where you specified compilation via NVCC (Custom build rule) – there will be a text box asking “outputs”. There in you can specify the OBJ file path…

For example, my custom build rule for trinomial program is:

nvcc -O2 -I$(CUDA_INC_PATH) -c -o $(ConfigurationName)\Trinomial_Alexandros.obj Trinomial_Alexandros.cu

The output file specified in “outputs” is $(ConfigurationName)\Trinomial_Alexandros.obj

HTH

I do something wrong but I don’t know what.

I do that:

I create a new project
Right clic on this project
–> CUstom Build Rules
----->I select CUDA compile
-------->modify rules files
----------->modify build rule
--------------> I change the output file name in the text box OutPuts
(ConfigurationName)\$(InputName).gen.c become (ConfigurationName)$(InputName).obj

I create a file.cu
–>right clic
----->properties
-------->“tool” box
Custom Build Tool become CUDA

I create a main.cpp
I create code very simple to the test

When I build my project
fatal error LNK1181: cannot open input file ‘.\Release\testCu.obj’ testCUDA

  1. Create empty project without files.
    a) Do NOT create a separate directory for solution (see the check boxes while creating project). That will create more confusions.

  2. Add new file. Name the file as “.cu” file

  3. In the project solution explorer, Right click the “.cu” file and go to custom-build rule section and specify as I had stated before!
    a) Just code a dummy int main() function and then go to next step

–edit–

  1. Right click the project, go to linker->input section. Specify “cuda.lib” and “cudart.lib” as additional inputs!

  2. You should also specify $(CUDA_LIB_PATH) as an additional search directory in linker->general

  3. Compile and create the EXE file!

Now, you can add more CPP files to this project as well and everything will work fine!

–edit over–

Dont worry about “build rules” file and all now! I have never used it before! But since you say you are a beginner - I would recommend not to complicate things.

Let me know if that worked!

Best Regards,
Sarnath

– edit –
Note that if you right click the project and specify custom build rules – then it means that will be applicable for the whole project! - Instead, do it on individual files as of now! May b, as you grow up with VC++, you can consider enabling the custom build rule for whole project. When you set a custom-build rule for while project – I am not sure if VC++ would apply the custom rule for all files OR only for file extensions that it does not know how to compile. THats the reason why I am advicing to enable custom-build rule on a per-file basis first! You can experiment once you mature a bit!

Good luck

The problem is the same

I have created a new empty project, I have added new a file.cu, I have specified the options of the Custom Build Rule, I have coded a simple main function, I have added the diffrent input of the linker but I have the same error.

I give you my very simple project, can you say me what is wrong
test.zip (12.4 KB)

Your project uses “nvcc.rules” – Remove that first from your project! Thats what I meant when I said “dont worry about build rules”… I think I was not clear…

For the same reason, I cant open your project in my Visual Studio. It is searching for that rules file and fails.

Remove the portion that specifies “nvcc.rules” and let me know if it works!

btw, Where did you get that “nvcc.rules”?

NVCC.rules can be find in the SDK “common” folder

–>“script” folder

but I find the problem but I don’t understand it.

But It 's crazy because I use MSVC 8 (visual studio 2005) and the exemple can be compiled without problem

:wacko:

Yeeeeeeeeeeessssssssssssss

I use the cppIntegration project that I modify to optain the result that I want.

It 's compile ,It’s so good but I don’t know why I can’t create a functional project