You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: examples/simd-operations.Rmd
+15-25Lines changed: 15 additions & 25 deletions
Original file line number
Diff line number
Diff line change
@@ -11,11 +11,20 @@ vignette: >
11
11
12
12
## SIMD Basics
13
13
14
-
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.
14
+
Modern CPU processors are built with new, extended instruction sets that
15
+
optimize for certain operations. A class of these allow for vectorized
16
+
operations, called Single Instruction / Multiple Data (SIMD) instructions.
17
+
Although modern compilers will use these instructions when possible, they are
18
+
often unable to reason about whether or not a particular block of code can be
19
+
executed using SIMD instructions.
15
20
16
-
`Boost.SIMD` is a C++ header-only library 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.
21
+
`Boost.SIMD` is a C++ header-only library that makes it possible to explicitly
22
+
request the use of SIMD instructions when possible, while falling back to
23
+
regular scalar operations if not. `RcppParallel` wraps and exposes this library
24
+
for use with R vectors.
17
25
18
-
Here's a quick example of how we might compute the sum of elements in a vector, using `Boost.SIMD`.
26
+
Here's a quick example of how we might compute the sum of elements in a vector,
27
+
using `Boost.SIMD`.
19
28
20
29
```{r, engine='Rcpp'}
21
30
// [[Rcpp::depends(RcppParallel)]]
@@ -25,7 +34,7 @@ Here's a quick example of how we might compute the sum of elements in a vector,
25
34
using namespace RcppParallel;
26
35
using namespace Rcpp;
27
36
28
-
// Define a functor -- a C++ class which defines a 'function call'
37
+
// Define a functor -- a C++ class which defines a templated 'function call'
29
38
// operator -- to perform the addition of two pieces of data.
30
39
struct add_two {
31
40
template <typename T>
@@ -36,9 +45,8 @@ struct add_two {
36
45
37
46
// [[Rcpp::export]]
38
47
double simd_sum(NumericVector x) {
39
-
// Use 'simd::accumulate', to sum our vector (by successively adding
@@ -60,24 +68,6 @@ Boost.SIMD provides two primary abstractions for the implementation of SIMD algo
60
68
61
69
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.
62
70
63
-
`Boost.SIMD` also provides a number of built in functions, which can be used effectively with `simd::accumulate()` or `simd::transform()`. For example, let's use SIMD instructions to compute the minimum:
0 commit comments