Note that there are some explanatory texts on larger screens.

plurals
  1. PONVidia Thrust Programming with Vectors and Iterators - Basic Questions
    primarykey
    data
    text
    <p>I'm trying to program something simple in order to learn NVidia CUDA/Thrust. I'm a total noob. What I'm trying to do is use a find_if with a custom predicate. My predicate for the moment just returns true on everything so I'm trying to get all input. I want to do a search eventually for strings where I initialize the functor with some string X and then allow the GPU to find all strings that match. </p> <p>I'm confused on several points here. </p> <p>I try to fill up a device_vector full of pointers to my strings and then run it against my MemCmp predicate. </p> <p>First off, does the device_vector "know" to copy my string over from main memory over to GPU memory or does it just copy a pointer value?</p> <p>Secondly, at the line "count = d_inputVector.end() - iter;" it returns a 12 being the number of items in my iterator that is the result from the find_if. Isn't this wrong? If I try iter - d_inputVector.begin() is returns zero which doesn't get my anywhere. </p> <p>Finally, is my method of getting at the results of my little program correct? Am I to copy memory using thrust::copy into a host_vector and would a loop like the one at the end suffice to view the results?</p> <p>Any suggestions are greatly appreciated. Thanks,</p> <p>mj</p> <pre><code>struct MemCmp { __host__ __device__ bool operator()(char *data) { bool rv = false; rv = true; return rv; } }; .... // I initialize a device_vector and then copy pointers from main memory into the device_vector. thrust::device_vector&lt;char*&gt; d_inputVector( itemCount ); for( int i=0; i&lt;itemCount; i++ ){ d_inputVector[i] = inputData[i]; } thrust::device_vector&lt;char*&gt;::iterator iter; iter = thrust::find_if( d_inputVector.begin(), d_inputVector.end(), MemCmp() ); // this is the count that I think is wrong. count = d_inputVector.end() - iter; thrust::host_vector&lt;char*&gt; results( count ); thrust::copy( d_inputVector.begin(), iter, results.begin() ); for( thrust::host_vector&lt;char *&gt;::iterator it = results.begin(); it != results.end(); it++ ){ char* foo = *it; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload