CUDA与C/C++;编译失败 我试图将CUDA代码与我现有的C++应用程序集成。按照某些web端的指示,我需要一个“file.cu”,其中我有一个包装函数,用于在GPU上分配内存并启动内核。我遵循了这个建议,但是,我现在无法编译代码

CUDA与C/C++;编译失败 我试图将CUDA代码与我现有的C++应用程序集成。按照某些web端的指示,我需要一个“file.cu”,其中我有一个包装函数,用于在GPU上分配内存并启动内核。我遵循了这个建议,但是,我现在无法编译代码,cuda,gpu,gpgpu,Cuda,Gpu,Gpgpu,file.cu #include <cuda.h> #include <stdio.h> void preComputeCorrelation_gpu( int * d ) { //I shall write the kernel later once I am confirmed that CUDA code works cudaDeviceProp prop; cudaGetDeviceProperties( &prop, 0 );

file.cu

#include <cuda.h>
#include <stdio.h>

void preComputeCorrelation_gpu( int * d )
{
    //I shall write the kernel later once I am confirmed that CUDA code works
    cudaDeviceProp prop;
    cudaGetDeviceProperties( &prop, 0 );
    printf( "name = %s\n", prop.name );
}

我如何解决这个问题?

< P>这个问题的解决方法是普通的C++代码和CUDA代码的链接需要用LIbcUART完成。所以

编译应该看起来像--


在本例中,cudaWrap.cu包含cuda代码。main_omp.cpp包含main(),还有一些其他应用程序文件也需要编译

你忘了链接libcudart.so。在g++命令的末尾添加-lcudart,它应该可以编译。太好了…现在它可以工作了…谢谢@mkuse:如果您添加您的解决方案作为答案,那么if将非常有用。再过几天,你就可以接受这个问题了,这将使这个问题从没有答案的名单上消失。
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#include <cuda.h>

#define __CUDA_SUPPORT__

#ifdef __CUDA_SUPPORT__
// Defination to be found in "cudaWrap.cu"
extern void preComputeCorrelation_gpu( int * d );
#endif


int main()
{
//code to read d from the file and other initialization
int * d;
.
.

#ifdef __CUDA_SUPPORT__ 
    fprintf( stderr, "GPU Computation starts" );
    // Defination to be found in "cudaWrap.cu"
    preComputeCorrelation_gpu( d ); 
#else
    fprintf( stderr, "CPU Computation starts" );
    preComputeCorrelation( d );
#endif


.
.
//more code

return 0 ;
}
$ nvcc -c cudaWrap.cu <br/>
$ g++ -I /usr/local/cuda-5.0/include -L /usr/local/cuda-5.0/lib -o GA_omp GA_dev_omp.cpp main_omp.cpp data_stats.cpp cudaWrap.o
cudaWrap.o: In function `preComputeCorrelation_gpu(DataSet*)':
tmpxft_00001061_00000000-3_cudaWrap.cudafe1.cpp:(.text+0x2f): undefined reference to `cudaGetDeviceProperties'
cudaWrap.o: In function `__cudaUnregisterBinaryUtil()':
tmpxft_00001061_00000000-3_cudaWrap.cudafe1.cpp:(.text+0x6b): undefined reference to `__cudaUnregisterFatBinary'
cudaWrap.o: In function `__sti____cudaRegisterAll_43_tmpxft_00001061_00000000_6_cudaWrap_cpp1_ii_f8a043c5()':
tmpxft_00001061_00000000-3_cudaWrap.cudafe1.cpp:(.text+0x8c): undefined reference to `__cudaRegisterFatBinary'
collect2: ld returned 1 exit status
$ nvcc -c cudaWrap.cu 
$ g++ -lcudart -I /usr/local/cuda-5.0/include -L /usr/local/cuda-5.0/lib -o GA_omp GA_dev_omp.cpp main_omp.cpp data_stats.cpp cudaWrap.o