Skip to content

Commit 8174480

Browse files
committed
make use of Boost.SIMD opt-in
1 parent a556b4c commit 8174480

12 files changed

+22
-66
lines changed

R/build.R

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
#
77
# PKG_CXXFLAGS += $(shell "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" -e "RcppParallel::CxxFlags()")
88
#
9-
CxxFlags <- function(simd = TRUE) {
10-
cat(tbbCxxFlags(simd = simd))
9+
CxxFlags <- function() {
10+
cat(tbbCxxFlags())
1111
}
1212

1313

@@ -40,18 +40,14 @@ inlineCxxPlugin <- function() {
4040
)
4141
}
4242

43-
tbbCxxFlags <- function(simd = TRUE) {
43+
tbbCxxFlags <- function() {
4444

4545
flags <- c()
4646

4747
# opt-in to TBB on Windows
4848
if (Sys.info()['sysname'] == "Windows")
4949
flags <- paste(flags, "-DRCPP_PARALLEL_USE_TBB=1")
5050

51-
# reflect requested use of boost::simd
52-
if (!simd)
53-
flags <- paste(flags, "-DRCPP_PARALLEL_USE_SIMD=0")
54-
5551
flags
5652
}
5753

examples/boost-simd-abssum.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// [[Rcpp::depends(RcppParallel)]]
2+
#define RCPP_PARALLEL_USE_SIMD 1
23
#include <RcppParallel.h>
34
#include <Rcpp.h>
45
using namespace Rcpp;

examples/boost-simd-accumulate.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// [[Rcpp::depends(RcppParallel)]]
2+
#define RCPP_PARALLEL_USE_SIMD 1
23
#include <RcppParallel.h>
34
#include <Rcpp.h>
45
using namespace Rcpp;

examples/boost-simd-capabilities.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// [[Rcpp::depends(RcppParallel)]]
2+
#define RCPP_PARALLEL_USE_SIMD 1
23
#include <RcppParallel.h>
34
#include <Rcpp.h>
45
using namespace Rcpp;

examples/boost-simd-dot.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// [[Rcpp::depends(RcppParallel)]]
2+
#define RCPP_PARALLEL_USE_SIMD 1
23
#include <RcppParallel.h>
34
#include <Rcpp.h>
45
using namespace Rcpp;

examples/boost-simd-hello-world.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// [[Rcpp::depends(RcppParallel)]]
2+
#define RCPP_PARALLEL_USE_SIMD 1
23
#include <RcppParallel.h>
34
#include <Rcpp.h>
45
using namespace Rcpp;

examples/boost-simd-transform.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// [[Rcpp::depends(RcppParallel)]]
2+
#define RCPP_PARALLEL_USE_SIMD 1
23
#include <RcppParallel.h>
34
#include <Rcpp.h>
45
using namespace Rcpp;

examples/rcpp-simd-transform.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// [[Rcpp::depends(RcppParallel)]]
2+
#define RCPP_PARALLEL_USE_SIMD 1
23
#include <RcppParallel.h>
34
#include <Rcpp.h>
45

examples/simd-operations.Rmd

Lines changed: 6 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ using `Boost.SIMD`.
2828

2929
```{r, engine='Rcpp'}
3030
// [[Rcpp::depends(RcppParallel)]]
31+
#define RCPP_PARALLEL_USE_SIMD 1
3132
#include <RcppParallel.h>
3233
#include <Rcpp.h>
3334
@@ -72,49 +73,21 @@ These functions operate like their `std::` counterparts, but expect a functor wi
7273

7374
To build an R package that uses Boost.SIMD you need to make some modifications to the standard RcppParallel configuration:
7475

75-
1. Make sure you call the `CxxFlags` and `LdFlags` functions in `Makevars`
76-
2. Add the **BH** package as a LinkingTo dependency
77-
3. Add C++11 as a SystemRequirement
76+
1. Add the **BH** package as a LinkingTo dependency
77+
2. Add C++11 as a SystemRequirement
7878

79-
Here's the complete recipe for using RcppParallel with Boost.SIMD in an R package:
80-
81-
**DESCRIPTION**
82-
83-
```yaml
84-
Imports: RcppParallel
85-
LinkingTo: RcppParallel, BH
86-
SystemRequirements: GNU make, C++11
87-
```
88-
89-
**NAMESPACE**
90-
91-
```R
92-
importFrom(RcppParallel, RcppParallelLibs)
93-
```
94-
95-
**src/Makevars**
96-
97-
```make
98-
PKG_CXXFLAGS += $(shell ${R_HOME}/bin/Rscript -e "RcppParallel::CxxFlags()")
99-
PKG_LIBS += $(shell ${R_HOME}/bin/Rscript -e "RcppParallel::LdFlags()")
100-
```
101-
102-
**src/Makevars.win**
103-
104-
```make
105-
PKG_CXXFLAGS += $(shell "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" \ -e "RcppParallel::CxxFlags()")
106-
PKG_LIBS += $(shell "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" -e "RcppParallel::LdFlags()")
107-
```
10879

10980
### Platform Compatibility
11081

11182
Note that Boost.SIMD requires a C++11 conformant compiler. This means that packages making use of SIMD features may not compile on platforms with older compilers including Windows and RedHat/CentOS Linux. You can however create a package that takes advantage of Boost.SIMD where available and falls back to a non-SIMD implementation elsewhere.
11283

113-
You can test for the availability of Boost.SIMD on a given platform using the `RCPP_PARALLEL_USE_SIMD` preprocessor variable. If the current compiler doesn't support C++11 (as determined by `__cplusplus <= 199711L`) the variable will be undefined. This allows you to write code like this:
84+
You can test for the availability of Boost.SIMD on a given platform using the `RCPP_PARALLEL_USE_SIMD` preprocessor variable. If the current compiler doesn't support C++11 (as determined by `__cplusplus <= 199711L`) the variable will be undefined (even if you defined it explicitly). This allows you to write code like this:
11485

11586
```cpp
87+
#define RCPP_PARALLEL_USE_SIMD 1
11688
#include <RcppParallel.h>
11789

90+
11891
#if RCPP_PARALLEL_USE_SIMD
11992

12093
#include <boost/simd/sdk/simd/pack.hpp>
@@ -146,28 +119,6 @@ The two `transformDataImpl` functions have the same name, but only one will be c
146119
147120
Note that if you conditionally compile all uses of Boost.SIMD within your package then you can actually drop the `C++11` from `SystemRequirements` (it's no longer required as a result of your fallback implementation).
148121
149-
## Disabling SIMD
150-
151-
If you don't want to use Boost.SIMD at all you can explicitly disable it as follows:
152-
153-
1. For `sourceCpp` you can define `RCPP_PARALLEL_USE_SIMD`:
154-
155-
```cpp
156-
#define RCPP_PARALLEL_USE_SIMD 0
157-
```
158-
159-
2. For R packages you can pass `simd = FALSE` to the CxxFlags function:
160-
161-
```make
162-
PKG_CXXFLAGS += $(shell ${R_HOME}/bin/Rscript -e "RcppParallel::CxxFlags(simd = FALSE)")
163-
```
164-
165-
166-
167-
168-
169-
170-
171122
172123
173124

gallery/simd-variance.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// [[Rcpp::depends(RcppParallel)]]
2+
#define RCPP_PARALLEL_USE_SIMD 1
23
#include <RcppParallel.h>
34
using namespace RcppParallel;
45

0 commit comments

Comments
 (0)