title: Moving from Multithreaded CPU program to GPU in C++
body: <p>I created a program that needs to call a function multiple times (lots !!) with different input parameters.
  To speed things up, I multithreaded this like this:</p>
  
  <pre><code>std::vector&lt; MTDPDS* &gt; mtdpds_list;
  boost::thread_group thread_gp;
  for (size_t feat_index = 0; feat_index &lt; feat_parser.getNumberOfFeat(); ++feat_index)
  {
      Feat* feat = feat_parser.getFeat(static_cast&lt;unsigned int&gt;(feat_index));
  
      // != 0 has been added to avoid a warning message during compilation
      bool rotatedFeat = (feat-&gt;flag &amp; 0x00000020) != 0;
      if (!rotatedFeat)
      {
          Desc* desc = new Desc(total_sb, ob.size());
  
          MTDPDS* processing_data = new MTDPDS();
          processing_data-&gt;feat = feat;
          processing_data-&gt;desc = desc;
          processing_data-&gt;img_info = image_info;
          processing_data-&gt;data_op = &amp;data_operations;
          processing_data-&gt;vecs_bb = vecs_bb;
  
          mtdpds_list.push_back(processing_data);
  
          thread_gp.add_thread(new boost::thread(compute_desc, processing_data));
      }
  }
  
  // Wait for all threads to complete
  thread_gp.join_all();
  </code></pre>
  
  <p>This code is a piece of a much larger code, so don't worry too much about variable names, etc...
  The important thing is that I create an object (<code>MTDPDS</code>) for each thread that contains input and output parameters, then spawn a thread calling my processing function <code>compute_desc</code>, and wait for all threads to complete before continuing.</p>
  
  <p>However, my <code>for</code> loop has about 2000+ iterations, meaning that I start about 2000+ threads. I run my code on a cluster, so it's pretty fast, though it still takes too long IMO.</p>
  
  <p>I would like to move this part to the GPU (as it has much more cores), though I'm new to GPU programming.</p>
  
  <ol>
  <li>Is there a way (as I already have a separated computing function) to move this easily without changing the whole code? Like a function that could start threads on GPU in a similar way as boost (like replacing boost thread with GPU thread)?</li>
  <li>Also, my computing function is accessing some data loaded in memory (RAM here), does the GPU requires to have these data loaded into GPU memory, or can it access RAM (and then in this case, which one is faster)?</li>
  <li>And one last question (though I'm pretty sure I know the answer), is it possible to make it hardware independent (so my code could run on Nvidia, ATI, etc...)?</li>
  </ol>
  
  <p>Thank you.</p>