af :: array :: device不适用于复杂的数组 [英] af::array::device doesn't work with complex arrays

查看:134
本文介绍了af :: array :: device不适用于复杂的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

当我尝试构建此文件时,出现此错误:
/ usr / bin / ld:CMakeFiles / test.dir / comp.cu.o:在函数test()中:
tmpxft_00003e39_00000000-5_comp.cudafe1.cpp :(。text + 0x2e6) :对`thrust :: complex< double> * af :: array :: device< thrust :: complex< double>的未定义引用>()const’

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'

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

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

推荐答案

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

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.

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

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.

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

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

这篇关于af :: array :: device不适用于复杂的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆