CUDA "reprint" Installed on Windows Visual Studio

Source: Internet
Author: User
Tags windows visual cuda toolkit nvcc

Original: http://blog.csdn.net/augusdi/article/details/12527497

Prerequisite Installation:

Visual Studio 2012

Visual Assist X

Installation steps:

1. Nvidia graphics driver , 275.33 version, this is the latest version of the driver, the initial installation in order to minimize errors, it is best to install a newer version of the driver.

2. Cuda Toolkit 4.0 installation , the new features of Cuda 4.0 can be found in its release Notes, which includes the thrust library that this article will cover.

3. GPU Computing SDK 4.0 installation , the default installation path may be

C:\ProgramData\NVIDIA Corporation\nvidia GPU Computing SDK 4.0, remember this path is Sdk_path.

4. Parallel nsight 2.0 Installation , this tool integrates GPU universal computing into Microsoft Visual Studio, enabling the use of Cuda C,opencl, DirectCompute, Direct3D , and OpenGL applications for debugging and analysis.

5. You can now use the VS open Cuda SDK example, before that, two tool libraries can be generated first.

A. Use VS2010 to open sdk_path \ c\common\cutil vs2010.sln, VS2010 select "build| Batch build ... "," Select All ", generates all the required lib for the configuration. If you encounter a" Can not open source file ... "error, remove the read-only attribute of the folder.

Purpose: Generate Cutilxx[d].lib XX:32/64 [d]debug mode for each configuration required]

LIB storage location: Sdk_path \ c\common\lib\ (win32| X64)

B. Above method, open sdk_path\share\ Shrutils_vs2010.sln select "build| Batch Build ..."

Purpose: Generate ShrUtilxx.lib XX:32/64 [d]debug mode for each configuration required]

LIB Storage location: sdk_path\share\lib\ (win32|x64)

Note: This project compiles with two prompts. cpp can not find, directly to remove them from the project. Because the full code already exists in the. h file with the same name.

c. Test Example: VS2010 Open SDK Example:devicequery, Matrixmul Various configurations can be compiled and executed successfully, CUDA's basic configuration is finished.

CUDA C + + keyword and function highlighting:

In the Helloworldcuda.cu file above, the Cuda C + + keyword __global__ and so on are not highlighted, and there is a stroke curve. The following syntax highlighting of Cuda C + + keywords and functions, configuring visual Assistx function highlighting, code hinting and other functions.

The following is a set of code highlighting. A total of three settings

1.. CU C + + keyword highlighting in file

This setting is for VS2010 to edit the. cu file, highlighting the C + + syntax in the. cu file.

Setup method: Click on the VS2010 menu: "tools| options...| Text editor| File Extension ", in this interface:" Editor "drop-down box select" Microsoft Visual C + + "in the" Extension "text box to enter. CU Click on the" Add "button and repeat work to add the. Cuh to the VC + + type, click the OK button. Close all. cu files and open them, and the. cu file C + + keyword is highlighted. If not, restart VS2010. But Cuda's keyword is still black, the next step is to highlight the Cuda key self.

2. Cuda keyword highlighting

In order for Cuda keywords, such as __device__, dim3 and other text highlighting, the following steps are required:

Copy Sdk_path\c\doc\syntax_highlighting\usertype.dat to X:\Program Files (X86) \microsoft Visual Studio 10.0 under the \common7\ide\ directory

Here X: is the installation of the VS2010 drive letter, which is the path under the Win7 64 bit.

Note: Win7 64 system do not copy to this directory, copied to here is not cuda keyword highlighting:

X:\Program Files \microsoft Visual Studio 10.0\common7\ide\
(If your Win7 is 32-bit, it may just be the above directory, it should be highlighted, this is Win7 64-bit and 32-bit difference)

Re-emphasize: Sdk_path to replace the actual path you installed the SDK, do not use this string directly.

VS2010 need to restart, after restarting the. cu file, Cuda's keywords should turn blue.

3. Cuda function highlighting, and Cuda function input code hints
This function is implemented using VASSISTX. Install the visual assistx that support VS2010 first, before and after the Cuda installation. Two steps are required to achieve the required functionality:

a) let visual Assistx support Cuda function highlighting and code completion. In the VS2010 menu, click: "vassistx->visual assist X options->projects->c/c++directories" In this interface "Platform" Drop-down box selected Custom, in "Show directories for ..." Drop-down box select other include files, and then in the input box below, create a new, add three paths, click OK, and three paths are as follows:

Sdk_path's \c\common\inc
Sdk_path's \shared\inc
X:\Program Files\nvidia GPU Computing toolkit\cuda\v4.0\include

Here Sdk_path to use your installed SDK path instead, X: Is your CUDA toolkit installation letter.

The functions and types defined in the. h file, respectively, in these three directories VASSISTX help us to highlight and complete the code when we edit the file. If you include less than one path, the functions and types defined by the. h in this directory will not be highlighted and prompted.

b) let visual assistx support the. cu file, and let Visual assistx help us implement the. cu file highlighting and code completion functions, and you need to edit the registry. First close VS2010, click Start Menu input regedit to open the registry, locate the following location:hkey_current_user\software\whole tomato\visual Assist x\vanet11. Find the Extsource project on the right, the right mouse button to modify, in the original text after adding the following text:. cu;. Cuh; After you have determined to close the registry, reopen Vs2010,visual Assistx to start supporting. CU and. cuh file syntax highlighting and code completion. In this case, the Cuda function of the. cu file is highlighted, and the function name symbol automatically prompts for information such as the full name of the function, the parameter type, and so on.

After the installation above, the development program should be no problem, but will find the following problems:

1. VS2010 display. cu file, there are a lot of cuda functions under the wavy line

2. Using the VS2010 "Go to Definition" function in a. cu file cannot find the definition of the CUDA function.

The reason for these two problems is that VS2010 does not recognize these functions and does not specify what they are included in the header file. The solution is actually the same, the Cuda Tookit and Cuda SDK header file path added to the VS2010 VC + + directory inside.

Create your own Cuda project

1. Create a WIN32 console application program Helloworldcuda, select the Empty project, then add a source file HelloWorldCuda.cpp and change the name to HELLOWORLDCUDA.CU.

2. Select Project | Build customizations ... menu, select Cuda 4.0 in the dialog box, which adds support for Cuda C + + files (*.cu)

3. Select the Helloworldcuda.cu file, right-click to select the Property Open Properties dialog box, under the General Properties page, change item type to "CUDA/C + +"

Note: CUDA/C + + has already appeared in the property page

4. Open the linker| Input property page, add "cudart.lib;" in "Additional Dependencies"

5. Add some code to the HELLOWORLDCUDA.CU. ............

Test procedure:

[CPP]View Plaincopy
  1. #include <stdio.h>
  2. BOOL Initcuda ()
  3. {
  4. int count;
  5. Cudagetdevicecount (&count);
  6. if (count = = 0)
  7. {
  8. fprintf (stderr, "There is no device.\n");
  9. return false;
  10. }
  11. int i;
  12. For (i = 0; i < count; i++)
  13. {
  14. Cudadeviceprop prop;
  15. if (cudagetdeviceproperties (&prop, i) = = cudasuccess)
  16. {
  17. if (prop.major >= 1)
  18. {
  19. Break ;
  20. }
  21. }
  22. }
  23. if (i = = count)
  24. {
  25. fprintf (stderr, "There is no device supporting CUDA 1.x.\n");
  26. return false;
  27. }
  28. Cudasetdevice (i);
  29. return true;
  30. }
  31. int main ()
  32. {
  33. if (! Initcuda ())
  34. {
  35. return 0;
  36. }
  37. printf ("HelloWorld, CUDA has been initialized.\n");
  38. return 0;
  39. }

Run with CTRL+F5, compile successfully through NVCC, output result.
"C:\Program files\nvidia GPU Computing toolkit\cuda\v4.0\bin\nvcc.exe"-gencode=arch=compute_10,code=\ "sm_10, Compute_10\ "--use-local-env--cl-version 2010-ccbin

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.