您好,登錄后才能下訂單哦!
本文記錄了CUDA項(xiàng)目配置教程,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
一、新建項(xiàng)目
打開VS2017→ 新建項(xiàng)目→Win32控制臺(tái)應(yīng)用程序 → “空項(xiàng)目”打鉤
二、調(diào)整配置管理器平臺(tái)類型
右鍵項(xiàng)目→ 屬性→ 配置管理器→ 全改為“x64”
三、配置生成屬性
右鍵項(xiàng)目 → 生成依賴項(xiàng)→ 生成自定義→ 勾選“CUDA 9.0XXX”
四、配置基本庫目錄
注意:后續(xù)步驟中出現(xiàn)的目錄地址需取決于你當(dāng)前的CUDA版本及安裝路徑
右鍵項(xiàng)目→屬性→ 配置屬性→ VC++目錄→ 包含目錄,添加以下目錄:
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\include
C:\ProgramData\NVIDIA Corporation\CUDA Samples\v9.0\common\inc
……→ 庫目錄,添加以下目錄:
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\lib\x64
C:\ProgramData\NVIDIA Corporation\CUDA Samples\v9.0\common\lib\x64
五、配置CUDA靜態(tài)鏈接庫路徑
右鍵項(xiàng)目→ 屬性→ 配置屬性→ 鏈接器→ 常規(guī)→ 附加庫目錄,添加以下目錄:
$(CUDA_PATH_V9_0)\lib\$(Platform)
六、選用CUDA靜態(tài)鏈接庫
右鍵項(xiàng)目→ 屬性→ 配置屬性→ 鏈接器→ 輸入→ 附加依賴項(xiàng),添加以下庫:
cublas.lib;cublas_device.lib;cuda.lib;cudadevrt.lib;cudart.lib;cudart_static.lib;cufft.lib;cufftw.lib;curand.lib;cusolver.lib;cusparse.lib;nppc.lib;nppial.lib;nppicc.lib;nppicom.lib;nppidei.lib;nppif.lib;nppig.lib;nppim.lib;nppist.lib;nppisu.lib;nppitc.lib;npps.lib;nvblas.lib;nvcuvid.lib;nvgraph.lib;nvml.lib;nvrtc.lib;OpenCL.lib;
以上為 “第三步” 中添加的庫目錄 “C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v9.0\lib\x64” 中的庫!
注意:
kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)
這些庫為原有!
七、配置源碼文件風(fēng)格
右鍵源文件→ 添加→ 新建項(xiàng)→ 選擇 “CUDA C/C++ File”
右鍵 “xxx.cu" 源文件→ 屬性→ 配置屬性→ 常規(guī)→ 項(xiàng)類型→ 設(shè)置為“CUDA C/C++”
八、測試程序
#include "cuda_runtime.h" #include "device_launch_parameters.h" #include <stdio.h> int main() { int deviceCount; cudaGetDeviceCount(&deviceCount); int dev; for (dev = 0; dev < deviceCount; dev++) { int driver_version(0), runtime_version(0); cudaDeviceProp deviceProp; cudaGetDeviceProperties(&deviceProp, dev); if (dev == 0) if (deviceProp.minor = 9999 && deviceProp.major == 9999) printf("\n"); printf("\nDevice%d:\"%s\"\n", dev, deviceProp.name); cudaDriverGetVersion(&driver_version); printf("CUDA驅(qū)動(dòng)版本: %d.%d\n", driver_version / 1000, (driver_version % 1000) / 10); cudaRuntimeGetVersion(&runtime_version); printf("CUDA運(yùn)行時(shí)版本: %d.%d\n", runtime_version / 1000, (runtime_version % 1000) / 10); printf("設(shè)備計(jì)算能力: %d.%d\n", deviceProp.major, deviceProp.minor); printf("Total amount of Global Memory: %u bytes\n", deviceProp.totalGlobalMem); printf("Number of SMs: %d\n", deviceProp.multiProcessorCount); printf("Total amount of Constant Memory: %u bytes\n", deviceProp.totalConstMem); printf("Total amount of Shared Memory per block: %u bytes\n", deviceProp.sharedMemPerBlock); printf("Total number of registers available per block: %d\n", deviceProp.regsPerBlock); printf("Warp size: %d\n", deviceProp.warpSize); printf("Maximum number of threads per SM: %d\n", deviceProp.maxThreadsPerMultiProcessor); printf("Maximum number of threads per block: %d\n", deviceProp.maxThreadsPerBlock); printf("Maximum size of each dimension of a block: %d x %d x %d\n", deviceProp.maxThreadsDim[0], deviceProp.maxThreadsDim[1], deviceProp.maxThreadsDim[2]); printf("Maximum size of each dimension of a grid: %d x %d x %d\n", deviceProp.maxGridSize[0], deviceProp.maxGridSize[1], deviceProp.maxGridSize[2]); printf("Maximum memory pitch: %u bytes\n", deviceProp.memPitch); printf("Texture alignmemt: %u bytes\n", deviceProp.texturePitchAlignment); printf("Clock rate: %.2f GHz\n", deviceProp.clockRate * 1e-6f); printf("Memory Clock rate: %.0f MHz\n", deviceProp.memoryClockRate * 1e-3f); printf("Memory Bus Width: %d-bit\n", deviceProp.memoryBusWidth); } return 0; }
輸出結(jié)果:
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持億速云。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。