title: CUDA: how to do a matrix multiplication using thrust?
body: <p>I'm new to CUDA and Thrust and I'm trying to implement a matrix multiplication and I want to achieve this by only using the thrust algorithms, because I want to avoid calling a kernel manually.</p>
  
  <p>Is there a way I can achieve this efficiently? (At least without Using 2 nested for loops)</p>
  
  <p>Or do I have to resign and call a CUDA Kernel?</p>
  
  <pre class="lang-cpp prettyprint-override"><code>//My data
  thrust::device_vector&lt;float&gt; data(n*m);
  thrust::device_vector&lt;float&gt; other(m*r);
  thrust::device_vector&lt;float&gt; result(n*r);
  
  // To make indexing faster, not really needed
  transpose(other);
  
  // My current approach
  for (int i = 0; i &lt; n; ++i)
  {
     for (int j = 0; j &lt; r;++j)
     {
         result[i*r+ j] = thrust::inner_product(data.begin()+(i*m), data.begin()+((i+1)*m),other+(j*m), 0.0f);
     }
  }
  </code></pre>