我正在编写一个程序,其中 C++ 文件调用外部“C”函数以启动多个 CUDA 内核函数。在调试代码时,我发现当我进入 extern 函数时,我的一个指针的目标地址发生了变化。
这是有问题的代码(在我的 .cpp 文件中):
cout << "knnIndices before launch: " << knnIndices_d << endl;
launch_kernel(numParticles, dptr /*positions_d*/, velocities_d, embedded_d,
forces_d,
#ifndef USE_ATOMIC_FLOAT
externalForces_d,
#endif
masses_d, knnIndices_d, dt);
cout << "knnIndices after launch complete: " << knnIndices_d << endl;
在 .cu 文件中:
extern "C" void launch_kernel(int numParticles, float4* positions, float4* velocities,
float4* embedded, float4* forces,
#ifndef USE_ATOMIC_FLOAT
int4* externalForces,
#endif
float* masses, int* knnIndices, float dt)
{
std::cout << "knnIndices at launch start: " << knnIndices << std::endl;
输出是:
knnIndices before launch: 0x200420000
knnIndices at launch start: 0x200321400
knnIndices after launch complete: 0x200420000
我已经没有试图解释这种行为的想法,我将不胜感激。谢谢!