如何使用Eigen在CUDA内核 [英] How to work with Eigen in CUDA kernels
问题描述
Eigen是一个c ++线性代数库, http://eigen.tuxfamily.org 。
Eigen is a c++ linear algebra library http://eigen.tuxfamily.org.
很容易使用基本数据类型,例如基本的float数组,只需将其复制到设备内存,并将指针传递给cuda内核。但是Eigen矩阵是复杂类型的,所以如何将它复制到设备内存,并让cuda内核读/写?
It's easy to work with basic data types, like basic float arrays, and just copy it to device memory and pass the pointer to cuda kernels. But Eigen matrix are complex type so how to copy it to device memory and let cuda kernels read/write with it?
推荐答案
所有你想要的是通过原始C指针访问 Eigen :: Matrix
的数据,然后可以使用 .data()
函数。默认情况下,系数按顺序存储在列主要顺序的存储器中,或者如果您请求,则按行主要顺序存储:
If all you want is to access the data of an Eigen::Matrix
via a raw C pointer, then you can use the .data()
function. Coefficient are stored sequentially in memory in a column major order by default, or row major if you asked for:
MatrixXd A(10,10);
double *A_data = A.data();
这篇关于如何使用Eigen在CUDA内核的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!