CUDA programming (1) installation

foreword

  1. What is a CPU

    Consisting of millions of transistors and can have multiple processing cores, a CPU is often referred to as the computer's brain. It is an essential component of all modern computing systems as it executes the commands and processes required by computers and operating systems. CPU also matters when it comes to determining how fast programs run, from web browsing to building spreadsheets.

  2. What is a GPU

    A GPU is a processor made up of many smaller, more specialized cores. Working together, these cores can deliver powerful performance when dividing and executing a processing task among multiple cores.

  3. Why do we use GPUs

    In the era of the rise of AI, scientific computing often involves very high-dimensional matrix calculations, and CPU-based serial computing is difficult to meet its performance requirements, so GPU-based parallel computing emerged as the times require. Obviously, parallel computing requires processing a lot of data at the same time, which requires hardware with many cores. Therefore, in the same price and power range, it provides higher instruction throughput and memory bandwidth than CPU.

Install

1. Installation environment

win10

vs2019

miracles 11.1

2. Open VS and create a new empty project

Create a .cu file for CUDA in the source file. Among them, when the CUDA installation is completed, the corresponding CUDA area will appear. (If there is no such area, please refer to https://blog.csdn.net/weixin_39591031/article/details/124462430)

32c27dd12a72c83de6bc0e95a03f9950.png

3. Configure the environment

Add C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1\include in the VC++ directory---include directory

b931f7932f6c67a84af0c9be6800a0aa.png

Add C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1\lib\x64 in the VC++ directory---library directory

925ff5203c00ca2c7fb9271abc5967f9.png

Add lib in the linker --- input --- additional dependencies, and add all the .libs in the folder C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1\lib\x64.

0059abd37478dcd87936e44dbf517461.png

Right click on the project---generate dependencies---generate customization---check the corresponding CUDA (if there is no cuda solution in the customization https://blog.csdn.net/a7_aaaaa/article/details/ 122470988)

edcf00618fc60ebc90e37fb23e1f19f8.png

Right click on the .cu file---Properties---Configuration Properties---General---Item Type---CUDA C/C++

ff4b9bdec9b1b9942d09b68696a56fe3.png

Tools---Options---Text Editor---File Extension---Add cu, and cuh

1aa8e18e0026936ddc317be247974166.png

Tools --- Options --- VC++ Project Settings Add ---.cu.cuh

1a86b86bb8e12052786c92027aa1fd2e.png

Test whether the installation is successful

test code

#include<iostream>
using namespace std;
#include"cuda_runtime.h"
#include<cudnn.h>
#include<cuda.h>
#include<device_functions.h>


int main()
{
  int dev = 0;
  cudaDeviceProp devProp;
  cudaGetDeviceProperties(&devProp, dev);
  std::cout << "使用GPU device " << dev << ": " << devProp.name << std::endl;


  cout << "柯西的笔" << endl;
  return 0;
}

If no error is reported and the graphics card type is output normally, the installation is successful. The following articles will explain cuda programming from simple to difficult.

Guess you like

Origin blog.csdn.net/weixin_41202834/article/details/127046274
Recommended