af::array::device doesn't work with complex arrays

£可爱£侵袭症+ 提交于 2020-01-17 18:24:12

问题


I just want to "use" a complex af::array for a Cuda kernel. Unfortunately, the transformation which is described in the af documentation (http://arrayfire.org/docs/interop_cuda.htm) doesn't work here:

#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;
}

When I tried to build this I got this error: /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'

It worked with normal doubles. My Cuda-version is V10.1.105. My OS is Ubuntu 19.04. Thanks for your help!


回答1:


We don't have API that accepts thrust::complex<T> type as that would require us to include third-party headers in our header which is not a requirement for all use cases.

That doesn't mean you cannot use complex numbers though. Any complex number representation that is ABI compatible with what we defined (af::cfloat & af::cdouble) in af/complex.h can be passed to our API.

Having said that, I personally don't know if thrust::complex is a simple POD or not. Assuming it is, you should be able to do the following:

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


来源:https://stackoverflow.com/questions/58392739/afarraydevice-doesnt-work-with-complex-arrays

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!