CUDA调用设备功能从单独的文件(名称混淆?)
CUDA calling device functions from separate files (Name mangling?)
我应该如何正确地做到这一点?下面是代码的简化:
//main.cu
#include "math.cuh"
__global__ void test(float *x, unsigned numElements)
{
int i = blockDim.x * blockIdx.x + threadIdx.x;
if (i < numElements)
{
float array[5] = {1, 2, 3, 4, 5};
copyArray(x + 5*i, array, 5);
}
}
int main(int argc, char **argv)
{
test<<<blocksPerGrid, threadsPerBlock>>>(d_A, numElements);
}
//math.cuh
__device__ void copyArray(float *dest, float *src, unsigned length);
//math.cu
#include "math.cuh"
__device__ void copyArray(float *dest, float *src, size_t length)
{
for (int i = 0; i < length; i++) {
dest[i] = src[i];
}
}
用这个命令编译:
nvcc -rdc=true -arch=sm_20 -o cudaMain main.cu math.cu -Xlinker -framework,OpenGL,-framework,GLUT && ./cudaMain
并得到这个错误:
nvlink error : Undefined reference to '_Z9copyArrayPfS_j' in '/tmp/tmpxft_00000265_00000000-21_main.o'
这显然看起来像一个名称混淆错误,但我试着把外部"C"在各种地方,它没有工作。
函数原型使用unsigned
,而定义使用size_t
。这是原因吗?
相关文章:
- 编译多个C++文件.调用二进制文件以运行代码
- 无法从 SO 文件调用 SO 文件的函数 - C++生成文件
- 如何从另一个文件调用类构造函数?
- 调用函数一次用于动态链接库,一次从可执行文件调用函数
- 当我从头文件和实现文件调用我的函数到我的主文件时,我没有得到任何输出
- 从 Android 中的 C 文件调用C++函数
- 从外部文件C++调用函数
- 如何从多个 cpp 文件调用函数
- 从用户定义的头文件调用函数时出现未定义的引用错误,其实现位于.cpp文件中
- cmake:生成批处理文件调用cl.exe
- 在文件中生成随机数,然后从文件调用它们,然后将它们打印出来
- main.cpp从 .h 文件调用公共虚拟方法
- 如何从 python (py) 文件调用 C++ 函数
- 如何从 cpp 文件调用 setRequestOrientation()
- 调试Visual Studio中可执行文件调用的C 文件
- 可以使用不同的头文件调用相同的函数吗?
- 从 Android 中的原生 c++ 文件调用本机 opencv
- 使用对象文件调用Winapi功能
- 从头文件调用字符串getter函数
- 方法从头文件调用