我研究了几个小时,
但尚未找到解决以下错误的方法,
Error 1 error LNK2019: unresolved external symbol _curandCreateGenerator@8 referenced in function _GPU_RNG F:\New\Eks\Visual Studio 2013\PEOPLE PROJECTS\RNGTests\CURANDRNGLib\CURANDRNG.cu.obj CURANDRNGLib
Error 2 error LNK2019: unresolved external symbol _curandCreateGeneratorHost@8 referenced in function _CPU_RNG F:\New\Eks\Visual Studio 2013\PEOPLE PROJECTS\RNGTests\CURANDRNGLib\CURANDRNG.cu.obj CURANDRNGLib
Error 3 error LNK2019: unresolved external symbol _curandDestroyGenerator@4 referenced in function _GPU_RNG F:\New\Eks\Visual Studio 2013\PEOPLE PROJECTS\RNGTests\CURANDRNGLib\CURANDRNG.cu.obj CURANDRNGLib
Error 4 error LNK2019: unresolved external symbol _curandSetPseudoRandomGeneratorSeed@12 referenced in function _GPU_RNG F:\New\Eks\Visual Studio 2013\PEOPLE PROJECTS\RNGTests\CURANDRNGLib\CURANDRNG.cu.obj CURANDRNGLib
Error 5 error LNK2019: unresolved external symbol _curandGenerateUniform@12 referenced in function _GPU_RNG F:\New\Eks\Visual Studio 2013\PEOPLE PROJECTS\RNGTests\CURANDRNGLib\CURANDRNG.cu.obj CURANDRNGLib
CURANDRNGLib.cu
#include <cuda.h>
#include <cuda_runtime.h>
#include <curand.h>
#include <curand_kernel.h>
using namespace std;
extern "C" __declspec(dllexport) void __cdecl GPU_RNG(float* , unsigned int , unsigned int);
extern "C" __declspec(dllexport) void __cdecl CPU_RNG(float* , unsigned int , unsigned int);
extern void GPU_RNG(float * h_randomData, unsigned int dataCount, unsigned int mainSeed)
{
float * d_randomData = 0;
//allocate device memory
size_t randomDataSize = dataCount * sizeof(float);
cudaMalloc((void**)&d_randomData, randomDataSize);
curandGenerator_t m_prng;
//Create a new generator
curandCreateGenerator(&m_prng, CURAND_RNG_PSEUDO_DEFAULT);
//Set the generator options
curandSetPseudoRandomGeneratorSeed(m_prng, (unsigned long) mainSeed);
//Generate random numbers
curandGenerateUniform(m_prng, d_randomData, dataCount);
//Copy memory back to the device
cudaMemcpy(h_randomData, d_randomData, randomDataSize, cudaMemcpyDeviceToHost);
//Clean
curandDestroyGenerator(m_prng);
//free device memory
cudaFree(d_randomData);
}
extern void CPU_RNG(float * h_randomData, unsigned int dataCount, unsigned int mainSeed)
{
curandGenerator_t m_prng;
//Create a new generator
curandCreateGeneratorHost(&m_prng,CURAND_RNG_PSEUDO_DEFAULT);
//Set the generator options
curandSetPseudoRandomGeneratorSeed(m_prng, (unsigned long) mainSeed);
//Generate random numbers
curandGenerateUniform(m_prng, h_randomData, dataCount);
//Clean
curandDestroyGenerator(m_prng);
}
我应该添加#include吗? (我不太擅长英语)
答案 0 :(得分:2)
您应该链接curand.lib
- 将其添加到链接器下的属性表中 - &gt;输入 - &gt;附加依赖。
这是打开详细链接器输出的方法:
答案 1 :(得分:1)
我猜你可能已经在Win32平台上开发了代码。只有基本的CUDA API支持,但Win32上没有CURAND库支持。您可以尝试切换到开发64位版本。 (项目 - &gt;属性 - &gt;更改顶部的平台选项)