准备条件
ECS规格:ecs.gn5i-c16g1.8xlarge
GPU:NVIDIA P4*2
CUDA:11.0.2
Driver:460.91.03
CUDNN:8.0.4
步骤
- 远程登录ECS后自动执行CUDA、Driver和Cudnn安装脚本安装相应版本组件;
- 安装cmake(version > 3.0)、gcc、gdb
sudo yum install epel-release cmake3
sudo yum remove cmake
sudoln-s /usr/bin/cmake3 /usr/bin/cmake
sudo yum install gcc
sudo yum group install "Development Tools"
- 配置Clion Toolschain中的Remote Host SSH
- 添加toolchain到cmake到启动配置
- 配置本地机器目录和Remote主机目录的SFTP映射关系
- 同步代码后建立build目录并配置nvcc路径,执行cmake指令生成makefile
- 生成makefile后执行make即可编译为可执行文件
- 在clion中调试即可,调试代码(来源于https://nicholaspjohnson.com/clioncuda/CLionInstructions.html):
staticvoidrun(std::ostream&); voidrun(std::ostream&printer) { intcount; printer<<"C++ Version: "<<__cplusplus<<std::endl; CUDA_CHECKRESULT(cudaGetDeviceCount(&count)); printer<<std::endl<<"Number of CUDA devices: "<<count<<std::endl; printer<<std::endl<<"-------------------------Device Properties-------------------------"<<std::endl; for (intdev=0; dev<count; ++dev) { printer<<std::endl<<"**************************** GPU "<<dev<<" ****************************"<<std::endl<<std::endl; cudaDevicePropprop{}; CUDA_SAFECALL(cudaGetDeviceProperties, &prop, dev); printer<<"Name: "<<prop.name<<std::endl; printer<<"Global Memory: "<< ((double) prop.totalGlobalMem/1024/1048576) <<" Gb"<<std::endl; printer<<"Shared Memory/block: "<< ((double) prop.sharedMemPerBlock/1024) <<" Kb"<<std::endl; printer<<"Registers/block: "<<prop.regsPerBlock<<std::endl; printer<<"Warp Size: "<<prop.warpSize<<std::endl; printer<<"Max Threads/block: "<<prop.maxThreadsPerBlock<<std::endl; printer<<"Max Block Dimensions: [ "<<prop.maxThreadsDim[0] <<" x "<<prop.maxThreadsDim[1] <<" x "<<prop.maxThreadsDim[2] <<" ]"<<std::endl; printer<<"Max Grid Dimensions: [ "<<prop.maxGridSize[0] <<" x "<<prop.maxGridSize[1] <<" x "<<prop.maxGridSize[2] <<" ]"<<std::endl; printer<<"Constant Memory: "<< ((double) prop.totalConstMem/1024) <<" Kb"<<std::endl; printer<<"Compute Capability: "<<prop.major<<"."<<prop.minor<<std::endl; printer<<"Clock Rate: "<< ((double) prop.clockRate/1000000) <<" GHz"<<std::endl; } } intmain(intargc, char**argv) { if (argc>=2) { std::ofstreamfilestream(argv[1]); if (!filestream) { std::cerr<<"Unable to open file '"<<argv[1] <<"' for writing, exiting!"<<std::endl; return-1; } run(filestream); } else { run(std::cout); } }
调试成功后显示类似如下信息: