From d0ccb13d091a9010eb8e543aaaf97ed563aab515 Mon Sep 17 00:00:00 2001 From: Philip Hyunsu Cho Date: Wed, 9 Sep 2020 21:21:55 -0700 Subject: [PATCH] Work around a compiler bug in MacOS AppleClang 11 (#6103) * Workaround a compiler bug in MacOS AppleClang * [CI] Run C++ test with MacOS Catalina + AppleClang 11.0.3 * [CI] Migrate cmake_test on MacOS from Travis CI to GitHub Actions * Install OpenMP runtime * [CI] Use CMake to locate lz4 lib --- .github/workflows/main.yml | 24 ++++++++++++++++++++++++ .travis.yml | 7 +++---- plugin/CMakeLists.txt | 7 ++++++- src/common/threading_utils.h | 7 ++++--- tests/travis/run_test.sh | 26 ++++++-------------------- tests/travis/setup.sh | 4 ---- 6 files changed, 43 insertions(+), 32 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 4806692c0..9b1cbcbf7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -11,6 +11,30 @@ env: # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: + gtest-cpu: + name: Test Google C++ test (CPU) + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [macos-10.15] + steps: + - uses: actions/checkout@v2 + with: + submodules: 'true' + - name: Install system packages + run: | + brew install lz4 ninja libomp + - name: Build gtest binary + run: | + mkdir build + cd build + cmake .. -DGOOGLE_TEST=ON -DUSE_OPENMP=ON -DUSE_DMLC_GTEST=ON -DPLUGIN_LZ4=ON -DPLUGIN_DENSE_PARSER=ON -GNinja + ninja -v + - name: Run gtest binary + run: | + cd build + ctest --extra-verbose test-with-jvm: name: Test JVM on OS ${{ matrix.os }} runs-on: ${{ matrix.os }} diff --git a/.travis.yml b/.travis.yml index 5f782ffe4..49f23dd98 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,5 @@ sudo: required -osx_image: xcode10.1 dist: bionic env: @@ -15,16 +14,16 @@ jobs: env: TASK=python_sdist_test - os: osx arch: amd64 + osx_image: xcode10.1 env: TASK=python_test - os: osx arch: amd64 + osx_image: xcode10.1 env: TASK=python_sdist_test - os: osx arch: amd64 + osx_image: xcode10.1 env: TASK=java_test - - os: osx - arch: amd64 - env: TASK=cmake_test - os: linux arch: s390x env: TASK=s390x_test diff --git a/plugin/CMakeLists.txt b/plugin/CMakeLists.txt index 8afce01ff..dc54c2509 100644 --- a/plugin/CMakeLists.txt +++ b/plugin/CMakeLists.txt @@ -1,6 +1,11 @@ if (PLUGIN_LZ4) target_sources(objxgboost PRIVATE ${xgboost_SOURCE_DIR}/plugin/lz4/sparse_page_lz4_format.cc) - target_link_libraries(objxgboost PUBLIC lz4) + find_path(LIBLZ4_INCLUDE_DIR lz4.h) + find_library(LIBLZ4_LIBRARY NAMES lz4) + message(STATUS "LIBLZ4_INCLUDE_DIR = ${LIBLZ4_INCLUDE_DIR}") + message(STATUS "LIBLZ4_LIBRARY = ${LIBLZ4_LIBRARY}") + target_include_directories(objxgboost PUBLIC ${LIBLZ4_INCLUDE_DIR}) + target_link_libraries(objxgboost PUBLIC ${LIBLZ4_LIBRARY}) endif (PLUGIN_LZ4) if (PLUGIN_DENSE_PARSER) diff --git a/src/common/threading_utils.h b/src/common/threading_utils.h index 2c6f5ba11..d6d6d041d 100644 --- a/src/common/threading_utils.h +++ b/src/common/threading_utils.h @@ -109,7 +109,7 @@ class BlockedSpace2d { // Wrapper to implement nested parallelism with simple omp parallel for -template +template void ParallelFor2d(const BlockedSpace2d& space, int nthreads, Func func) { const size_t num_blocks_in_space = space.Size(); nthreads = std::min(nthreads, omp_get_max_threads()); @@ -118,7 +118,8 @@ void ParallelFor2d(const BlockedSpace2d& space, int nthreads, Func func) { dmlc::OMPException omp_exc; #pragma omp parallel num_threads(nthreads) { - omp_exc.Run([&]() { + omp_exc.Run( + [](size_t num_blocks_in_space, const BlockedSpace2d& space, int nthreads, Func func) { size_t tid = omp_get_thread_num(); size_t chunck_size = num_blocks_in_space / nthreads + !!(num_blocks_in_space % nthreads); @@ -128,7 +129,7 @@ void ParallelFor2d(const BlockedSpace2d& space, int nthreads, Func func) { for (auto i = begin; i < end; i++) { func(space.GetFirstDimension(i), space.GetRange(i)); } - }); + }, num_blocks_in_space, space, nthreads, func); } omp_exc.Rethrow(); } diff --git a/tests/travis/run_test.sh b/tests/travis/run_test.sh index 500aa1e57..1db1c73b7 100755 --- a/tests/travis/run_test.sh +++ b/tests/travis/run_test.sh @@ -17,6 +17,12 @@ if [ ${TASK} == "python_sdist_test" ]; then fi if [ ${TASK} == "python_test" ]; then + if grep -n -R '<<<.*>>>\(.*\)' src include | grep --invert "NOLINT"; then + echo 'Do not use raw CUDA execution configuration syntax with <<>>.' \ + 'try `dh::LaunchKernel`' + exit -1 + fi + set -e # Build/test rm -rf build @@ -69,26 +75,6 @@ if [ ${TASK} == "java_test" ]; then mvn -q test fi -if [ ${TASK} == "cmake_test" ]; then - set -e - - if grep -n -R '<<<.*>>>\(.*\)' src include | grep --invert "NOLINT"; then - echo 'Do not use raw CUDA execution configuration syntax with <<>>.' \ - 'try `dh::LaunchKernel`' - exit -1 - fi - - # Build/test - rm -rf build - mkdir build && cd build - PLUGINS="-DPLUGIN_LZ4=ON -DPLUGIN_DENSE_PARSER=ON" - cmake .. -DCMAKE_VERBOSE_MAKEFILE=ON -DGOOGLE_TEST=ON -DUSE_OPENMP=ON -DUSE_DMLC_GTEST=ON ${PLUGINS} - make -j$(nproc) - ./testxgboost - cd .. - rm -rf build -fi - if [ ${TASK} == "s390x_test" ]; then set -e diff --git a/tests/travis/setup.sh b/tests/travis/setup.sh index 0e9f7e8fd..2056bc78f 100755 --- a/tests/travis/setup.sh +++ b/tests/travis/setup.sh @@ -16,10 +16,6 @@ if [ ${TASK} == "python_test" ] || [ ${TASK} == "python_sdist_test" ]; then conda create -n python3 python=3.7 fi -if [ ${TASK} == "cmake_test" ] && [ ${TRAVIS_OS_NAME} == "osx" ]; then - sudo softwareupdate -i "Command Line Tools (macOS High Sierra version 10.13) for Xcode-9.3" -fi - if [ ${TASK} == "s390x_test" ] && [ ${TRAVIS_CPU_ARCH} == "s390x" ]; then sudo snap install cmake --channel=3.17/beta --classic export PATH=/snap/bin:${PATH}