Note that there are some explanatory texts on larger screens.

plurals
  1. POWhen I use thrust::counting_iterator how can I select the backend for Thrust 1.7 (CUDA 5.5)?
    text
    copied!<p>Thrust automatically selects the GPU backend when I provide an algorithm with iterators from <code>thrust::device_vector</code>, since the vector's data lives on the GPU. However, when I only provide <code>thrust::counting_iterator</code> parameters to an algorithm, how can I select which backend it executes on?</p> <p>In the following invocation of <code>thrust::find</code>, there are no <code>device_vector</code> iterator arguments, so how does Thrust choose which backend (CPU, OMP, TBB, CUDA) to use?</p> <p>How can I control on which backend this algorithm executes without using <code>thrust::device_vector&lt;&gt;</code> in this code?</p> <pre><code>thrust::counting_iterator&lt;uint64_t&gt; first(i); thrust::counting_iterator&lt;uint64_t&gt; last = first + step_size; auto iter = thrust::find( thrust::make_transform_iterator(first, functor), thrust::make_transform_iterator(last, functor), true); </code></pre> <p><strong>UPDATE 23.01.14. MSVS2012, CUDA5.5, Thrust 1.7</strong>:</p> <p><strong>Compile success!</strong> </p> <pre><code>#include &lt;iostream&gt; #include &lt;thrust/iterator/counting_iterator.h&gt; #include &lt;thrust/iterator/transform_iterator.h&gt; #include &lt;thrust/find.h&gt; #include &lt;thrust/functional.h&gt; #include &lt;thrust/execution_policy.h&gt; struct is_odd : public thrust::unary_function&lt;uint64_t, bool&gt; { __host__ __device__ bool operator()(uint64_t const&amp; x) { return x &amp; 1; } }; int main() { thrust::counting_iterator&lt;uint64_t&gt; first(0); thrust::counting_iterator&lt;uint64_t&gt; last = first + 100; auto iter = thrust::find(thrust::device, thrust::make_transform_iterator(first, is_odd()), thrust::make_transform_iterator(last, is_odd()), true); int bbb; std::cin &gt;&gt; bbb; return 0; } </code></pre>
 

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