Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
414 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...