简体   繁体   中英

How to compile a CUDA C++ project

I am writing code to handle communication between two users and require a CUDA implementation of LDPC to quickly check for errors. I have not used CUDA before but I have found a repo on GitHub ( https://github.com/robertwgh/cuLDPC ) which does everything I need. My problem is that I am unable to compile this library, possibly due to it being an old version of CUDA (v4/v5).

I have tried compiling using Visual Studio by adding all of the files to a project, but various errors appear. Some of these seem to be with the code itself but the main issue is a problem with nvcc, given in an MSB3721 error.

In the repo there is a pull request which contains a makefile, so I checked that out but this has not changed the error.

I then tried going into the command prompt and using nvcc manually, but get the error

Cannot find compiler 'cl.exe' in PATH

I have tried solving this by adding

C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.16.27023\\bin\\

to my PATH variable, but I get the same error. I also ran vcvars32.bat and vcvars64.bat after resetting my PATH but this still had no effect both times.

Additionally, I have added cublas.lib, cudart.lib and cusparse.lib to the linker input dependencies in the project properties and I have checked CUDA 10.1 in the build dependencies > build customisations menu.

I am at a loss on where to go now and would very much appreciate some help from people with some more knowledge on the matter.

FWIW that github repo built and ran for me, almost out-of-the-box. The only few hacks needed were:

  • Don't compile cuLDPC_kernel.cu directly, because it's treated like a header file from cuLDPC.cu
  • Comment out some broken timing code, that is non-critical to the functionality. I guess the variables are in the wrong lexical scope. (result of git diff below)

First create a new CUDA-enabled Visual Studio project:

创建新的启用 CUDA 的 Visual Studio 项目

Drag in the "src" directory from the github repo. Then modify file properties for cuLDPC_kernel.cu to not be built.

解决方案资源管理器菜单

Set "Excluded from Build" = Yes

从构建中排除

Code changes required to build:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM