Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eigen: viennalcl::copy GPUVector from EigenMatrix( Dynamic, Dynamic ) #255

Open
chkone opened this issue Jan 30, 2018 · 0 comments
Open

Comments

@chkone
Copy link

chkone commented Jan 30, 2018

Hello,

I propose this fix to support Eigen Matrix with dynamic column to with an assert.

`template<typename NumericT, unsigned int AlignmentV>
void copy( vector<NumericT, AlignmentV> const & gpu_vec,
Eigen::Matrix<NumericT, Eigen::Dynamic, Eigen::Dynamic> & eigen_mat)
{
assert( eigen_mat.cols() == 1 && "copy vector to matrix not a single column: not compatible" );
viennacl::fast_copy( gpu_vec.begin(), gpu_vec.end(), &( eigen_mat[ 0 ] ) );
}

template<typename NumericT, unsigned int AlignmentV, int EigenMapTypeV, typename EigenStrideT>
void copy( vector<NumericT, AlignmentV> const & gpu_vec,
Eigen::Map<Eigen::Matrix<NumericT, Eigen::Dynamic, Eigen::Dynamic>, EigenMapTypeV, EigenStrideT> & eigen_mat )
{
assert( eigen_mat.cols() == 1 && "copy matrix (not a single column) to vector: not compatible" );
viennacl::fast_copy( gpu_vec.begin(), gpu_vec.end(), &( eigen_mat[ 0 ] ) );
}`

And for symmetry:
`template<typename NumericT, unsigned int AlignmentV>
void copy( vector<NumericT, AlignmentV> const & gpu_vec,
Eigen::Matrix<NumericT, Eigen::Dynamic, Eigen::Dynamic> & eigen_mat)
{
assert( eigen_mat.cols() == 1 && "Dimensions not compatible" );
viennacl::fast_copy( gpu_vec.begin(), gpu_vec.end(), &( eigen_mat( 0, 0 ) ) );
}

template<typename NumericT, unsigned int AlignmentV, int EigenMapTypeV, typename EigenStrideT>
void copy( vector<NumericT, AlignmentV> const & gpu_vec,
Eigen::Map<Eigen::Matrix<NumericT, Eigen::Dynamic, Eigen::Dynamic>, EigenMapTypeV, EigenStrideT> & eigen_mat )
{
assert( eigen_mat.cols() == 1 && "Dimensions not compatible" );
viennacl::fast_copy( gpu_vec.begin(), gpu_vec.end(), &( eigen_mat( 0, 0 ) ) );
}`

Cheers this is the version I use locally

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant