boost::numeric::ublas::vector internal data storage pointer

1.4k views Asked by At

I am using 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? I need the internal pointer because I want to copy the vector to CUDA (i.e. 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?

1

There are 1 answers

0
talonmies On

I think that if you instantiate your vector using an unbounded_array as the storage model:

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.