折腾笔记[4]-cuda的hello-world
摘要
在window11上搭建cuda开发环境并编译hello world程序;
关键信息
- 编译器:cuda nvcc 12.4.131
- 平台:windows11
原理简介
cuda简介
CUDA(Compute Unified Device Architecture,统一计算架构)是由英伟达所推出的一种集成技术,向用户提供了可以很优雅地调用GPU进行并行计算的编程接口。
nvcc简介
NVCC(NVIDIA CUDA Compiler)是NVIDIA CUDA编程工具链中的编译器驱动程序,它负责将基于CUDA C/C++编写的代码编译成能够在NVIDIA GPU上执行的程序.
实现
[https://www.cnblogs.com/GeekPoplar/p/14950828.html]
[https://github.com/Tony-Tan/CUDA_Freshman]
- 安装nvcc编译器(cuda平台)
 [https://developer.download.nvidia.com/compute/cuda/]
- 安装Visual Studio平台(主要是需要cl.exe文件)
 安装时选择C++开发用途即可.
 系统环境PATH添加cl.exe的路径:
 C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801\bin\Hostx64\x64
- 编译hello.cu程序
#include<stdio.h>
__global__ void hello_world(void)
{
  printf("GPU: Hello world!\n");
}
int main(int argc,char **argv)
{
  printf("CPU: Hello world!\n");
  hello_world<<<1,10>>>();
  cudaDeviceReset();//if no this line ,it can not output hello world from gpu
  return 0;
}
编译:
nvcc .\hello.cu
# 执行
.\a.exe
效果
| 打印10个hello world | 
|---|
|  | 
 
                    
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号