Omer Belal
Omer Belal

Reputation: 112

How to copy host vector to device vector by thrust

I want to copy host std::vector to thrust::device_vector

std::vector<double> p_a(100)
thrust::device_vector<double> d_vec

I want to copy p_a to d_vec

Upvotes: 2

Views: 8238

Answers (1)

Rama
Rama

Reputation: 3305

From the documention,

You can use this constructor:

__host__ thrust::device_vector< T, Alloc >::device_vector   
(   const std::vector< OtherT, OtherAlloc > &   v   )   

Copy constructor copies from an exemplar std::vector.

This constructor receives as parameter the std::vector to copy. So, you can do:

std::vector<double> p_a(100);
thrust::device_vector<double> d_vec(p_a);

And also you can use Copy-assignment:

d_vec = p_a;

Upvotes: 4

Related Questions