cuda - Thrust vector with custom data type -


i using thrust library project , ran following problem:

i have struct called box defined as

typedef struct {     int coord[4];     float h; } box; 

and trying copy data device_vector of boxes host_vector of boxes:

thrust::device_vector<box> d_boxes(100); thrust::host_vector<box> h_boxes; thrust::copy(d_boxes.begin(), d_boxes.end(), h_boxes.begin()); 

but throws error

terminate called after throwing instance of 'thrust::system::system_error' what(): invalid argument

if same int instead of box, works fine. unfortunately, documentation not seem have example of vectors of custom data types.

what did miss?

thrust::copy doesn't automatically resize vectors (actually no thrust algorithms do.)

so empty vector, not large enough hold 100 objects:

thrust::host_vector<box> h_boxes; 

try instead:

thrust::host_vector<box> h_boxes(100); 

as pointed out @jaredhoberock, alternate realization be:

thrust::device_vector<box> d_boxes(100); thrust::host_vector<box> h_boxes = d_boxes; 

in case, constructor h_boxes creates size appropriate hold number of elements in d_boxes (as performing device -> host data copy.)


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -