简体   繁体   中英

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

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!

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>());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM