我拼命想用CUDA函数创建一个dll,但我无法使它工作。
我尝试了这里解释的方法:Creating DLL from CUDA using nvcc 编译,但我有以下错误:
nvcc :
warning: __declspec attributes ignored
At line:1 char:1
+ nvcc -o ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (...ributes ignored:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
...\kernel.cu(81): warning: __declspec attributes ignored
...\cudaFFT.h(21): warning: __declspec attributes ignored
.../kernel.cu(81): warning: __declspec attributes ignored
nvcc warning : The 'compute_20', 'sm_20', and 'sm_21' architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning).
kernel.cu
CrÚation de la bibliothÞque C:/Users/alombet/Documents/Visual Studio 2015/Projects/Test/kernel.lib et de l'objet C:/Users/alombet/Documents/Visual Studio 2015/Projects/Test/kernel.exp
tmpxft_00003b9c_00000000-30_kernel.obj : error LNK2019: symbole externe non rÚsolu cufftPlan1d rÚfÚrencÚ dans la fonction AllocateMemoryForFFTs
tmpxft_00003b9c_00000000-30_kernel.obj : error LNK2019: symbole externe non rÚsolu cufftExecD2Z rÚfÚrencÚ dans la fonction ComputeFFT
tmpxft_00003b9c_00000000-30_kernel.obj : error LNK2019: symbole externe non rÚsolu cufftDestroy rÚfÚrencÚ dans la fonction DeAllocateMemoryForFFTs
C:/Users/alombet/Documents/Visual Studio 2015/Projects/Test/kernel.dll : fatal error LNK1120: 3 externes non rÚsolus
首先,__declspec
似乎被忽略了,之后似乎编译器找不到我在cuda库中使用的函数。我真的不习惯手工编译。通常,我依靠IDE来做这件事,因此我完全迷失了。
以下是代码:
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <stdio.h>
#include <iostream>
// includes, system
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
// includes, project
#include <cuda_runtime.h>
#include <cufft.h>
#include <cufftXt.h>
#define LIBRARY_EXPORTS 1
#ifdef LIBRARY_EXPORTS
#define LIBRARY_API __declspec(dllexport)
#else
#define LIBRARY_API __declspec(dllimport)
#endif
#include "cudaFFT.h"
#ifdef __cplusplus
extern "C" {
#endif
int LIBRARY_API __cdecl numberOfGpus()
{
int nDevices;
cudaGetDeviceCount(&nDevices);
return nDevices;
}
cufftDoubleReal *host_input;
cufftDoubleReal *device_input;
cufftDoubleComplex *host_output;
cufftDoubleComplex *device_output;
cufftHandle plan;
cudaError LIBRARY_API __cdecl AllocateMemoryForFFTs(int maxSize, int maxBatch)
{
int width = maxSize; int height = maxBatch;
cudaError err = cudaMallocHost((void **)&host_input, sizeof(cufftDoubleReal) * width * height);
if (err)
return err;
err = cudaMallocHost((void **)&host_output, sizeof(cufftDoubleComplex) * (width / 2 + 1) * height);
if (err)
return err;
err = cudaMalloc((void **)&device_input, sizeof(cufftDoubleReal) * width * height);
if (err)
return err;
err = cudaMalloc((void **)&device_output, sizeof(cufftDoubleComplex) * (width / 2 + 1) * height);
if (err)
return err;
cufftResult res = cufftPlan1d(&plan, width, CUFFT_D2Z, height);
if (res)
return (cudaError)res;
return cudaSuccess;
}
double* LIBRARY_API __cdecl GetInputDataPointer()
{
return host_input;
}
cudaError LIBRARY_API __cdecl ComputeFFT(int size, int batch, double2** result)
{
cudaError err = cudaMemcpy(device_input, host_input, sizeof(cufftDoubleReal) * size * batch, cudaMemcpyHostToDevice);
if (err)
return err;
cufftResult res = cufftExecD2Z(plan, device_input, device_output);
if (res)
return (cudaError)res;
err = cudaMemcpy(host_output, device_output, sizeof(cufftDoubleComplex) * (size / 2 + 1) * batch, cudaMemcpyDeviceToHost);
if (err)
return err;
*result = host_output;
return cudaSuccess;
}
void LIBRARY_API __cdecl DeAllocateMemoryForFFTs()
{
cufftDestroy(plan);
cudaFree(device_input);
cudaFree(device_output);
cudaFreeHost(host_input);
cudaFreeHost(host_output);
}
#ifdef __cplusplus
}
#endif
答案 0 :(得分:-1)
好的,我发现了我的问题,我将解决方案留在这里,以防它可以帮助某人。
1)我从.cu中删除了LIBRARY_API关键字 2)在.h中,我在每个声明的最开始移动了LIBRARY_API。 3)我在vs中更改了项目属性以生成一个dll。 4)让vs编译