af :: array :: device不适用于复杂的数组

时间:2019-10-15 10:39:16

标签: c++ cuda complex-numbers arrayfire

我只想为Cuda内核“使用”复杂的af :: array。不幸的是,af文档(http://arrayfire.org/docs/interop_cuda.htm)中描述的转换在这里不起作用:

#include <arrayfire.h>
#include <af/cuda.h>
#include <thrust/complex.h>
#include <cuComplex.h>
using namespace af;


typedef thrust::complex<double> D2;

void test(){
    randomEngine en =  randomEngine(); 
    dim4 dims(4, 4);
    array a = randn(dims, c64, en); // array a = randn(dims, f64, en);
    a.eval();
    D2 *d_A = a.device<D2>(); // double *d_A = a.device<double>(); --------error line----------
    a.unlock();
}


int main(){
    test();
    return 0;
}

当我尝试构建它时,出现此错误: /usr/bin/ld: CMakeFiles/test.dir/comp.cu.o: in function `test()': tmpxft_00003e39_00000000-5_comp.cudafe1.cpp:(.text+0x2e6): undefined reference to `thrust::complex<double>* af::array::device<thrust::complex<double> >() const'

它与普通双打一起使用。我的Cuda版本是V10.1.105。我的操作系统是Ubuntu 19.04。 感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

我们没有可以接受thrust::complex<T>类型的API,因为这要求我们在标头中包含第三方标头,而并非所有用例都需要。

但这并不意味着您不能使用复数。任何与我们在af::cfloat中定义的af::cdoubleaf/complex.h兼容的ABI复数表示形式都可以传递给我们的API。

话虽如此,我个人不知道推力::复杂是否是一个简单的POD。假设是,您应该能够执行以下操作:

D2 *d_A = reinterpret_cast<D2*>(a.device<af::cdouble>());