From 9065d59cc91264c1946fd833e9e4545f0ba4829f Mon Sep 17 00:00:00 2001 From: James Lamb Date: Sun, 1 Nov 2020 04:30:38 +0000 Subject: [PATCH] [R-package] fix MM_PREFETCH and MM_MALLOC checks in configure.ac (#3510) * [R-package] fix MM_PREFETCH and MM_MALLOC checks in configure.ac * update gitignore --- .gitignore | 1 + R-package/configure | 39 +++++++++++++++++++++++++++------------ R-package/configure.ac | 24 ++++++++++++------------ 3 files changed, 40 insertions(+), 24 deletions(-) diff --git a/.gitignore b/.gitignore index f2f2c6c2316f..600a914bf169 100644 --- a/.gitignore +++ b/.gitignore @@ -402,6 +402,7 @@ python-package/lightgbm/VERSION.txt # R build artefacts **/autom4te.cache/ +conftest* R-package/config.status R-package/docs R-package/src/CMakeLists.txt diff --git a/R-package/configure b/R-package/configure index f75666297982..4fbf13f2a3a3 100755 --- a/R-package/configure +++ b/R-package/configure @@ -1694,6 +1694,7 @@ if test -z "${R_HOME}"; then exit 1 fi CC=`"${R_HOME}/bin/R" CMD config CC` +CXX=`"${R_HOME}/bin/R" CMD config CXX11` # LightGBM-specific flags LGB_CPPFLAGS="" @@ -1705,6 +1706,12 @@ LGB_CPPFLAGS="" { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether MM_PREFETCH works" >&5 $as_echo_n "checking whether MM_PREFETCH works... " >&6; } ac_mmprefetch=no +ac_ext=cpp +ac_cpp='$CXXCPP $CPPFLAGS' +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu + cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -1715,11 +1722,9 @@ int main () { - int main() { - int a = 0; - _mm_prefetch(&a, _MM_HINT_NTA); - return 0; - } + int a = 0; + _mm_prefetch(&a, _MM_HINT_NTA); + return 0; ; @@ -1728,7 +1733,7 @@ main () _ACEOF -${CC} -o conftest conftest.c 2>/dev/null && ./conftest && ac_mmprefetch=yes +${CXX} -o conftest conftest.cpp 2>/dev/null && ./conftest && ac_mmprefetch=yes { $as_echo "$as_me:${as_lineno-$LINENO}: result: ${ac_mmprefetch}" >&5 $as_echo "${ac_mmprefetch}" >&6; } if test "${ac_mmprefetch}" = yes; then @@ -1742,6 +1747,12 @@ fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether MM_MALLOC works" >&5 $as_echo_n "checking whether MM_MALLOC works... " >&6; } ac_mm_malloc=no +ac_ext=cpp +ac_cpp='$CXXCPP $CPPFLAGS' +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu + cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ @@ -1752,11 +1763,9 @@ int main () { - int main() { - char *a = (char*)_mm_malloc(8, 16); - _mm_free(a); - return 0; - } + char *a = (char*)_mm_malloc(8, 16); + _mm_free(a); + return 0; ; @@ -1765,7 +1774,7 @@ main () _ACEOF -${CC} -o conftest conftest.c 2>/dev/null && ./conftest && ac_mm_malloc=yes +${CXX} -o conftest conftest.cpp 2>/dev/null && ./conftest && ac_mm_malloc=yes { $as_echo "$as_me:${as_lineno-$LINENO}: result: ${ac_mm_malloc}" >&5 $as_echo "${ac_mm_malloc}" >&6; } if test "${ac_mm_malloc}" = yes; then @@ -1790,6 +1799,12 @@ then ac_pkg_openmp=no { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether OpenMP will work in a package" >&5 $as_echo_n "checking whether OpenMP will work in a package... " >&6; } + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ diff --git a/R-package/configure.ac b/R-package/configure.ac index 4dfa2c43c09a..6887fb279ee7 100644 --- a/R-package/configure.ac +++ b/R-package/configure.ac @@ -21,6 +21,7 @@ if test -z "${R_HOME}"; then exit 1 fi CC=`"${R_HOME}/bin/R" CMD config CC` +CXX=`"${R_HOME}/bin/R" CMD config CXX11` # LightGBM-specific flags LGB_CPPFLAGS="" @@ -31,6 +32,7 @@ LGB_CPPFLAGS="" AC_MSG_CHECKING([whether MM_PREFETCH works]) ac_mmprefetch=no +AC_LANG(C++) AC_LANG_CONFTEST( [ AC_LANG_PROGRAM( @@ -38,16 +40,14 @@ AC_LANG_CONFTEST( #include ]], [[ - int main() { - int a = 0; - _mm_prefetch(&a, _MM_HINT_NTA); - return 0; - } + int a = 0; + _mm_prefetch(&a, _MM_HINT_NTA); + return 0; ]] ) ] ) -${CC} -o conftest conftest.c 2>/dev/null && ./conftest && ac_mmprefetch=yes +${CXX} -o conftest conftest.cpp 2>/dev/null && ./conftest && ac_mmprefetch=yes AC_MSG_RESULT([${ac_mmprefetch}]) if test "${ac_mmprefetch}" = yes; then LGB_CPPFLAGS+=" -DMM_PREFETCH=1" @@ -59,6 +59,7 @@ fi AC_MSG_CHECKING([whether MM_MALLOC works]) ac_mm_malloc=no +AC_LANG(C++) AC_LANG_CONFTEST( [ AC_LANG_PROGRAM( @@ -66,16 +67,14 @@ AC_LANG_CONFTEST( #include ]], [[ - int main() { - char *a = (char*)_mm_malloc(8, 16); - _mm_free(a); - return 0; - } + char *a = (char*)_mm_malloc(8, 16); + _mm_free(a); + return 0; ]] ) ] ) -${CC} -o conftest conftest.c 2>/dev/null && ./conftest && ac_mm_malloc=yes +${CXX} -o conftest conftest.cpp 2>/dev/null && ./conftest && ac_mm_malloc=yes AC_MSG_RESULT([${ac_mm_malloc}]) if test "${ac_mm_malloc}" = yes; then LGB_CPPFLAGS+=" -DMM_MALLOC=1" @@ -98,6 +97,7 @@ then OPENMP_LIB='-lomp' ac_pkg_openmp=no AC_MSG_CHECKING([whether OpenMP will work in a package]) + AC_LANG(C) AC_LANG_CONFTEST( [ AC_LANG_PROGRAM(