foreword
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.
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.
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)
3. Configure the environment
Add C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1\include in the VC++ directory---include directory
Add C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.1\lib\x64 in the VC++ directory---library directory
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.
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)
Right click on the .cu file---Properties---Configuration Properties---General---Item Type---CUDA C/C++
Tools---Options---Text Editor---File Extension---Add cu, and cuh
Tools --- Options --- VC++ Project Settings Add ---.cu.cuh
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.