How to add a cuda-file to VS 2015 c++ solution

I have a simple c++ VS2015 solution, a form and a button adding some numbers. Now I want to add a cuda file and do that adding on the GPU. How do I add that cuda-file? All my attempts have failed and I find only 10 years old tutorials for that simple task. I feel real foolish. Why can I not just add a file or a class or whatever and choose cuda 8.0??? I have installed Cuda of course, I can run the cuda-examples.

I would create a new empty CUDA project and use that as a guide for the settings that are needed to add a CUDA file to your existing project.
There is no special magic, it’s just about using the right settings.

Thank you for your swift reply. I created an .cu-file with only the cuda-header includes and I copied all settings I could find. However, I get the same error on compilation:
Exception thrown at 0x777F13B9 (ntdll.dll) in CLRFormPlusCuda.exe: 0xC0000005: Access violation reading location 0x80C13CE5, which doesn’t tell my anything.
Guess there is some magic to it anyways:-)

There are instructions on this forum about some possible methods to use CUDA in a C++/CLI (CLR) project. Here’s one example:

[url]https://devtalk.nvidia.com/default/topic/979462/how-can-i-compile-cuda-code-then-link-it-to-a-c-clr-project/[/url]

Well. There is this simple list

  1. File->New->Project->Visual C+±>CLR->CLR Empty Project.
  2. Project->Add New Items->UI-> Windows Form.
  3. Project->Add New Items->NVIDIA CUDA 8.0->Coda-> CUDA C/C++ File.
  4. Your project->Build Customisazions…-> CUDA 8.0
  5. Project->Properties->Linker->Input->Additional Dependencies->“cudart.lib;”
  6. Project->Properties->Linker->System->Subsystem->Windows(/Subsystem:WINDOWS)
  7. Project->Properties->Linker->Advanced->Entry Point->“main”
  8. Files such (sample)

However, When I get to point 3) Project->Add New Items->NVIDIA CUDA 8.0
I can not choose NVIDIA among new items. I can only choose from “Visual C++” and “Online”. And online is nothing…

Hello Flisp,

You need to install CUDA from the following link before you could get a new project of CUDA type in Visual Studio.
[url]https://developer.nvidia.com/cuda-downloads[/url]

You can have a look at this video where they get Step3.
[url]CUDACast #2 - Your First CUDA C Program - YouTube

This is the same problem which I got. This is the pure installation problem of addons for Visual Studio 2015. Please reinstall in case you don’t see this. I did reinstall to get the CUDA addon.
And note that CUDA 8.0 is still not launched for Visual Studio 2017. So Visual Studio 2015 is the latest version which supports CUDA 8.0

Let me know if you still don’t get it.

Thanks

Thanks again.
I reinstalled CUDA (8.0.61_win10) but still no NVIDIA option when I want to add an item.
(I have only the new project NVIDIA option)
Do I need to reinstall VS as well?

I now uninstalled and reinstalled both Visual Studio 2015 and Nvidia 8.0.61 and even some patch. But still no addon for an new NVIDIA item. Any suggestions?

Okay, in such cases let’s try some more steps

  1. Update the latest Graphics Card Driver
  2. Download the Nsight (Win 64-bit) from the following website
    [url]https://developer.nvidia.com/gameworksdownload#?dn=nsight-visual-studio-edition-5-3-0[/url]
  3. Restart your computer and check again and tell me.

Nvidia nsight 5.3.0 installed, but no new NVIDIA item 'n sight:-)
Just to make sure it’s not me being stupid. I have a CLR Form. I try to add a cuda file by Project>New Item> and there I can only choose c++ files, Graphics (images and stuff) and online. It is here I expect some NVIDIA option. I tried the code from the link txbob suggestest but I can not compile it due to an error if that is any help:
"Severity Code Description Project File Line Suppression State
Error LNK2001 unresolved external symbol _Main Project2 C:\Users.…\Documents\Visual Studio 2015\Projects\Project2\Project2\LINK 1

One Question when you installed CUDA 8.0 did you keep the Visual Studio on in background by any chance. As at the end of cuda installation it gives a set of add-ons installed and the not installed ones.

And before compiling you need to get the step 3, otherwise, you won’t get the .cu file, which is like a .cpp file. If you don’t get anything like that, the compilation of the cuda functions won’t make any sense to the compiler. I mean you need to get the template as shown in the video I suggested (NVIDIA template and then the CUDA) then it means your cuda is not getting installed properly.

And if you reinstall there is no need for the visual studio 2015, you need to just reinstall cuda. Make sure there is no visual studio application open, close all the apps and then only reinstall cuda. This is the exact thing I was facing because I kept my Visual Studio on in background and was trying to install cuda. So at the end, I got a message after installation in the cuda release that cuda not installed for visual studio 2015.
Hence, I closed all the applications and then reinstalled cuda. And it worked for me. I also installed Nsight and it came.

Thank you Shaurakar for your engagement!

I closed all VS, checked even in the task manager for hidden stuff.

At the end of installation I get a list telling me that Cuda is installed for VS2015 but not for other versions (since I don’t have any).

I can run Cuda-code. Both samples and code I written myself. I just can NOT add a .cu file to a form (or concole for that matter). It’s really frustrating!

I reinstalled Cuda now one more time but the final message was different since installed Nsight was newer that the one in the cuda-package. I have installed both VS and Cuda several times now with no difference.

I have never used Nsight and don’t know what to expect, but it’s there. Nsight want’s to go online when debugging. I don’t know why.

I am running VS 2015 community edition. Might that be a problem?

Usually, you don’t have to add the .cu file, when you choose the cuda template from visual studio it will automatically add a .cu file.
Check here if the visual studio community is supported or not.
[url]Installation Guide Windows :: CUDA Toolkit Documentation

Also, try uploading a video of your steps what you are following. It is difficult to get the exact picture what is happening.

Somewhere I did read that cuda is supported from professional edition but may be completely wrong. I just can’t recollect why i changed from community edition to professional edition. It might be cuda but now I don’t recollect. There was for sure some reason for me to change from community edition to professional edition.

When I start a Cuda-project I get .cu files and they work fine. I can run both own cuda programs and samples. No problem there.

I downloaded VS2015 Pro, installed CUDA and NSIGHT and have the same problem.

I fear the problem is somewhere else entirely. Maybe some header thing I am missing, some setting, I don’t know…

Shaurakar, you could do me a huge favor: Can you write a super simple program (as a VS solution), one form with one button, calling a cuda-kernel-function to do something simple like vector addition and send it to me, so I can see if I compile and run it? Or point me somewhere where I can download one?

Ok, that can be done. But before that can you post a video of your problem in youtube or something. I want to see the exact issue. I still haven’t understood the issue.

I have written a program in c# running an immensely time consuming analysis of files using a GUI to select the files, display results etc. To bring down calculation time I want to use CUDA. I have translated the program from C# to C++ (barely, because I know little about C++) and the crucial analysis to CUDA. But I can’t bring the two together. Now I’m looking for any template of a CLR-Form calling any simple Cuda-kernel, that I can use to put in my GUI-controls and my CUDA-code. I have tried this: [url]CUDA GUI VS 2015 + CLR FORM [Simple Adding] - YouTube but get a lot of unresolved external symbol errors, I don’t know how to fix. What I need is a solution for VS 2015 with a simple GUI calling any simple cuda-kernel. The rest I can fix myself (I hope:-).

I finally got it to work. The YouTube above tells to target x64, but I changed it to target x86, both in the Debug option and in Project>Properties>Linker>Advanced>Target Machine>MachineX86 (/MACHINE:X86).
Curiously neither copying the settings from a clean cuda project nor from the working solution above did help. Why that is so, maybe someone else can answer. But an external symbol error IS a settings problem. Good to know for bloody newbies like me. ANd one more thing, the discusion in the beginning: It seems that neither VS 2015 Community nor Professional has the New Item > NVIDIA Cuda option. VS 2012 Ultimate has, Enterprise, I don’t know.

Thank you all for trying to help me.

Hi

Great that you have got things to work. I am stuck in the same problem in Visual Studio Community 2015, so I am looking for help, here and there.

It would be great if you would write the steps that you followed so that we can follow those too. Or it would be great if you provided the minimum working solution so that we can expand on that ( if this is not too much that I am asking :p )

The working solution for Visual Studio 2015 is a simple From with one button and a multiline Te4xBox to display the results from an CUDA vector addition. It is basically the code and all the settings from the YouTube video by Ka Mirul CUDA GUI VS 2015 + CLR FORM [Simple Adding] - YouTube.
However, that tutorial showed a setting where a x64 machine was targeted, which did not work on my computer. I finally got the solution running by setting it up on an old Win32 machine with VS 2012 Ult. I than copied it back to my vs 2015 where it worked. To make Ka Miruls solution work you need to target a x86 machine: Project>Properties>Linker>Advanced>Target Machine>MachineX86 (/MACHINE:X86).
Below you can download my workning solution as a .rar-file from Dropbox.

If you work with VS community there are two ways to add .cu-file to a solution (once you have a running solution, with all the correct settings)

  1. Create the file outside VS and save it in the project directory. The import it as Project>Add Existing Item.
  2. Project>Add New Item choose a txt-file or a cpp-file and simply name it xxx.cu instead of xxx.txt or xxx.cpp. Just double check that its settings are correct by right-clicking on the file>Properties>Configuration Properties>General>Item Type>CUDA C/C++. That shoul happen by itself if you have checked CUDA 8.0 in Project>Build Customazations
    Please let me know, if it works.

[url]Dropbox - File Deleted

Thank you so much for the help.

Your solution compiled and worked fine. Right now I am implementing my project as a console application which I originally planned to implement using GUI. Now I plan to extend upon from your work.

I will write to you if I have any difficulties.