CUDA--Arrayfire--类型转换

Arrayfire与cucomplex数据之间的转换

转换目的:

  • Arrayfire进行矩阵变换时有C++借口函数方便调用;
  • CUDA提供的cublas函数属于底层一些的函数,使用起来非常不方便;
  • cucomplex数据类型与cdouble中的类型一致,可以方便我们定制自己的kernel而且可以使用Arrayfire中的函数。

cdouble To cucomplex

示例:

#include "cuda_runtime.h"
#include "device_launch_parameters.h"

#include <stdio.h>


#include <arrayfire.h>
#include <af/cuda.h>

#include <iostream>
#include <cmath>
#include <cuComplex.h>

using namespace af;

typedef cuDoubleComplex 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----------
	D2 *d_A = reinterpret_cast<D2*>(a.host<af::cdouble>());
	std::cout << cuCreal(*(d_A+0)) << std::endl;
	a.unlock();
}

int main()
{
    	test();
	return 0;
}


posted @ 2020-09-15 23:14  flyingswallow  阅读(435)  评论(0编辑  收藏  举报