CUDA and VS C++ Win32 GUI application

Can anyone please direct me to an example/explanation of how to use CUDA programming in Visual Studio C++ Win32 applications with GUI?

I have a .cu console example that works and a working .cpp app - how do I put them together?

As I understand, they use different compilers?

One approach would be to create a VS solution that has multiple projects. The output of the CUDA project could be a static library. The other project would contain your GUI, and link against the library.

Another, related approach would be to create a DLL containing the GPU routines you want to call. Build a VS solution around that. I would create this DLL so that the exposed functions are all “wrapper” functions, i.e. not CUDA kernels. Then you would have another VS solution that contains your GUI project, and it would use/link against the DLL.

Under the hood, CUDA projects use cl.exe, the same compiler used by ordinary VS projects, when compiling host code. So linking this stuff together shouldn’t be particularly challenging.

Ok, I’m not a guru, so after some trial and error I finally made it work in VS 2010 Pro, here is what I have, maybe it will help someone else at my level:

.cu CUDA Solution:

  1. Create a new console solution for ‘CUDA 6.5 runtime’ supplied with CUDA SDK
  2. Delete all content in ‘’ and replace it with the content of the attached ‘’. The file has a C++ wrapper function ‘dll_saxpy’ for calling CUDA function ‘saxpy’.
  3. Create ‘Headers’ folder in the Solution and add file ‘stdafx.h’ into it, you can find this file in any Win32 GUI app solution in VS.
  4. Change Solution properties > Configuration properties > General > Configuration type to Dynamic Library and Apply.
    After this the code should compile into a DDL.

.cpp Solution:
Attached file ‘cudaDLLCall.cpp’ contains code for loading, unloading and calling ‘dll_saxpy’ from the DLL, you can use this in any Win32 GUI app you have.
The only thing you will need to change is ‘cudaPath’ and supply your own function instead of ‘updateTextA(msg)’ that outputs ‘msg’ in to whatever GUI text field you have. (1.94 KB)
cudaDLLCall.cpp (1.3 KB)