Skip to content

Commit 6c48129

Browse files
committed
add TODO + 2 more examples
1 parent 5d556bf commit 6c48129

File tree

3 files changed

+91
-0
lines changed

3 files changed

+91
-0
lines changed

TODO

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Boost.SIMD
2+
==========
3+
4+
- Make it easy for client packages to use Boost.SIMD (plugin? Also need LinkingTo: BH?)
5+
- Enable 'parallelFor', 'parallelReduce'-style calls to SIMD
6+
- See 'Wizard' (http://www.evanmiller.org/) for inspiration
7+
- Need to think about NA (idiom that handled NA)
8+
- Setting of compiler flags for CRAN
9+
- Don't overlap with Armadillo, Eigen
10+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// [[Rcpp::depends(RcppParallel)]]
2+
#include <RcppParallel.h>
3+
#include <Rcpp.h>
4+
using namespace Rcpp;
5+
6+
#include <boost/simd/sdk/simd/extensions/meta/tags.hpp>
7+
#include <boost/simd/sdk/config/is_supported.hpp>
8+
#include <boost/config.hpp>
9+
10+
// Try playing around with the '-march' flag to see what support is detected.
11+
// Note that most modern processors will implement instructions up to SSE3,
12+
// but certain AVX and FMA instructions are only available on newer CPUs.
13+
14+
// [[Rcpp::export]]
15+
void simd_capabilities() {
16+
17+
using boost::simd::is_supported;
18+
using namespace boost::simd::tag;
19+
20+
std::cout << "SIMD Capabilities\n"
21+
<< "=================\n\n";
22+
23+
std::cout << "AVX2: " << is_supported<avx2_>() << "\n"
24+
<< "AVX: " << is_supported<avx_>() << "\n"
25+
<< "FMA4: " << is_supported<fma4_>() << "\n"
26+
<< "FMA3: " << is_supported<fma3_>() << "\n"
27+
<< "SSE4a: " << is_supported<sse4a_>() << "\n"
28+
<< "SSE4_2: " << is_supported<sse4_2_>() << "\n"
29+
<< "SSE4_1: " << is_supported<sse4_1_>() << "\n"
30+
<< "SSE3: " << is_supported<sse3_>() << "\n"
31+
<< "SSE2: " << is_supported<sse2_>() << "\n"
32+
<< "SSE: " << is_supported<sse_>() << "\n";
33+
}
34+
35+
/***R
36+
simd_capabilities()
37+
*/

examples/boost-simd-transform.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// [[Rcpp::depends(RcppParallel)]]
2+
#include <RcppParallel.h>
3+
#include <Rcpp.h>
4+
using namespace Rcpp;
5+
6+
#include <boost/simd/sdk/simd/algorithm.hpp>
7+
8+
struct plus
9+
{
10+
template <class T>
11+
T operator()(const T& lhs, const T& rhs) const
12+
{
13+
return lhs + rhs;
14+
}
15+
};
16+
17+
// [[Rcpp::export]]
18+
NumericVector simd_add(NumericVector lhs,
19+
NumericVector rhs)
20+
{
21+
NumericVector result = no_init(lhs.size());
22+
boost::simd::transform(lhs.begin(), lhs.end(), rhs.begin(), result.begin(), plus());
23+
return result;
24+
}
25+
26+
// [[Rcpp::export]]
27+
NumericVector cpp_add(NumericVector lhs, NumericVector rhs)
28+
{
29+
return lhs + rhs;
30+
}
31+
32+
/***R
33+
n <- 1024 * 1000
34+
lhs <- rnorm(n)
35+
rhs <- rnorm(n)
36+
simd <- simd_add(lhs, rhs)
37+
cpp <- cpp_add(lhs, rhs)
38+
all.equal(simd, cpp)
39+
microbenchmark::microbenchmark(
40+
simd = simd_add(lhs, rhs),
41+
cpp = cpp_add(lhs, rhs),
42+
R = lhs + rhs
43+
)
44+
*/

0 commit comments

Comments
 (0)