**第一步:**在一台装有Nvidia显卡和驱动的机器上,用nvidia-smi命令查看显卡所支持cuda版本
第二步: 到Nvidia官网下载CUDA Toolkit并安装,CUDA Toolkit Archive | NVIDIA Developer
安装时按提示下一步即可,安装完成用 nvcc -V 命令检查是否成功
**第三步:**编写HelloWorld
CMakeLists.txt
cpp
cmake_minimum_required(VERSION 3.14)
project(Hello_Cuda)
set(CMAKE_CXX_STANDARD 14)
find_package(CUDA REQUIRED)
cuda_add_executable(Hello main.cu)
cpp
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <stdio.h>
__global__ void hello(void)
{
printf("Hello CUDA!\n");
}
int main()
{
hello <<<1, 1 >>> ();
cudaDeviceSynchronize();
return 0;
}
run: cmake ../ && make