如何在设备中使用主机功能?
例如在下面的函数中,我想返回一个值
__device__ float magnitude2( void ) {
return r * r + i * i;
}
但是这个功能是一个设备功能,我收到了这个错误:
calling a host function from a __device__/__global__ function is not allowed
解决这个问题的最佳方法是什么?
对代码的额外评论:
我想定义这个结构:
struct cuComplex {
float r;
float i;
cuComplex( float a, float b ) : r(a), i(b) {}
__device__ float magnitude2( void ) {
return r * r + i * i;
}
__device__ cuComplex operator*(const cuComplex& a) {
return cuComplex(r*a.r - i*a.i, i*a.r + r*a.i);
}
__device__ cuComplex operator+(const cuComplex& a) {
return cuComplex(r+a.r, i+a.i);
}
};