cuda thrust: selective copying and resizing results -
i copying items selectively between 2 thrust device arrays using copy_if
follows:
thrust::device_vector<float4> collated = thrust::device_vector<float4> original_vec.size()); thrust::copy_if(original_vec.begin(), original_vec.end(), collated.begin(), is_valid_pt()); collated.shrink_to_fit();
the is_valid_pt
implemented as:
struct is_valid_kpt { __host__ __device__ bool operator()(const float4 x) { return x.w >= 0; } };
now after running code, expecting size of collated
vector less original array still same size.
thrust doesn't resize vectors part of algorithm call. size of vectors going thrust algorithm size of vectors coming out of algorithm.
shrink_to_fit has no impact on vector's size, may impact capacity, has allocation.
if want reduce size of collated
actual number of elements copied it, need use the return value of copy_if
function, compute size, , resize.
something this:
size_t my_size = thrust::copy_if(original_vec.begin(), original_vec.end(), collated.begin(), is_valid_pt()) - collated.begin(); collated.resize(my_size);
Comments
Post a Comment