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: vignettes/simd-operations.Rmd
+21-1Lines changed: 21 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ vignette: >
11
11
12
12
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.
13
13
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.
15
15
16
16
Here's a quick example of how we might compute the sum of elements in a vector, using `Boost.SIMD`.
17
17
@@ -34,6 +34,8 @@ struct add_two {
34
34
35
35
// [[Rcpp::export]]
36
36
double simd_sum(NumericVector x) {
37
+
// Use 'simd::accumulate', to sum our vector (by successively adding
38
+
// up pairwise components of the vector)
37
39
return simd::accumulate(x, 0.0, add_two());
38
40
}
39
41
```
@@ -52,3 +54,21 @@ Boost.SIMD provides two primary abstractions for the implementation of SIMD algo
52
54
-`simd::transform()`, for vector -> vector transformations.
53
55
54
56
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:
0 commit comments