我正在尝试使用 CUDA 编译器编译此代码:
#include <stdio.h>
#include <stdlib.h>
#include <cuda.h>
#include <curand.h>
int main(void)
{
size_t n = 100;
size_t i;
int *hostData;
unsigned int *devData;
hostData = (int *)calloc(n, sizeof(int));
curandGenerator_t gen;
curandCreateGenerator(&gen, CURAND_RNG_PSEUDO_DEFAULT);
curandSetPseudoRandomGeneratorSeed(gen, 12345);
cudaMalloc((void **)&devData, n * sizeof(int));
curandGenerate(gen, devData, n);
cudaMemcpy(hostData, devData, n * sizeof(int), cudaMemcpyDeviceToHost);
for(i = 0; i < n; i++)
{
printf("%d ", hostData[i]);
}
printf("\n");
curandDestroyGenerator (gen);
cudaFree ( devData );
free ( hostData );
return 0;
}
通过使用此命令:
nvcc -o RNG RNG7.cu
这是我收到的输出:
[root@client2 CUDA]$ nvcc -o RNG7 RNG7.cu
/tmp/tmpxft_00001ed1_00000000-13_RNG7.o: In function `main':
tmpxft_00001ed1_00000000-1_RNG7.cudafe1.cpp:(.text+0x6c): undefined reference to `curandCreateGenerator'
tmpxft_00001ed1_00000000-1_RNG7.cudafe1.cpp:(.text+0x7a): undefined reference to `curandSetPseudoRandomGeneratorSeed'
tmpxft_00001ed1_00000000-1_RNG7.cudafe1.cpp:(.text+0xa0): undefined reference to `curandGenerate'
tmpxft_00001ed1_00000000-1_RNG7.cudafe1.cpp:(.text+0x107): undefined reference to `curandDestroyGenerator'
collect2: ld returned 1 exit status
在另一个讨论中,他们表示这个问题可能与链接器问题或其他问题有关,我需要在编译器命令中手动链接库以包含我的代码中所述的库。
我不知道要做到这一点,有人可以帮忙吗?
谢谢!