Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
425 views
in Technique[技术] by (71.8m points)

c++ - 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!

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...