当前位置:网站首页>CUDA programming-01: build CUDA Programming Environment
CUDA programming-01: build CUDA Programming Environment
2022-07-27 08:52:00 【DeepDriving】
This article was first published on WeChat public 【DeepDriving】, Welcome to your attention .
CUDA brief introduction
CUDA It is a parallel computing platform and programming model developed by NVIDIA , Using it makes it very convenient for programmers to use GPU Powerful computing power . Support CUDA Of GPU There are hundreds of cores , It can run thousands of computing threads at the same time , These kernels have shared resources , Including register file and shared memory , On chip shared memory allows parallel tasks running on these cores to share data without sending data through the system memory bus .CUDA It is developed for the following design purposes :
- Standard programming language (
C/C++) Provide a small group of extensions to support the direct implementation of parallel algorithms , UseCUDA C/C++, Programmers can focus on the task of parallelizing algorithms , Instead of spending time on their implementation . - Support simultaneous use of applications
CPUandGPUPerform heterogeneous computing , The serial part of the application isCPUUp operation , The parallel part is loaded intoGPUUp operation ,CPUandGPUAre independent devices with independent memory space , Allow inCPUandGPUCalculate at the same time without contention for memory resources . therefore ,CUDAIt can be applied incrementally to existing applications .
This article will show you how to Ubuntu 20.04 Install in CUDA development tool , build CUDA Programming environment .
Preparation before installation
Every CUDA The requirements of the version for the operating system and other dependent tool software versions can be seen from the release notes Find , The picture below is CUDA 11.0 Supported by Linux Release and supported versions of related tools , In the installation CUDA Before , We need to do some preparatory work .

1. Verify if there are available GPU
To use CUDA Parallel computation , The first premise is that there is at least one NVIDIA GPU equipment . Want to know whether NVIDIA is installed on your machine GPU, The following commands can be executed in the command line terminal :
lspci | grep -i nvidia
The results obtained on my machine are as follows :
01:00.0 VGA compatible controller: NVIDIA Corporation TU104 [GeForce RTX 2080] (rev a1)
01:00.1 Audio device: NVIDIA Corporation TU104 HD Audio Controller (rev a1)
01:00.2 USB controller: NVIDIA Corporation TU104 USB 3.1 Host Controller (rev a1)
01:00.3 Serial bus controller [0c80]: NVIDIA Corporation TU104 USB Type-C UCSI Controller (rev a1)
06:00.0 VGA compatible controller: NVIDIA Corporation TU104 [GeForce RTX 2080] (rev a1)
06:00.1 Audio device: NVIDIA Corporation TU104 HD Audio Controller (rev a1)
06:00.2 USB controller: NVIDIA Corporation TU104 USB 3.1 Host Controller (rev a1)
06:00.3 Serial bus controller [0c80]: NVIDIA Corporation TU104 USB Type-C UCSI Controller (rev a1)
From the above results, we can know , My machine is equipped with 2 Models are GeForce RTX 2080 Of GPU.
We can also check our own GPU Whether the model supports CUDA Of :https://developer.nvidia.com/cuda-gpus.
2. Verify whether the operating system supports
CUDA Development tools are available only in certain releases Linux operating system , If you want to know which one you use Linux Release version , The following commands can be executed in the command line terminal :
uname -m && cat /etc/*release
stay Ubuntu 20.04 The following results are obtained in the system :
x86_64
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.3 LTS"
NAME="Ubuntu"
VERSION="20.04.3 LTS (Focal Fossa)"
3. verification gcc edition
Use CUDA Development requires gcc compiler ( function CUDA Applications don't need ),gcc Usually as Linux Part of the installation , You can run the following command to view gcc Version of :
gcc --version
stay Ubuntu 20.04 The following results are obtained in the system ,gcc Version is 9.3.0:
gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
4. Verify whether the operating system has the correct kernel header file and development package
CUDA The driver requires that the kernel header file and development package used to run the kernel version be installed when installing the driver , In the installation CUDA It's best to confirm the kernel header file and development package first , The version of the kernel header file can be controlled by the command uname -r To view the , If you want to install the kernel header file and development package corresponding to the current system running kernel , You can execute the following command :
sudo apt-get install linux-headers-$(uname -r)
6. download CUDA Installation package
CUDA The installation package can be downloaded from NVIDIA website http://developer.nvidia.com/cuda-downloads Download . When downloading, you need to select the operating system, computing architecture and other information , You can choose deb File or runfile file Installation , The downloaded installation file contains GPU Drive and CUDA Library file 、 The header file 、 routine 、 Tools etc. .

use runfile Installation
In the previous section CUDA Can pass deb or runfile File to install , This paper introduces the use of runfile File installation method .
1. Delete the old GPU drive
Before installation , If NVIDIA has been installed in our system GPU drive , It is recommended to run the following command first to delete :
sudo apt-get --purge remove nvidia-*
2. Ban Nouveau drive
To install NVIDIA GPU drive , must Disable first Nouveau drive . First, check through the following command Nouveau Whether the driver has been loaded , If the execution command has output , explain Nouveau The driver has not been disabled .
lsmod | grep nouveau
To disable Nouveau drive , First execute the command to create and edit the file
sudo vim /etc/modprobe.d/blacklist-nouveau.conf
Then add the following to the file
blacklist nouveau
options nouveau modeset=0
Then execute the command to regenerate the kernel initramfs Image file
sudo update-initramfs -u
3. install CUDA
Disable in the previous step Nouveau After driving , We need to restart the system and enter command line mode , Then execute the following command to install ( Suppose you downloaded runfile File for cuda_11.0.2_450.51.05_linux.run, That is to say CUDA Version is 11.0,GPU The driver version is 450.51.05):
sudo sh cuda_11.0.2_450.51.05_linux.run
During the installation process, we need to make some settings according to the prompts :
- Terminate the user license agreement (
End User License Agreement), InputacceptThen press enter to proceed to the next step . - install
GPUdrive . - install
CUDAdevelopment tool , You need to set the installation path and whether to create/usr/local/cudaSoft link , You can press enter directly to use the default . - install
CUDAroutine , By default, it will be installed in$(HOME)/NVIDIA_CUDA-11.0_SamplesUnder the path .
Once installed , You need to set some environment variables :
export PATH=/usr/local/cuda-11.0/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-11.0/lib64:$LD_LIBRARY_PATH
export C_INCLUDE_PATH=/usr/local/cuda-11.0/include:$C_INCLUDE_PATH
export CPLUS_INCLUDE_PATH=/usr/local/cuda-11.0/include:$CPLUS_INCLUDE_PATH
If you want to uninstall the installed CUDA, You can execute the following command :
sudo /usr/local/cuda-11.0/bin/cuda-uninstaller
Use CUDA routine
CUDA The version of the development tool can be passed nvcc -V Command to view , Here are my results :
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2020 NVIDIA Corporation
Built on Thu_Jun_11_22:26:38_PDT_2020
Cuda compilation tools, release 11.0, V11.0.194
Build cuda_11.0_bu.TC445_37.28540450_0
nvcc The command is used to compile CUDA Applications , It can call gcc compile C Language program , Call NVIDIA PTX Compiler compilation CUDA Program .
The last section said in CUDA By default, the installation process will be in $(HOME)/NVIDIA_CUDA-11.0_Samples Install... In directory CUDA routine , We can execute commands in this directory make Compile routines , Before compiling, you can execute the following command to install the necessary dependent libraries :
sudo apt-get install g++ freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev libglu1-mesa libglu1-mesa-dev libglfw3 libglfw3-dev
The compiled executable will be copied to the directory bin/x86_64/linux/release Under the folder , We can run some routines to verify CUDA Whether the environment has been built .
function deviceQuery You can query each GPU Details of :

function bandwidthTest You can test the data transmission bandwidth :

Reference material
- 《
CUDA Installation Guide for Linux.pdf》
Welcome to my official account. 【DeepDriving】, I will share computer vision from time to time 、 machine learning 、 Deep learning 、 Driverless and other fields .

边栏推荐
- NIO总结文——一篇读懂NIO整个流程
- NIO this.selector.select()
- Realization of background channel group management function
- JS detects whether the client software is installed
- What are the differences or similarities between "demand fulfillment to settlement" and "purchase to payment"?
- PyTorch自定义CUDA算子教程与运行时间分析
- Make a game by yourself with pyGame 01
- User management - restrictions
- 07_ Service registration and discovery summary
- [I2C reading mpu6050 of Renesas ra6m4 development board]
猜你喜欢
随机推荐
03.使用引号来监听对象嵌套值的变化
新年小目标!代码更规范!
Unity3D 2021软件安装包下载及安装教程
General Administration of Customs: the import of such products is suspended
3311. Longest arithmetic
General view, DRF view review
Can "Gulangyu yuancosmos" become an "upgraded sample" of China's cultural tourism industry
Day5 - Flame restful request response and Sqlalchemy Foundation
Flink1.15源码阅读flink-clients客户端执行流程(阅读较枯燥)
NiO Summary - read and understand the whole NiO process
PyQt5快速开发与实战 4.1 QMainWindow
Sliding conflict of view
Implementation of queue (sequential storage, chain storage)
网络IO总结文
3428. 放苹果
flex:1的原理
Realization of background channel group management function
Tensorflow package tf.keras module construction and training deep learning model
Solve the problem of Chinese garbled code on the jupyter console
【渗透测试工具分享】【dnslog服务器搭建指导】








![[I2C reading mpu6050 of Renesas ra6m4 development board]](/img/1b/c991dd0d798edbb7410a1e16f3a323.png)
