Note that there are some explanatory texts on larger screens.

plurals
  1. POSIMD or not SIMD - cross platform
    primarykey
    data
    text
    <p>I need some idea how to write a C++ cross platform implementation of a few parallelizable problems in a way so I can take advantage of SIMD (SSE, SPU, etc) if available. As well as I want to be able at run time to switch between SIMD and not SIMD.</p> <p><b>How would you suggest me to approach this problem?</b> (Of course I don't want to implement the problem multiple times for all possible options)</p> <p>I can see how this might not be very easy task with C++ but I believe that I'm missing something. So far my idea looks like this... A class cStream will be array of a single field. Using multiple cStreams I can achieve SoA (Structure of Arrays). Then using a few Functors I can fake Lambda function that I need to be executed over the whole cStream.</p> <pre><code>// just for example I'm not expecting this code to compile cStream a; // something like float[1024] cStream b; cStream c; void Foo() { for_each( AssignSIMD(c, MulSIMD(AddSIMD(a, b), a))); } </code></pre> <p>Where for_each will be responsible for incrementing the current pointer of the streams as well as inlining the functors' body with SIMD and without SIMD.</p> <p>something like so:</p> <pre><code>// just for example I'm not expecting this code to compile for_each(functor&lt;T&gt; f) { #ifdef USE_SIMD if (simdEnabled) real_for_each(f&lt;true&gt;()); // true means use SIMD else #endif real_for_each(f&lt;false&gt;()); } </code></pre> <p>Notice that if the SIMD is enabled is checked once and that the loop is around the main functor.</p>
    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.
 

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