当前位置:网站首页>Write the first CUDA program
Write the first CUDA program
2022-07-04 01:45:00 【naibula】
1. Environmental preparation
Make sure cuda The driver has been installed correctly , Execute the following command to view :
nvidia-smi
There are specific graphics card information display , It indicates that the graphics card and its driver are working normally . If it does not work properly, you can refer to course Installation driver .
2. Source code preparation
The following source code output graphics card support CUDA Program information ,cuda_status Used to judge the status of obtaining information ,cuda_status by 0 Show success .
#include <iostream>
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
using namespace std;
int main()
{
int dev = 0;
cudaDeviceProp dev_prop;
cudaError_t cuda_status;
cuda_status = cudaGetDeviceProperties(&dev_prop, dev);
cout << "cuda_status:" << cuda_status << endl;
cout << " Use GPU device " << dev << ": " << dev_prop.name << endl;
cout << "SM The number of :" << dev_prop.multiProcessorCount << endl;
cout << " Shared memory size per thread block :" << dev_prop.sharedMemPerBlock / 1024.0 << " KB" << endl;
cout << " Maximum number of threads per thread block :" << dev_prop.maxThreadsPerBlock << endl;
cout << " Every SM Is the maximum number of threads :" << dev_prop.maxThreadsPerMultiProcessor << endl;
cout << " Every SM The maximum number of thread bundles :" << dev_prop.maxThreadsPerMultiProcessor / 32 << endl;
return 0;
}
3. Compile and run
The above source code is saved in the file GPU_info.cu in , The compile command is as follows :
nvcc GPU_info.cu -o gpu_info
./gpu_info
As shown in the figure below , It is the result of correct execution .
边栏推荐
- File contains vulnerability summary
- All metal crowns - current market situation and future development trend
- 2022 electrician (elementary) examination question bank and electrician (elementary) simulation examination question bank
- Yyds dry goods inventory it's not easy to say I love you | use the minimum web API to upload files
- The latest analysis of hoisting machinery command in 2022 and free examination questions of hoisting machinery command
- IPv6 experiment
- 【.NET+MQTT】. Net6 environment to achieve mqtt communication, as well as bilateral message subscription and publishing code demonstration of server and client
- Winter vacation daily question -- a single element in an ordered array
- Decompile and modify the non source exe or DLL with dnspy
- MySQL -- Introduction and use of single line functions
猜你喜欢
ES6 deletes an attribute in all array objects through map, deconstruction and extension operators
CLP information - how does the digital transformation of credit business change from star to finger?
Maximum likelihood method, likelihood function and log likelihood function
[leetcode daily question] a single element in an ordered array
The contact data on Jerry's management device supports reading and updating operations [articles]
Conditional statements of shell programming
Small program graduation design is based on wechat order takeout small program graduation design opening report function reference
Openbionics robot project introduction | bciduino community finishing
Long article review: entropy, free energy, symmetry and dynamics in the brain
IPv6 experiment
随机推荐
Jerry's watch listens to the message notification of the target third-party software and pushes the message to the device [article]
What are the advantages and disadvantages of data center agents?
Day05 branch and loop (II)
[leetcode daily question] a single element in an ordered array
Description of setting items of Jerry [chapter]
The latest analysis of hoisting machinery command in 2022 and free examination questions of hoisting machinery command
How to use AHAS to ensure the stability of Web services?
Small program graduation project based on wechat video broadcast small program graduation project opening report function reference
G3 boiler water treatment registration examination and G3 boiler water treatment theory examination in 2022
ES6 deletes an attribute in all array objects through map, deconstruction and extension operators
C import Xls data method summary I (upload files and create Workbooks)
Small program graduation design is based on wechat order takeout small program graduation design opening report function reference
AI helps make new breakthroughs in art design plagiarism retrieval! Professor Liu Fang's team paper was employed by ACM mm, a multimedia top-level conference
Cancer biopsy instruments and kits - market status and future development trends
Which insurance products can the elderly buy?
Rearrangement of tag number of cadence OrCAD components and sequence number of schematic page
After listening to the system clear message notification, Jerry informed the device side to delete the message [article]
Applet graduation project is based on wechat classroom laboratory reservation applet graduation project opening report function reference
How to view the computing power of GPU?
Audio resource settings for U3D resource management