high-level usage of Boost.SIMD

41 views
Skip to first unread message

kevin...@gmail.com

unread,
Jan 15, 2016, 2:48:37 PM1/15/16
to nt2-dev
Hi everyone,

I'm interested in how Boost.SIMD can be used at a high level -- in particular, using `boost::simd::transform()` and `boost::simd::accumulate()` together with the high-level functions that Boost.SIMD defines. The goal is that clients of the wrapper wouldn't need to worry about alignment or what SIMD operations are available, but would just 'automagically' get all the benefits that Boost.SIMD provides when appropriate.

The unit tests in nt2 show an example of how this could be done, with the `sqrt()` function provided by Boost.SIMD: https://github.com/jfalcou/nt2/blob/b9ba2ba9220c89ca389ffdf0072adfcbaf8ead0c/modules/boost/simd/sdk/bench/simd/algorithm/transform.cpp#L33-L38

It seems like the general way these functions could be used is with:

   1) Create a class with a template call operator, using the desired function;
   2) Pass an instance of that functor to the appropriate algorithm.

However, it would 'be nice' if we could directly use these functions, or functors, in the algorithm wrappers provided by Boost.SIMD, e.g. I'd love to just write something like

    boost::simd::accumulate(data.begin(), data.end(), 0.0, boost::simd::sqrt);

Is there another mechanism for handling this -- preferably, without the use of wrapper structs?

It seems like C++14 generic lambdas might be helpful here, e.g.

    boost::simd::accumulate(data.begin(), data.end(), 0.0, [](auto el) { return boost::simd::sqrt(el); })

but unfortunately the version of clang I'm using seems to barf when attempting to run in C++14 mode (perhaps I'm missing a support header, not sure). For reference, the sample program + output is available here: https://gist.github.com/kevinushey/5e800b68fc028302ebbc. Note that I'm using the Boost.SIMD headers as included in RcppParallel; these were generated by building + installing nt2 then copying the headers over.

Any thoughts on a lower-overhead, C++11-ish way of using 'transform()' and 'accumulate()' with the available SIMD functions? Or, what can I do to get a C++14 version with generic lambdas to work?

Thanks!
Kevin

Joel Falcou

unread,
Jan 15, 2016, 2:50:07 PM1/15/16
to nt2...@googlegroups.com
This is being fixed in the new standalone version and yes, auto lambda was our may goal at some point.
I dunno why current code barfs with clang C++14 but it works in the other version. Which version of clang is it ?

We should be pushign actual SIMD function starting this week and I'll update the doc.


--
You received this message because you are subscribed to the Google Groups "nt2-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nt2-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Joel Falcou

unread,
Jan 15, 2016, 2:50:47 PM1/15/16
to nt2...@googlegroups.com
Other point, you shoudl nto be including

#include <boost/simd/arithmetic/include/functions/fast_sqrt.hpp>

but

#include <boost/simd/include/functions/fast_sqrt.hpp>
Reply all
Reply to author
Forward
0 new messages