折腾笔记[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]

  1. 安装nvcc编译器(cuda平台)
    [https://developer.download.nvidia.com/compute/cuda/]
  2. 安装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
  3. 编译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
posted @   qsBye  阅读(23)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· DeepSeek 开源周回顾「GitHub 热点速览」
历史上的今天:
2023-01-01 MATLAB笔记[5]-蚁群算法
点击右上角即可分享
微信分享提示