CUDA:错误 C2491:“log1p” : 不允许定义 dllimport 函数
我正在尝试将 CUDA 集成到现有项目中,其中创建了多个库(DLL)。我从一个计算点积的非常简单的内核开始:
// dotProd_kernel.cu
__global__ void dotProd( double* result, double* vec1, double* vec2)
{
int i = threadIdx.x;
result[i] = vec1[i] * vec2[i];
}
该内核由主机脚本调用:
// doProd.cu
#include <cutil_inline.h>
#include <dotProd_kernel.cu>
extern "C" double CUDA_dot(THTensor *vec1, THTensor *vec2);
double CUDA_dot(THTensor *vec1, THTensor *vec2)
{
// [content skipped]
// execute the kernel
dotProd<<< 1, nbThreads >>>(device_vec1, device_vec2, device_result_array);
// [content skipped]
return sum;
}
我使用 cmake 生成构建文件,并使用 Visual Studio 2008 Pro 来编译它。如果我只是使用带有 foobar 函数且不调用内核的 .cu 文件,则它执行得很好。但是使用上面的代码,我收到以下错误:
c:\cuda\include\math_functions.h(3459) : error C2491: 'log1p' : definition of dllimport function not allowed
调用 CUDA 代码的结果代码被导出为 DLL。这是问题所在吗?
I am tryint to integrate CUDA in an existing project, in which several libs (DLLs) are created. I started with a very simple kernel that computes a dot product :
// dotProd_kernel.cu
__global__ void dotProd( double* result, double* vec1, double* vec2)
{
int i = threadIdx.x;
result[i] = vec1[i] * vec2[i];
}
This kernel is called by a host script :
// doProd.cu
#include <cutil_inline.h>
#include <dotProd_kernel.cu>
extern "C" double CUDA_dot(THTensor *vec1, THTensor *vec2);
double CUDA_dot(THTensor *vec1, THTensor *vec2)
{
// [content skipped]
// execute the kernel
dotProd<<< 1, nbThreads >>>(device_vec1, device_vec2, device_result_array);
// [content skipped]
return sum;
}
I generate build files using cmake, and use Visual Studio 2008 Pro to compile it. If I simply use a .cu file with a foobar function that calls no kernel, it executes fine. But with the above code, I get the following error :
c:\cuda\include\math_functions.h(3459) : error C2491: 'log1p' : definition of dllimport function not allowed
The resulting code that calls the CUDA code is exported as a DLL. Is this the problem ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我什至不知道 CUDA 是什么,但我会查看有编译器错误的代码(math_functions.h)并查看第 3459 行,看看它试图做什么并从那里开始。这似乎与您在发布的代码中尝试执行的操作无关。
I don't even know what CUDA is, but I would look at the code that had the compiler error (math_functions.h) and look at line 3459 and see what it's trying to do and start from there. It seems unrelated to what you are trying to do in the code you posted.
顺便说一句,如果您使用 CUDA 2.3(或者最好是 3.0),那么您应该能够摆脱外部“C”。
Incidentally, if you're using CUDA 2.3 (or, preferably 3.0) then you should be able to get rid of the extern "C".
实际上,CUDA 库定义了 log1p 函数,因此这是我尝试添加 CUDA 的代码中一个模糊的部分。于是,两人之间就产生了某种冲突。我只是在代码中重命名了该函数,它就起作用了!
Actually, the CUDA library defines the log1p function, and so was an obscure part of the code I'm trying to add CUDA to. Thus, there was some kind of conflict between the two. I simply renamed the function in my code, and it worked !