How do I CUDA on Windows?

So, I had a dying GPU. I think. I wasn’t even sure that it was the GPU that was dying. But I wasn’t going to play bad part whack-a-mole with a 6 year old computer so I decided to just upgrade computers entirely.

Part of this upgrade including switching from Ubuntu to Windows 10. I’m absolutely at a loss for what to do to get stuff to work in Windows lol.

I’ve downloaded an Nvidia display driver and I got that working. I installed VS Community 2015 and I’ve verified that I can compile “Hello, world!”. I’ve then since downloaded CUDA and Nsight Visual Studio.

Visual Studio is very alien to me. I’ve found that the only way I can do anything CUDA related is to make a new CUDA project (I can at least do that) and I was able to compile an empty main. My question becomes, how do I port in my entire project? I don’t see any other way of importing something that’s not a Visual C++ project.

What’s the CUDA Visual Studio workflow like? I tried googling a bit but didn’t find anything productive.

As someone who has used CUDA extensively on Linux and Windows (and a little bit on OS X), my suggestion would be to install the complete Cygwin suite (and Emacs if that is your editor of choice), then use command line tools and makefiles. Forget MSVS solution files or using CMake, those are build obfuscation tools in my view.

You should be up and running in no time, you just need to learn a bit about different host toolchain switches, path separators, and file name extensions and you are good to go. With a smidgen of effort you can even set up your makefiles to work on both Windows and Linux by abstracting the relevant differences into a single file.

Note: I have zero experience with the VS Community editions; personally I have found it worthwhile to shell out the money for MSVS Professional, but your mileage may differ.

My personal opinion is that CUDA is easy to use in Windows with Visual Studio.

There is a good resource video set here which goes over the setup with Visual Studio;

https://www.youtube.com/playlist?list=PLKK11Ligqititws0ZOoGk3SW-TZCar4dK

That video series is 4 years old and he uses Visual Studio 2010 I believe, but in general later versions of Visual Studio follow the same setup. I still use Visual Studio 2012.

If you have a GPU which can use the TCC driver I recommend switching to that driver via NVSMI. Otherwise make sure you set the WDDM timeout (the video #3 shows how to do this, but make sure you reboot after).

Also the folks at Orange Owl have a blog which goes over a bunch of Visual Studio related issues;

http://www.orangeowlsolutions.com/archives/tag/visual-studio

and also go over how to work with MATLAB including profiling and debugging mex files.

Okay, I’ll check out the video then!

I’m still king of just exploring the IDE but it doesn’t seem too bad.

In one sense, I agree with you, njuffa. But I still think this would be a valuable skill for me to learn. I see a lot of jobs that require developing-on-Windows experience.

I do miss Ubuntu though… Mostly for the awesome suite of command-line tools. But hey, I can play Starcraft II again so that’ exciting!

Being familiar with software development on both Linux and Windows is certainly a valuable skill, and it can get you ahead of people who “don’t do Windows” in the job market. Yet, for all the many years I have developed on Windows, I have found it is best to stick with command line tools, in particular for large, multi-platform projects. When working for hardware manufacturers, multi-platform development is pretty much unavoidable. MSVS solution files in particular can be hard to deal with once you add scripted automation to a large multi-platform environment.

A common issue for non-expert users of MSVS is just trying to remember where stuff is. You may know exactly what compiler or link switch you need to add, you just can’t find where you need to add that. Probably in some dialog five sub-menus down, and in a different place from the previous version of MSVS. My all time record for such a search is 30 minutes for a (to me) completely non-obvious location. This effect is reflected by many of the MSVS-specific questions in these forums. People report broken builds simply because they forgot to set or remove a flag or file somewhere, but it’s not trivial to see that they did.

Ha, that’s fair enough :P

I think I’m going to stick with Windows as my main development OS now. I’m doing this for a couple of reasons though. Namely, Linux fatigue. Linux distros just aren’t big enough targets (yes, I am looking at you, Nvidia) and at the end of the day, Windows needs the good software more than Linux does.

Okay, so… how do I do this? If I install Cygwin, that’s cool. But I’ve already installed MSVS and CUDA. nvcc seems like it’s linked to CL.exe (the MSVS compiler [which I really just learned about]). If I were to install the ports of gcc over, can I go into my CUDA install and just reset the symlinks? Or whatever Windows calls symlinks?

I don’t mind going the command-line route in Windows, tbh. But I was playing around with Visual Studio 2015 last night and I gotta say, as far as an IDE for CUDA, it’s pretty decent. I just wish I could figure it out a bit better. I learned you can add multiple items from a folder! Only issue is, it adds them in a flat way. I want directory structure, darn it!

CMAKE may be able to provide a middle ground to achieve cross platform compatibility.

CMAKE projects can detect a CUDA installation, regardless if running on Windows or Linux and will create platform specific project or make files (Visual C++ 2015 is one of the supported platforms) if needed.

The only thing to really watch out for is to neither use Microsoft specific language extensions, nor any gcc/g++ specific intrinsics or extensions when coding. Declaring memory alignment requirements of variables and struct packing does work a bit differently between the two compilers. Best to pack this into a #define that gets set depending on the host compiler.

I cannot recommend running cygwin together with CUDA, as it is not a supported host compiler for CUDA. But it does provide the familiar Unix shell and build environment for sure.

Christian

I suspect regarding cygwin that njuffa was just suggesting it for shell/environmental stuff. I imagine he meant that nvcc compile options should be specified to use cl.exe

You cannot use gcc on Windows, you will have to use MSVC.

When I recommended to “install the full Cygwin package” the intent was to give you a consistent set of familiar Unix command line tools. In particular, you would want gmake as a make tool which works the same as your Linux gmake. Prior to using Cygwin, I personally used mkstools for many years, which was commercial software providing Unix development tools on Windows. Cygwin is better, and free.

Cygwin can be installed in bits and pieces, which is what I did when I first used it 15 years ago. I found that over time, one then finds that one forgot some tool that would come in really handy now, and it became difficult to mix and match versions years apart due to an un-versioned shmem block used by Cygwin. Better to wait five hours for a full install, then use that for the next ten years. I have been using my current installation unmodified for the past four years.

CMAKE gives people more rope to hang themselves, as shown by build configuration questions about it here and on Stackoverflow. Same issue as with MSVS solution files: Instead of spending 30 seconds to simply add a compiler flag where you know it is needed, you may spend 30 minutes trying to figure out how to describe to CMAKE when and where to add that flag. Been there, done that, got the t-shirt. Never again.

@cbuchner1 As far as alignment goes, last time I checked, CUDA’s alignment directives are translated (via definitions in host_defines.h) into the platform specific versions for host code, which is how CUDA’s own predefined vectors types are usable from host code.

In order for cmake to work properly for the average CUDA user, it must be maintained properly, and must evolve forward as CUDA toolchain gradually evolves over time.

For example, I’ve seen a considerable number of folks struggling to use Cmake with CUDA separate compilation. Things may be fixed, now, not sure.

But the complexity of the process e.g. of building a library (.dll or .so) that includes CUDA separable compilation components would give me pause before I would try such a thing in Cmake.

As a final note. If someone loves GUI IDEs and considers command line tools archaic remnants of a distant past only used by dinosaurs as myself, by all means learn how to use the Visual Studio IDE, just expect there to be an initial learning curve and to spend some quality time now and then as you figure out how to do something you haven’t done before, such as building a DLL. Under the hood, MSVS uses the command line tools anyhow (or at least used, I am using an older version), which can easily be seen when you turn on detailed logs.

So, I found out about the MSVS developer console. And then I learned about NMake. I’m hoping these can work with the existing CUDA toolchain. I’m not at my home computer so I can’t try but ideally, I’d like to switch to using the developer console and NMake. It’s similar enough to regular Makefiles that maintaining both should be relatively straight-forward. And the best part is, no more Visual Studio! I’m not going to give up on VS yet but it is nice to have a simple way of creating one-off C++ files.