简体   繁体   English

boost :: numeric :: ublas :: vector内部数据存储指针

[英]boost::numeric::ublas::vector internal data storage pointer

I am using boost::numeric::ublas::vector<double> ( http://www.boost.org/doc/libs/1_41_0/libs/numeric/ublas/doc/vector.htm ). 我正在使用boost::numeric::ublas::vector<double>http://www.boost.org/doc/libs/1_41_0/libs/numeric/ublas/doc/vector.htm )。

How can I get an internal data pointer to the double? 如何获得指向double的内部数据指针? I need the internal pointer because I want to copy the vector to CUDA (ie using cudaMemcpy) . 我需要内部指针,因为我想将向量复制到CUDA (ie using cudaMemcpy) Or is there any elegant way to copy my boost vectors/matrices across? 还是有什么优雅的方法可以复制我的增强向量/矩阵?

I know I can do something like: 我知道我可以做类似的事情:

boost::numeric::ublas::vector<double> vector;
double* ptr = &vector[0];

but is there a more elegant way? 但是还有更优雅的方法吗?

I think that if you instantiate your vector using an unbounded_array as the storage model: 我认为,如果您使用unbounded_array作为存储模型实例化向量:

vector<double, unbounded_array<double,n_elements>> vector;

then you can do something like this: 那么您可以执行以下操作:

cudaMemcpy(device_dest, 
           vector.data().begin(), 
           vector.data().size(), 
           cudaMemcpyHostToDevice);

This works because the unbounded_array iterator is a standard C++ pointer to the type being stored. 这是unbounded_array因为unbounded_array迭代器是指向要存储的类型的标准C ++指针。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM