我正在尝试使用 Google Colab 上的 cuRAND 库运行 CUDA 程序来生成随机数,但遇到链接器问题。
我知道,我们可以在使用 nvcc 编译时使用 -lcurand 来解决这个问题,但据我所知,我们无法访问 colab 中的终端。
我用它来生成 2*N 随机数。
#include <curand_kernel.h>
int status;
curandGenerator_t gen;
status = curandCreateGenerator(&gen, CURAND_RNG_PSEUDO_MRG32K3A);
status |= curandSetPseudoRandomGeneratorSeed(gen, 4294967296ULL^time(NULL));
status |= curandGenerateUniform(gen, randomnums, (2*N));
status |= curandDestroyGenerator(gen);
Run Code Online (Sandbox Code Playgroud)
错误:
/tmp/tmpxft_000006b3_00000000-10_11f5cb12-9471-4d0d-9dcb-659af6ee1dae.o: In function `main':
tmpxft_000006b3_00000000-5_11f5cb12-9471-4d0d-9dcb-659af6ee1dae.cudafe1.cpp:(.text+0xb0): undefined reference to `curandCreateGenerator'
tmpxft_000006b3_00000000-5_11f5cb12-9471-4d0d-9dcb-659af6ee1dae.cudafe1.cpp:(.text+0xdc): undefined reference to `curandSetPseudoRandomGeneratorSeed'
tmpxft_000006b3_00000000-5_11f5cb12-9471-4d0d-9dcb-659af6ee1dae.cudafe1.cpp:(.text+0xfa): undefined reference to `curandGenerateUniform'
tmpxft_000006b3_00000000-5_11f5cb12-9471-4d0d-9dcb-659af6ee1dae.cudafe1.cpp:(.text+0x109): undefined reference to `curandDestroyGenerator'
collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)