Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>find_if</code> is not a good function to find all strings that match. It simply finds the first first element that matches. Take a look at <code>copy_if</code>.</p> <blockquote> <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> </blockquote> <p>You will end up with pointer values that have no meaning on the GPU.</p> <p>In C++, to run on the CPU, you would use <code>std::string</code> to store your strings. So it would be a <code>std::vector&lt;std::string&gt;</code>. Matters are complicated by the fact that there is no device implementation of <code>string</code>, so you can't copy those to the GPU.</p> <p>In addition, many of the STL algorithms (I'm guessing it's the same with <code>thrust</code>) require that the objects that are elements in the vector have working copy constructor and assignment operators. The compiler supplies those for the basic types, but not for an array of char.</p> <p>So, your simple exercise to learn CUDA/Trust may not turn out to be that simple. I <em>think</em> you would need a C++ class that encapsulates a fixed size array of chars and implements device functions for the necessary operators.</p> <p>Also, moving a vector with many items over to device memory in that way is very inefficient because each assignment you do to the <code>device_vector</code> causes a separate copy from host to device memory to be executed in the background. Instead, populate a <code>host_vector</code> and then assign the <code>host_vector</code> to the <code>device_vector</code>. Then, only a single copy from host to device memory is executed.</p> <blockquote> <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> </blockquote> <p>The expression should be <code>count = d_inputVector.begin() - iter;</code> and it should return 0 because the first element in the vector matches the find.</p> <blockquote> <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> </blockquote> <p>After you have created a <code>device_vector</code> with your results, simply assign it to a <code>host_vector</code> to move it to host memory in a single operation.</p> <pre><code>thrust::host_vector&lt;char*&gt; H = D; </code></pre>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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