[R-pkg-devel] using portable simd instructions
jesse koops
je@@e@koop@ @end|ng |rom gm@||@com
Tue Mar 26 10:53:37 CET 2024
Hello R-package-devel,
I recently got inspired by the rcppsimdjson package to try out simd
registers. It works fantastic on my computer but I struggle to find
information on how to make it portable. It doesn't help in this case
that R and Rcpp make including Cpp code so easy that I have never had
to learn about cmake and compiler flags. I would appreciate any help,
including of the type: "go read instructions at ...".
I use RcppArmadillo and Rcpp. I currenlty include the following header:
#include <immintrin.h>
The functions in immintrin that I use are:
_mm256_loadu_pd
_mm256_set1_pd
_mm256_mul_pd
_mm256_fmadd_pd
_mm256_storeu_pd
and I define up to four __m256d registers. From information found
online (not sure where anymore) I constructed the following makevars
file:
CXX_STD = CXX14
PKG_CPPFLAGS = -I../inst/include -mfma -msse4.2 -mavx
PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS)
PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
(I also use openmp, that has always worked fine, I just included all
lines for completeness) Rcheck gives me two notes:
─ using R version 4.3.2 (2023-10-31 ucrt)
─ using platform: x86_64-w64-mingw32 (64-bit)
─ R was compiled by
gcc.exe (GCC) 12.3.0
GNU Fortran (GCC) 12.3.0
❯ checking compilation flags used ... NOTE
Compilation used the following non-portable flag(s):
'-mavx' '-mfma' '-msse4.2'
❯ checking C++ specification ... NOTE
Specified C++14: please drop specification unless essential
But as far as I understand, the flags are necessary, at least in GCC.
How can I make this portable and CRAN-acceptable?
kind regards,
Jesse
More information about the R-package-devel
mailing list