Skip to content

Commit e31ec98

Browse files
committed
add explicit 'RcppParallelSIMD.h' header
1 parent a336420 commit e31ec98

File tree

10 files changed

+35
-11
lines changed

10 files changed

+35
-11
lines changed

examples/boost-simd-abssum.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// [[Rcpp::depends(RcppParallel)]]
2-
#include <RcppParallel.h>
2+
#include <RcppParallelSIMD.h>
33
#include <Rcpp.h>
44
using namespace Rcpp;
55

examples/boost-simd-accumulate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// [[Rcpp::depends(RcppParallel)]]
2-
#include <RcppParallel.h>
2+
#include <RcppParallelSIMD.h>
33
#include <Rcpp.h>
44
using namespace Rcpp;
55

examples/boost-simd-capabilities.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// [[Rcpp::depends(RcppParallel)]]
2-
#include <RcppParallel.h>
2+
#include <RcppParallelSIMD.h>
33
#include <Rcpp.h>
44
using namespace Rcpp;
55

examples/boost-simd-dot.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// [[Rcpp::depends(RcppParallel)]]
2-
#include <RcppParallel.h>
2+
#include <RcppParallelSIMD.h>
33
#include <Rcpp.h>
44
using namespace Rcpp;
55

examples/boost-simd-hello-world.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// [[Rcpp::depends(RcppParallel)]]
2-
#include <RcppParallel.h>
2+
#include <RcppParallelSIMD.h>
33
#include <Rcpp.h>
44
using namespace Rcpp;
55

examples/boost-simd-transform.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// [[Rcpp::depends(RcppParallel)]]
2-
#include <RcppParallel.h>
2+
#include <RcppParallelSIMD.h>
33
#include <Rcpp.h>
44
using namespace Rcpp;
55

examples/rcpp-simd-transform.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// [[Rcpp::depends(RcppParallel)]]
2-
#include <RcppParallel.h>
2+
#include <RcppParallelSIMD.h>
33
#include <Rcpp.h>
44

55
using namespace Rcpp;

inst/include/RcppParallel.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
// TinyThread implementation
66
#include "RcppParallel/TinyThread.h"
77

8-
// SIMD Wrappers
9-
#include "RcppParallel/SIMD.h"
10-
118
// Use TBB only where it's known to compile and work correctly
129
// (NOTE: Windows TBB is temporarily opt-in for packages for
1310
// compatibility with CRAN packages not previously configured

inst/include/RcppParallelSIMD.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#ifndef __RCPP_PARALLEL_SIMD_H__
2+
#define __RCPP_PARALLEL_SIMD_H__
3+
4+
#include "RcppParallel.h"
5+
#include "RcppParallel/SIMD.h"
6+
7+
#endif /* __RCPP_PARALLEL_SIMD_H__ */

vignettes/simd-operations.Rmd

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ vignette: >
1111

1212
Modern CPU processors are built with new, extended instruction sets that optimize for certain operations. A class of these allow for vectorized operations, called Single Instruction / Multiple Data (SIMD) instructions. Although modern compilers will use these instructions when possible, it is often not possible for the compiler to reason about whether or not a particular block of code can be executed using SIMD instructions.
1313

14-
`Boost.SIMD` is a (proposed) C++ header-only libary, that makes it possible to explicitly request the use of SIMD instructions when possible, while falling back to regular scalar operations if not. `RcppParallel` wraps and exposes this library for use with R vectors.
14+
`Boost.SIMD` is a C++ header-only libary that makes it possible to explicitly request the use of SIMD instructions when possible, while falling back to regular scalar operations if not. `RcppParallel` wraps and exposes this library for use with R vectors.
1515

1616
Here's a quick example of how we might compute the sum of elements in a vector, using `Boost.SIMD`.
1717

@@ -34,6 +34,8 @@ struct add_two {
3434
3535
// [[Rcpp::export]]
3636
double simd_sum(NumericVector x) {
37+
// Use 'simd::accumulate', to sum our vector (by successively adding
38+
// up pairwise components of the vector)
3739
return simd::accumulate(x, 0.0, add_two());
3840
}
3941
```
@@ -52,3 +54,21 @@ Boost.SIMD provides two primary abstractions for the implementation of SIMD algo
5254
- `simd::transform()`, for vector -> vector transformations.
5355

5456
These functions operate like their `std::` counterparts, but expect a functor with a templated call operator. By making the call operator templated, `Boost.SIMD` can generate code using its own optimized SIMD functions when appropriate, and fall back to a default implementation (based on the types provided) when not.
57+
58+
`Boost.SIMD` also provides a number of builtin functions, which can be used effectively with `simd::accumulate()` or `simd::transform()`. For example, let's use SIMD instructions to compute the minimum:
59+
60+
```{r, engine='Rcpp'}
61+
// [[Rcpp::depends(RcppParallel)]]
62+
#include <RcppParallel.h>
63+
#include <Rcpp.h>
64+
65+
#include <boost/simd/arithmetic/functions/min.hpp>
66+
67+
using namespace RcppParallel;
68+
using namespace Rcpp;
69+
70+
// [[Rcpp::export]]
71+
NumericVector simd_min(NumericVector data) {
72+
return simd::transform(data, boost::simd::tag::min_());
73+
}
74+
```

0 commit comments

Comments
 (0)