GPU Parallel Programming in VS2012 with NVIDIA CUDA

You may also like...

  • Pingback: Parallel Programming Menggunakan GPU()

  • davidh2

    Selecting “Build” from the Menu works fine, but selecting “Rebuild” does not…This seems to be because the CudaClean target does not pass the –cl-version parameter to nvcc. Any ideas on the easiest way to fix this in the props or targets files?

    • norture

      Finally I was able to fix the problem. You can refer back to the solution I added on this page. Basically it involves making dependencies for “Clean” the same as with “Build” in the targets file.

  • Nguyen Ngoc Tu

    hi! Thanks for your help! i modified last time, It did rebuild and clear but i worked fine when i build OpenCV GPU (support cuda). But, i did this change, it didn’t work (i modified manually and download file ): nvcc cannot find a supported cl version. only msvc 9.0 and msvc 10.0 are supported. when i create a new project it works. hehe. can you help me fix error! thanks for your attention!

    • Are you sure you have modified all the files? With Windows 7 or 8 the UAC needs to be taken care of as well. Also, make the change in host_config.h as mentioned and you should be fine.

      • Nicola Pezzotti

        I also have this problem… I followed your guide but no way to compile opencv 🙁

        • Yangyan Li

          I have the same problem when I applied this to enable gpu support of OpenCV on Win7 x64 VS 2012. The guide works well for projects managed by VS itself, however, in OpenCV, the actual nvcc compile is invoked by cmake, where I don’t know how to apply the similar thing to workaround the cl version check…

          • I think the best solution is to wait for the updates/official support from NVidia themselves. We can search for more workarounds, but eventually there will be an update.

      • Nicola Pezzotti

        I figured out something… While in host_config.h you can find the following string “unsupported MSVC version! Only MSVC 8.0, 9.0, and 10.0 are supported” Into nvcc.exe you can find this string “Only MSVC 9.0 and MSVC 10.0 are supported” any way to avoid this check?

  • I want to thank you for taking the time to create the solution and document it online. I would never have worked through the problem of getting CUDA 5.x to compile with VS 2012 without your help. Thank you big time!

  • trent

    Excellent guide!!!!! You saved me! I was literally spending hours searching for a solution. I have to admit this did not work straight out the box. Initially used your .rar customization files and it would not work for some reason. Then I manually modified the files and it worked. A file comparison between your .rar customization files and those in “C:Program Files (x86)MSBuildMicrosoft.Cppv4.0V110BuildCustomizations” outlined other differences aside from the modifications you advised editing. So maybe that’s why it broke initially? Not sure, as I haven’t had time to look into this. I am using “cuda_5.0.35_winvista_win7_win8_general_64-1.msi”. Maybe there have been some updates in the customization files since you posted your blog. On a side note, your code above contains “amp;” within. A novice copying/pasting that straight into VS might be unaware that this is a html formatting error which the compiler will not like 🙂 Thank you so much again! 🙂

    • Yes it seems with the current build of CUDA some files have many differences which might have been introduced after my version. Therefore I would recommend to follow the instructions rather than downloading the pre-modified files. The sample code has been fixed. It was an HTML formatting error as you mentioned. Thank you for your valuable feedback! 🙂

      • Frank

        Many thanks for your guide of configuration! I was wondering if the “quot” in the code of step 6 is also actually not needed. And I have followed exactly the instructions but there are still problems. First, the “Compile” is gray, which means it cannot be used. Second, when I “build” the project, it said “1 succeeded” but actually nothing happened, i.e. no excutable files (*.exe) is generated. The entire output of build is as follows. 1>—— Rebuild All started: Project: cuda_test2, Configuration: Debug Win32 —— ========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ========== It’s weird that nothing like “linking…” is outputed, which should be the case for the building of a general project. BTW, the name of my source file is with “cu” extension, namely, And there are errors about “__global__”, “blockIdx”, “cudaMalloc()” and all the CUDA staff. I can’t figure out why. And it’s even weirder that the solution succeeded to build with there “errors”.

        • The quot in step 6 is actually part of the original code. I merely added the %(CudaCompile.BuildCommandLineTemplate) part to it so the (re)building process can be executed. Regarding the output I got this: —— Rebuild All started: Project: CudaExample, Configuration: Release Win32 —— Compiling CUDA source file… CudaExample.vcxproj -> C:UsersXXXDocumentsVisual Studio 2012ProjectsCudaExampleReleaseCudaExample.exe And I can find the outputted exe file. It looks like you did not follow the instructions given in the folder “C:Program Files (x86)NVIDIA GPU Computing ToolkitCUDAv5.0extrasvisual_studio_integration”. There is a couple of txt files containing such instructions to do the integration.

          • Frank

            Hi. Sorry I didn’t notice the “quot” is in the original code. As for the instructions given in “visual_studio_integration”, I already copied the “*.rules” files and BuildCustomization files to the indicated directory before I created the testing project. I don’t know if there is something else to do about configurations. I copied the “vectorAdd” project of CUDA samples from “D:ProgramDataNVIDIA CorporationCUDA Samplesv5.0_Simple” to my own directory. That is, the entire “vectorAdd” subdirectory was copied to, say, “E:wkspvs”. Then I opened the project file “vectorAdd_vs2010.sln” with Visual Studio 2012, which asked me to update the old version project files. And I did. Yesterday, the project couldn’t be successfully built, but after I followed your instructions in the blog I built it successfully. So the problem is that I cannot build my own project. I tried again and it came to the same result. I first created a “Win32 Console Application” project and then add a new “” to “Source Files”, the contents of which is just the example given in this blog. Then I checked the “CUDA 5.0” option in “Build Customizations…”, the “path” value of which is “$(VCTargetsPath)BuildCustomizationsCUDA 5.0.targets”, and started to build. The result is the same as what I described in the previous comment. What I found is that in the sample “vectorAdd” project, the “Build Customizations…” contains another option “CUDA 5.0(.targets)”, the “path” value of which is “$(CUDAPropsPath)CUDA 5.0.targets”, and this option is checked instead of the “CUDA 5.0(.targets, .props)” described above. But in my own project, this option is not available. I tried to add “D:Program FilesNVIDIA GPU Computing ToolkitCUDAv5.0extrasvisual_studio_integrationMSBuildExtensionsCUDA 5.0.targets” manually but still it didn’t work. I really don’t know how I can configurate it right.

          • I can confirm your situation, I tried creating a project from scratch, but it won’t compile. That’s very strange, given the fact that settings and configurations are similar. What I would suggest is to use the solution files from samples and modify them instead of creating them yourself. Edit: You have to set the property called “Item Type” for each of the .cu files to “CUDA C/C++” and only then it will be able to compile. So now you can create a new project from scratch.

          • Chace

            Hi, thx a lot for your help. But I am also suffering the trouble above. I just follows the steps. When I set the property called “Item Type” for .cu files, I cannot find “CUDA C/C++”. What can I do?

          • If you cannot find it, most probably you have not selected the Build Customization options for CUDA from the Project menu. Another way is to select the project from Solution Explorer, right click and choose “Build Customizations”.

          • Chace

            Thx a lot, I’ve solved it. Thx again!

          • Nice to hear that. You’re welcome 🙂

  • gpu_boy

    very good, thank you so much

  • Elo

    Still cannot compile the project. VS cannot recognize <<< – I assume it does not invoke nvcc – but everything else (__global__, cudaMemcpy, etc.)

    • Are you sure you have selected the Build Customization options for CUDA from the Project menu? Another way is to select the project from Solution Explorer, right click and choose “Build Customizations”. Then make sure to set the property called “Item Type” for each of the .cu files to “CUDA C/C++” and only then it will be able to compile.

  • DougB

    hi … this has helped me tremendously .. however, I’m still getting some errors (Windows 7 64bit with VS 2012 and CUDA 5.0) … When I try to clean the project I get Error 1 error : nvcc supports ‘–relocatable-device-code=true (-rdc=true)’, ‘–device-c (-dc)’, and ‘–device-link (-dlink)’ only when targeting sm_20 or higher C:ProgramDataNVIDIA CorporationCUDA Samplesv5.0_SimplesimpleSeparateCompilationnvcc simpleSeparateCompilation and Error 2 error MSB3721: The command “”C:Program FilesNVIDIA GPU Computing ToolkitCUDAv5.0binnvcc.exe” –use-local-env –cl-version 2010 -ccbin “C:Program Files (x86)Microsoft Visual Studio 11.0VCbinx86_amd64″ -rdc=true -I”./” -I”../../common/inc” -I”C:Program FilesNVIDIA GPU Computing ToolkitCUDAv5.0include” -I”C:Program FilesNVIDIA GPU Computing ToolkitCUDAv5.0include” –keep-dir “x64Release” -maxrregcount=0 –machine 64 –compile -DWIN32 -D_MBCS -Xcompiler “/EHsc /W3 /nologo /O2 /Zi /MT ” -o “x64/Release/” “C:ProgramDataNVIDIA CorporationCUDA” -clean” exited with code -1. C:Program Files (x86)MSBuildMicrosoft.Cppv4.0v110BuildCustomizationsCUDA 5.0.targets 754 10 simpleSeparateCompilation same errors occur on cdpQuadtree, cdpSimpleQuicksort, cdpSimplePrint, cdpLUDecomposition, and the cdpAdvancedQuicksort projects … Finally, when I try to build I get the following errors on some of the projects (for example cdpSimplePrint) nvcc : fatal error : nvcc cannot find a supported cl version. Only MSVC 9.0 and MSVC 10.0 are supported C:Program Files (x86)MSBuildMicrosoft.Cppv4.0v110BuildCustomizationsCUDA 5.0.targets(656,9): error MSB3721: The command “”C:Program FilesNVIDIA GPU Computing ToolkitCUDAv5.0binnvcc.exe” -dlink -o “x64/Release/cdpSimplePrint.device-link.obj” -Xcompiler “/EHsc /W3 /nologo /O2 /Zi /MT ” -L”C:Program FilesNVIDIA GPU Computing ToolkitCUDAv5.0libx64″ -L”../../common/lib/x64″ “cudadevrt.lib” “cudart.lib” “kernel32.lib” “user32.lib” “gdi32.lib” “winspool.lib” “comdlg32.lib” “advapi32.lib” “shell32.lib” “ole32.lib” “oleaut32.lib” “uuid.lib” “odbc32.lib” “odbccp32.lib” “kernel32.lib” “user32.lib” “gdi32.lib” “winspool.lib” “comdlg32.lib” “advapi32.lib” “shell32.lib” “ole32.lib” “oleaut32.lib” “uuid.lib” “odbc32.lib” “odbccp32.lib” -gencode=arch=compute_35,code=sm_35 –machine 64 x64/Release/” exited with code -1. Thanks!!

    • DougB

      Okay… doing some additional research I think I can answer my own question. cdp is CUDA Dynamic Parallelism … (see I only have a compute device 20 on my computer. Hence it seems to be checking the capabilities of the computer I am compiling the code on.

  • Jules Pénuchot

    This saved me from getting disgusted from CUDA. I don’t know why Nvidia didn’t make a single update to fix that issue… Thanks very much.

  • Kevin

    Guys, I’m a novice and tried this solution but ran into a wall. The header file “host_config.h” opens up in VS2012 and on that line I find “1500”. I made the change to “1700” but it won’t save. Apparently I can’t make modifications to the folder. I also noticed that the folder was located in Program Files and not Program Files (x86) if that matters. Moved the folder to Program Files (x86) and same result. In addition I couldn’t find “paths” to remove x86. Some guidance here please. Thanks.

    • Kevin

      in addition, I tried ‘save as’ to get a new copy too and that still won’t work

      • it’s a permission thing. If you use an editor that has been started in ‘administrator mode’, you should be able to save the changes. To start an editor in administrator mode, right click the editors’ shortcut and select ‘Run as administrator’.

  • Kevin

    Figured out how to make the edits. But still can’t “paths” to remove the x86.

    • Actually the paths need not be removed. What I meant by ‘removing’ is to appropriately change the path itself according to your circumstance, i.e. you’re supposed to make the edits in Program Files (x86) folder if you have 64-bit OS, otherwise change the files in the ordinary Program Files folder if you have 32-bit OS.

      • Kevin

        Please for guidance on making these edits. I’m not sure what to do. Thanks

        • Your inability to change files in Program Files folder is due to insufficient permission related to the UAC feature in Windows 8. One verified solution is first you have to copy the files to be edited to your Documents folder where you have write permission, then copy back those files to the Program Files folder after you’ve modified them.

          • Kevin

            Ok got it. I still can’t run any programs though. Done everything here. VS recognizes the <<>> but it underlines __global__ with error: this disclaration has no storage class or type identifier. Set the “Item Type” for .cu files to CUDA C/C++, and included cuda.h. No success with any of the sample solutions provided either.

          • That’s quite strange. Are you using a newer version of CUDA? Don’t forget to set the Build Customizations to CUDA from the Project menu. Also make sure all modified files are there.

          • kevin

            Finally got something to work. Needed to include some .pbd files. Not sure what those are and why I needed to. Now the files execute and exit with code 0.

  • E

    Thanks a lot! Found this after a whole afternoon of installing, trying, failing, uninstalling, reinstalling, trying some more, failing again and so on. While I found parts of this solution in other places here I finally found all changes needed and got an example to compile in only 5 minutes of configuring 🙂

  • Li Shuda

    Hi Thanks for the tutorial, but after carefully following the instructions above, I still get the following errors: 2>—— Build started: Project: HelloCuda, Configuration: Debug x64 —— 2>Build started 02/01/2013 02:15:09. 2>InitializeBuildStatus: 2> Touching “HelloCuda.dirDebugHelloCuda.unsuccessfulbuild”. 2>CustomBuild: 2> Building NVCC (Device) object CMakeFiles/HelloCuda.dir//Debug/ 2>nvcc : fatal error : nvcc cannot find a supported cl version. Only MSVC 9.0 and MSVC 10.0 are supported 2> CMake Error at (message): 2> Error generating 2> C:/csxsl/src/gpu-shuda/cuda/hello_world/build/CMakeFiles/HelloCuda.dir//Debug/ Do you have any idea about this? Thank you very much.

    • Li Shuda

      Hi, Just find this link useful in solving my problem: I follow Project Configuration Section, and everything works now!!!

  • EEN

    thanks alot. can you explain the way how it works with detail?

    • I think it seems that the modifications are required only to circumvent the VS version detection, otherwise the set up is basically the same for all VS.

  • Seems like support for VS2012 is nonexistent right now (January 2013). No project templates, sample proj fails to load as it fails to find CUDA 5.0.props in the right place… didn’t expect this from NVIDIA.

    • That is unfortunately true. I have no idea why they don’t just release a small update version, given that everything works after those simple modifications.

  • herohuyongtao

    Excellent work. I have one further problem. Configuration does work when setting with Visual Studio 2010 (v100) Platform Toolset. But it doesn’t work with Visual Studio 2012 (v110) Platform Toolset. Any ideas on why? And one more question is that (maybe related to the first question), in above step 2, why not just change CUDA 5.0.targets to be like “2012” (note not 2010 here)?

    • If you change it to 2010, it will not have any effect but instead complain that version 2012 is not supported. In fact, this is the issue we are talking about in the first place.

  • Lawrence

    Hi, thanks for your article, this has been the most progress i’ve made so far. I’m starting to use CUDA from my thesis. I can get the SDK examples to compile in 2012 but when i try to get the exercises (from to compile i get the nvcc cannot find a supported cl version only MSVC 9 and 10 are supported, Any ideas? Thanks.

  • rdmsgl

    When I try to compile the code, I get the following error: Error: The project file could not be loaded. Name cannot begin with the ‘$’ character, hexadecimal value 0x24. Line 626, position 35. C:Program Files (x86)MSBuildMicrosoft.Cppv4.0V110BuildCustomizationsCUDA 5.0.targets It is referring to the line “CommandLineTemplate=”"$(CudaToolkitNvccPath)" %(CudaCompile.BuildCommandLineTemplate) %(CudaCompile.ApiCommandLineTemplate) %(CudaCompile.CleanCommandLineTemplate)” />” from above. I presume the CudaToolkitNvccPath variable is not being set properly or something… I imagine that my CUDA installation is not completed properly, but I have uninstalled and reinstalled several times and I can’t find any errors. Do you have any suggestions? Thanks –

    • It strictly has to be like this: CommandLineTemplate=”& quot;$(CudaToolkitNvccPath)& quot; (Note the & quot;)

  • Dynamic Parallelism Problem

    Works perfectly, however, I get “1>nvcc : fatal error : nvcc cannot find a supported cl version. Only MSVC 9.0 and MSVC 10.0 are supported” when trying to compile with dynamic parallelism, rdc=true and cudadevrt.lib linked. Does anyone have an idea of how to avoid this additional check?

    • I am sorry, but for now I think the solution is to wait for the next version of CUDA which will (undoubtedly) support VS2012.

      • Dynamic Parallelism Problem

        Thanks for the answer, I suppose you’re right, so I’d have to revert back to VS2010 in the meantime, it’ll probably take a while.

  • Yoel Shoshan

    Thanks a lot! I can build Cuda samples in visual studio 2012 thanks to you now 🙂

    • You’re welcome! Some people didn’t manage to get it right on compiling advanced projects, though. For example building OpenCV.

  • Nicolas Tian

    Thanks a lot for the sharing! It saved me significant time of messing with CUDA configuration.

  • rayburgemeestre

    Awesome, worked perfectly!

  • Mike

    This book must to have it demonstrates CUDA in practice for optimizing applications

  • goryachih

    Thanks for instructions! But after all changes only nvidia samples build correctly. When I tried it in my own project I got this message: “nvcc : fatal error : ‘-ccbin’: expected a number” Do you have any idea?

    • Have you set every source files as “CUDA C/C++”? It is in the Properties Dialog under Configuration Properties->General->Item Type

      • Munesh Chauhan

        Hi I am not seeing the option of CUDA C/C++ at this location. Have I missed anything?

        • Maybe your BuildCustomizations settings are not set up properly. Check for missing modifications and try again.

          • Munesh Chauhan

            I can see the option Cuda5.5 targets in Build Customization. But when I select it and create a new source file “” I get the message “The project file could not be loaded.”” is an unexpected token. The expected token is ‘=’. Line 802, position 32, C:Program Files(x86)MSBuildMicrosoft.cppv4.0V110BuildCustmomizationCUDA5.5 targets

          • Can you post here what exactly does the line 802 contain? Maybe there is a missing equal sign somewhere.

          • Munesh Chauhan

            CommandLineTemplate””$(CudaToolkitNvccPath)” %(CudaCompile.BuildCommandLineTemplate) %(CudaCompile.ApiCommandLineTemplate) %(CudaCompile.CleanCommandLineTemplate)”/>

          • That’s it. You’re missing an equal sign. Obviously it should be CommandLineTemplate=”"$(CudaToolkitNvccPath)" %(CudaCompile.BuildCommandLineTemplate) %(CudaCompile.ApiCommandLineTemplate) %(CudaCompile.CleanCommandLineTemplate)” />

          • Munesh Chauhan

            Many thanks, now the error comes name cannot begin with a dollar character — Line 802 Pos 35

          • Munesh Chauhan

            A request, can you please email me this file in case you are having it. My email muneshchauhan at gmail dot com

          • I’m sorry but I have reinstalled my system. Please download the BuildCustomizations.rar file I attached in the blog post instead and compare its contents to yours. Do not copy & paste straight into your installation, since they are of different version (5.0 vs 5.5). Good luck!

          • Munesh Chauhan

            Great thanks for the info, By the way I mistakenly copied your file straight away. That means the original cuda5.5 targets file may have been lost..

          • Munesh Chauhan

            Many thanks Fardana, I was able copy cuda5.5.targets and changed the lines as mentioned on this blog. Further I added cudart.lib in Project -> properties -> Cuda C/C++ -> Linker -> Input -> Additional dependencies and added cudart.lib. CUDA is running ! Thanks again

  • tanglei

    thank u for the post.

  • Pingback: Making CUDA v5.0 work with Visual Studio 2012 | TeaKov's Blog()

  • Rachit Kalra

    Thanks a ton 🙂

  • cloudy

    I installed VS 2012 and Cuda 6.5. But I can’t see CUDA template in my VS2012. How I can fix it?