Skip to content

Commit

Permalink
C++14 for xgboost (#5664)
Browse files Browse the repository at this point in the history
  • Loading branch information
canonizer authored May 21, 2020
1 parent 60511a3 commit 646def5
Show file tree
Hide file tree
Showing 13 changed files with 22 additions and 16 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ endif (USE_OPENMP)
msvc_use_static_runtime()
add_subdirectory(${xgboost_SOURCE_DIR}/dmlc-core)
set_target_properties(dmlc PROPERTIES
CXX_STANDARD 11
CXX_STANDARD 14
CXX_STANDARD_REQUIRED ON
POSITION_INDEPENDENT_CODE ON)
list(APPEND LINKED_LIBRARIES_PRIVATE dmlc)
Expand Down Expand Up @@ -195,7 +195,7 @@ target_link_libraries(runxgboost PRIVATE ${LINKED_LIBRARIES_PRIVATE})
set_target_properties(
runxgboost PROPERTIES
OUTPUT_NAME xgboost
CXX_STANDARD 11
CXX_STANDARD 14
CXX_STANDARD_REQUIRED ON)
#-- End CLI for xgboost

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export CXX = g++
endif
endif

export CFLAGS= -DDMLC_LOG_CUSTOMIZE=1 -std=c++11 -Wall -Wno-unknown-pragmas -Iinclude $(ADD_CFLAGS)
export CFLAGS= -DDMLC_LOG_CUSTOMIZE=1 -std=c++14 -Wall -Wno-unknown-pragmas -Iinclude $(ADD_CFLAGS)
CFLAGS += -I$(DMLC_CORE)/include -I$(RABIT)/include -I$(GTEST_PATH)/include

ifeq ($(TEST_COVER), 1)
Expand Down
2 changes: 1 addition & 1 deletion R-package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ target_include_directories(xgboost-r
${PROJECT_SOURCE_DIR}/rabit/include)
set_target_properties(
xgboost-r PROPERTIES
CXX_STANDARD 11
CXX_STANDARD 14
CXX_STANDARD_REQUIRED ON
POSITION_INDEPENDENT_CODE ON)

Expand Down
2 changes: 1 addition & 1 deletion R-package/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ Imports:
magrittr (>= 1.5),
stringi (>= 0.5.2)
RoxygenNote: 7.1.0
SystemRequirements: GNU make, C++11
SystemRequirements: GNU make, C++14
2 changes: 1 addition & 1 deletion R-package/src/Makevars.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ PKGROOT=../../
ENABLE_STD_THREAD=1
# _*_ mode: Makefile; _*_

CXX_STD = CXX11
CXX_STD = CXX14

XGB_RFLAGS = -DXGBOOST_STRICT_R_MODE=1 -DDMLC_LOG_BEFORE_THROW=0\
-DDMLC_ENABLE_STD_THREAD=$(ENABLE_STD_THREAD) -DDMLC_DISABLE_STDIN=1\
Expand Down
2 changes: 1 addition & 1 deletion R-package/src/Makevars.win
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ xgblib:
cp -r ../../include .
cp -r ../../amalgamation .

CXX_STD = CXX11
CXX_STD = CXX14

XGB_RFLAGS = -DXGBOOST_STRICT_R_MODE=1 -DDMLC_LOG_BEFORE_THROW=0\
-DDMLC_ENABLE_STD_THREAD=$(ENABLE_STD_THREAD) -DDMLC_DISABLE_STDIN=1\
Expand Down
2 changes: 1 addition & 1 deletion jvm-packages/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ target_include_directories(xgboost4j
set_output_directory(xgboost4j ${PROJECT_SOURCE_DIR}/lib)
set_target_properties(
xgboost4j PROPERTIES
CXX_STANDARD 11
CXX_STANDARD 14
CXX_STANDARD_REQUIRED ON)
target_link_libraries(xgboost4j
PRIVATE
Expand Down
5 changes: 3 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ if (USE_CUDA)
$<$<COMPILE_LANGUAGE:CUDA>:--expt-extended-lambda>
$<$<COMPILE_LANGUAGE:CUDA>:--expt-relaxed-constexpr>
$<$<COMPILE_LANGUAGE:CUDA>:-lineinfo>
$<$<AND:$<NOT:$<CXX_COMPILER_ID:MSVC>>,$<COMPILE_LANGUAGE:CUDA>>:--std=c++11>
$<$<COMPILE_LANGUAGE:CUDA>:${GEN_CODE}>)

if (USE_NCCL)
Expand Down Expand Up @@ -45,6 +44,8 @@ if (USE_CUDA)
endif (HIDE_CXX_SYMBOLS)

set_target_properties(objxgboost PROPERTIES
CUDA_STANDARD 14
CUDA_STANDARD_REQUIRED ON
CUDA_SEPARABLE_COMPILATION OFF)
else (USE_CUDA)
add_library(objxgboost OBJECT ${CPU_SOURCES} ${PLUGINS_SOURCES})
Expand All @@ -71,7 +72,7 @@ endif (MSVC)

set_target_properties(objxgboost PROPERTIES
POSITION_INDEPENDENT_CODE ON
CXX_STANDARD 11
CXX_STANDARD 14
CXX_STANDARD_REQUIRED ON)
target_compile_definitions(objxgboost
PRIVATE
Expand Down
2 changes: 2 additions & 0 deletions src/common/column_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class Column {
index_(index),
index_base_(index_base) {}

virtual ~Column() = default;

uint32_t GetGlobalBinIdx(size_t idx) const {
return index_base_ + static_cast<uint32_t>(index_[idx]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/objective/rank_obj.cu
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ class NDCGLambdaWeightComputer
for (size_t i = 0; i < sorted_list.size(); ++i) {
labels[i] = sorted_list[i].label;
}
std::stable_sort(labels.begin(), labels.end(), std::greater<bst_float>());
std::stable_sort(labels.begin(), labels.end(), std::greater<>());
IDCG = ComputeGroupDCGWeight(&labels[0], labels.size());
}
if (IDCG == 0.0) {
Expand Down
2 changes: 1 addition & 1 deletion src/tree/updater_histmaker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ class GlobalProposalHistMaker: public CQHistMaker {
this->work_set_.insert(this->work_set_.end(), this->fsplit_set_.begin(),
this->fsplit_set_.end());
XGBOOST_PARALLEL_SORT(this->work_set_.begin(), this->work_set_.end(),
std::less<decltype(this->work_set_)::value_type>{});
std::less<>{});
this->work_set_.resize(
std::unique(this->work_set_.begin(), this->work_set_.end()) - this->work_set_.begin());

Expand Down
4 changes: 2 additions & 2 deletions tests/ci_build/tidy.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ def convert_nvcc_command_to_clang(self, command):
if pos != -1:
converted_components.append(
'--cuda-gpu-arch=sm_' + capability)
elif components[i].find('--std=c++11') != -1:
converted_components.append('-std=c++11')
elif components[i].find('--std=c++14') != -1:
converted_components.append('-std=c++14')
elif components[i].startswith('-isystem='):
converted_components.extend(components[i].split('='))
else:
Expand Down
7 changes: 5 additions & 2 deletions tests/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ if (USE_CUDA)
$<$<COMPILE_LANGUAGE:CUDA>:--expt-extended-lambda>
$<$<COMPILE_LANGUAGE:CUDA>:--expt-relaxed-constexpr>
$<$<COMPILE_LANGUAGE:CUDA>:-lineinfo>
$<$<AND:$<NOT:$<CXX_COMPILER_ID:MSVC>>,$<COMPILE_LANGUAGE:CUDA>>:--std=c++11>
$<$<COMPILE_LANGUAGE:CUDA>:-Xcompiler=${OpenMP_CXX_FLAGS}>
$<$<COMPILE_LANGUAGE:CUDA>:${GEN_CODE}>)
target_compile_definitions(testxgboost
Expand All @@ -48,6 +47,10 @@ if (USE_CUDA)
$<$<COMPILE_LANGUAGE:CUDA>:-Xcompiler=/utf-8>
)
endif (MSVC)

set_target_properties(testxgboost PROPERTIES
CUDA_STANDARD 14
CUDA_STANDARD_REQUIRED ON)
endif (USE_CUDA)

if (MSVC)
Expand All @@ -64,7 +67,7 @@ target_include_directories(testxgboost
${xgboost_SOURCE_DIR}/rabit/include)
set_target_properties(
testxgboost PROPERTIES
CXX_STANDARD 11
CXX_STANDARD 14
CXX_STANDARD_REQUIRED ON)
target_link_libraries(testxgboost
PRIVATE
Expand Down

0 comments on commit 646def5

Please sign in to comment.