[英]How to compile a CUDA C++ project
我正在編寫代碼來處理兩個用戶之間的通信,並需要 LDPC 的 CUDA 實現來快速檢查錯誤。 我之前沒有使用過 CUDA,但我在 GitHub ( https://github.com/robertwgh/cuLDPC ) 上找到了一個 repo,它可以滿足我的所有需求。 我的問題是我無法編譯這個庫,可能是因為它是舊版本的 CUDA (v4/v5)。
我嘗試通過將所有文件添加到項目來使用 Visual Studio 進行編譯,但出現了各種錯誤。 其中一些似乎與代碼本身有關,但主要問題是 nvcc 的問題,在 MSB3721 錯誤中給出。
在 repo 中有一個包含 makefile 的拉取請求,所以我檢查了它,但這並沒有改變錯誤。
然后我嘗試進入命令提示符並手動使用 nvcc,但出現錯誤
在 PATH 中找不到編譯器“cl.exe”
我已經嘗試通過添加來解決這個問題
C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.16.27023\\bin\\
到我的 PATH 變量,但我得到了同樣的錯誤。 重置我的 PATH 后,我還運行了 vcvars32.bat 和 vcvars64.bat 但這兩次仍然沒有效果。
此外,我已將 cublas.lib、cudart.lib 和 cusparse.lib 添加到項目屬性中的鏈接器輸入依賴項,並在構建依賴項 > 構建自定義菜單中檢查了 CUDA 10.1。
我現在不知道該去哪里,非常感謝對此事有更多了解的人的幫助。
FWIW github repo 為我構建並運行,幾乎是開箱即用的。 唯一需要的幾個黑客是:
cuLDPC_kernel.cu
,因為它被視為來自cuLDPC.cu
的頭文件git diff
結果)首先創建一個新的支持 CUDA 的 Visual Studio 項目:
從 github 存儲庫中拖入“src”目錄。 然后修改 cuLDPC_kernel.cu 的文件屬性,使其不被構建。
設置“從構建中排除”= 是
構建所需的代碼更改:
diff --git a/src/cuLDPC.cu b/src/cuLDPC.cu
index f217de4..3c3865c 100755
--- a/src/cuLDPC.cu
+++ b/src/cuLDPC.cu
@@ -448,17 +448,17 @@ int runTest()
#if MEASURE_CPU_TIME == 1
cudaDeviceSynchronize();
- cpu_timer.stop();
- cpu_run_time += cpu_timer.stop_get();
+ //cpu_timer.stop();^M
+ //cpu_run_time += cpu_timer.stop_get();^M
printf ("\n=================================\n\r");
printf ("GPU CUDA Demo\n");
printf ("SNR = %1.1f dB\n", snr);
printf ("# codewords = %d, # streams = %d, CW=%d, MCW=%d\r\n",total_codeword * NSTREAMS, NSTREAMS, CW, MCW);
printf("number of iterations = %1.1f \r\n", aver_iter);
- printf("CPU time: %f ms, for %d simulations.\n", cpu_run_time, MAX_SIM);
- float throughput = (float)CODEWORD_LEN * NSTREAMS * MCW * CW * MAX_SIM / cpu_run_time /1000;
- printf("Throughput = %f Mbps\r\n", (float)CODEWORD_LEN * NSTREAMS * MCW * CW * MAX_SIM / cpu_run_time /1000);
+ //printf("CPU time: %f ms, for %d simulations.\n", cpu_run_time, MAX_SIM);^M
+ //float throughput = (float)CODEWORD_LEN * NSTREAMS * MCW * CW * MAX_SIM / cpu_run_time /1000;^M
+ //printf("Throughput = %f Mbps\r\n", (float)CODEWORD_LEN * NSTREAMS * MCW * CW * MAX_SIM / cpu_run_time /1000); ^M
#endif
#if MEASURE_CUDA_TIME == 1
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.