Reputation: 89
I am new to Eigen and looking to learn ArrayFire for GPU acceleration. I would like to implement ArrayFire within my existing Eigen code rather than having to re-code all of my functions.
Is there a way to convert from an ArrayFire matrix to an Eigen matrix, and vice-versa?
Thanks!
Upvotes: 1
Views: 173
Reputation: 13295
Untested since I'm just looking at the ArrayFire documentation.
Eigen::MatrixXf hostside = ...;
af::array deviceside(hostside.rows(), hostside.cols(), hostside.data());
It's important that a plain matrix or 2D array is used on Eigen's side (not an Eigen::Ref
or other type of sub-matrix block) since neither the constructor nor any of the copy functions accept a column stride.
deviceside.write(hostside.data(), hostside.size() * sizeof(float));
Eigen::MatrixXf hostside(deviceside.dims(0), deviceside.dims(1));
deviceside.host(hostside.data());
Upvotes: 2