Skip to content

Commit 65b70bd

Browse files
authored
Merge branch 'dmlc:release_2.1.0' into release_2.1.0
2 parents ad53d55 + 213ebf7 commit 65b70bd

File tree

17 files changed

+168
-57
lines changed

17 files changed

+168
-57
lines changed

.github/workflows/python_wheels.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ jobs:
2828
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
2929
with:
3030
submodules: 'true'
31+
- name: Set up homebrew
32+
uses: Homebrew/actions/setup-homebrew@68fa6aeb1ccb0596d311f2b34ec74ec21ee68e54
33+
- name: Install libomp
34+
run: brew install libomp
3135
- uses: conda-incubator/setup-miniconda@a4260408e20b96e80095f42ff7f1a15b27dd94ca # v3.0.4
3236
with:
3337
miniforge-variant: Mambaforge

CMakeLists.txt

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -234,28 +234,17 @@ endif()
234234

235235
find_package(Threads REQUIRED)
236236

237+
# -- OpenMP
238+
include(cmake/FindOpenMPMacOS.cmake)
237239
if(USE_OPENMP)
238240
if(APPLE)
239-
find_package(OpenMP)
240-
if(NOT OpenMP_FOUND)
241-
# Try again with extra path info; required for libomp 15+ from Homebrew
242-
execute_process(COMMAND brew --prefix libomp
243-
OUTPUT_VARIABLE HOMEBREW_LIBOMP_PREFIX
244-
OUTPUT_STRIP_TRAILING_WHITESPACE)
245-
set(OpenMP_C_FLAGS
246-
"-Xpreprocessor -fopenmp -I${HOMEBREW_LIBOMP_PREFIX}/include")
247-
set(OpenMP_CXX_FLAGS
248-
"-Xpreprocessor -fopenmp -I${HOMEBREW_LIBOMP_PREFIX}/include")
249-
set(OpenMP_C_LIB_NAMES omp)
250-
set(OpenMP_CXX_LIB_NAMES omp)
251-
set(OpenMP_omp_LIBRARY ${HOMEBREW_LIBOMP_PREFIX}/lib/libomp.dylib)
252-
find_package(OpenMP REQUIRED)
253-
endif()
241+
find_openmp_macos()
254242
else()
255243
find_package(OpenMP REQUIRED)
256244
endif()
257245
endif()
258-
#Add for IBM i
246+
247+
# Add for IBM i
259248
if(${CMAKE_SYSTEM_NAME} MATCHES "OS400")
260249
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
261250
set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> -X64 qc <TARGET> <OBJECTS>")
@@ -381,6 +370,10 @@ if(JVM_BINDINGS)
381370
xgboost_target_defs(xgboost4j)
382371
endif()
383372

373+
if(USE_OPENMP AND APPLE)
374+
patch_openmp_path_macos(xgboost libxgboost)
375+
endif()
376+
384377
if(KEEP_BUILD_ARTIFACTS_IN_BINARY_DIR)
385378
set_output_directory(xgboost ${xgboost_BINARY_DIR}/lib)
386379
else()

R-package/DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Package: xgboost
22
Type: Package
33
Title: Extreme Gradient Boosting
44
Version: 2.1.0.1
5-
Date: 2024-05-30
5+
Date: 2024-06-19
66
Authors@R: c(
77
person("Tianqi", "Chen", role = c("aut"),
88
email = "[email protected]"),

cmake/FindOpenMPMacOS.cmake

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# Find OpenMP library on MacOS
2+
# Automatically handle locating libomp from the Homebrew package manager
3+
4+
# lint_cmake: -package/consistency
5+
6+
macro(find_openmp_macos)
7+
if(NOT APPLE)
8+
message(FATAL_ERROR "${CMAKE_CURRENT_FUNCTION}() must only be used on MacOS")
9+
endif()
10+
find_package(OpenMP)
11+
if(NOT OpenMP_FOUND)
12+
# Try again with extra path info. This step is required for libomp 15+ from Homebrew,
13+
# as libomp 15.0+ from brew is keg-only
14+
# See https://github.com/Homebrew/homebrew-core/issues/112107#issuecomment-1278042927.
15+
execute_process(COMMAND brew --prefix libomp
16+
OUTPUT_VARIABLE HOMEBREW_LIBOMP_PREFIX
17+
OUTPUT_STRIP_TRAILING_WHITESPACE)
18+
set(OpenMP_C_FLAGS
19+
"-Xpreprocessor -fopenmp -I${HOMEBREW_LIBOMP_PREFIX}/include")
20+
set(OpenMP_CXX_FLAGS
21+
"-Xpreprocessor -fopenmp -I${HOMEBREW_LIBOMP_PREFIX}/include")
22+
set(OpenMP_C_LIB_NAMES omp)
23+
set(OpenMP_CXX_LIB_NAMES omp)
24+
set(OpenMP_omp_LIBRARY ${HOMEBREW_LIBOMP_PREFIX}/lib/libomp.dylib)
25+
find_package(OpenMP REQUIRED)
26+
endif()
27+
endmacro()
28+
29+
# Patch libxgboost.dylib so that it depends on @rpath/libomp.dylib instead of
30+
# /opt/homebrew/opt/libomp/lib/libomp.dylib or other hard-coded paths.
31+
# Doing so enables XGBoost to interoperate with multiple kinds of OpenMP
32+
# libraries. See https://github.com/microsoft/LightGBM/pull/6391 for detailed
33+
# explanation. Adapted from https://github.com/microsoft/LightGBM/pull/6391
34+
# by James Lamb.
35+
# MacOS only.
36+
function(patch_openmp_path_macos target target_default_output_name)
37+
if(NOT APPLE)
38+
message(FATAL_ERROR "${CMAKE_CURRENT_FUNCTION}() must only be used on MacOS")
39+
endif()
40+
# Get path to libomp found at build time
41+
get_target_property(
42+
__OpenMP_LIBRARY_LOCATION
43+
OpenMP::OpenMP_CXX
44+
INTERFACE_LINK_LIBRARIES
45+
)
46+
# Get the base name of the OpenMP lib
47+
# Usually: libomp.dylib, libgomp.dylib, or libiomp.dylib
48+
get_filename_component(
49+
__OpenMP_LIBRARY_NAME
50+
${__OpenMP_LIBRARY_LOCATION}
51+
NAME
52+
)
53+
# Get the directory containing the OpenMP lib
54+
get_filename_component(
55+
__OpenMP_LIBRARY_DIR
56+
${__OpenMP_LIBRARY_LOCATION}
57+
DIRECTORY
58+
)
59+
# Get the name of the XGBoost lib, e.g. libxgboost
60+
get_target_property(
61+
__LIBXGBOOST_OUTPUT_NAME
62+
${target}
63+
OUTPUT_NAME
64+
)
65+
if(NOT __LIBXGBOOST_OUTPUT_NAME)
66+
set(__LIBXGBOOST_OUTPUT_NAME "${target_default_output_name}")
67+
endif()
68+
69+
# Get the file name of the XGBoost lib, e.g. libxgboost.dylib
70+
if(CMAKE_SHARED_LIBRARY_SUFFIX_CXX)
71+
set(
72+
__LIBXGBOOST_FILENAME_${target} "${__LIBXGBOOST_OUTPUT_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX_CXX}"
73+
CACHE INTERNAL "Shared library filename ${target}"
74+
)
75+
else()
76+
set(
77+
__LIBXGBOOST_FILENAME_${target} "${__LIBXGBOOST_OUTPUT_NAME}.dylib"
78+
CACHE INTERNAL "Shared library filename ${target}"
79+
)
80+
endif()
81+
82+
message(STATUS "Creating shared lib for target ${target}: ${__LIBXGBOOST_FILENAME_${target}}")
83+
84+
# Override the absolute path to OpenMP with a relative one using @rpath.
85+
#
86+
# This also ensures that if a libomp.dylib has already been loaded, it'll just use that.
87+
if(KEEP_BUILD_ARTIFACTS_IN_BINARY_DIR)
88+
set(__LIB_DIR ${xgboost_BINARY_DIR}/lib)
89+
else()
90+
set(__LIB_DIR ${xgboost_SOURCE_DIR}/lib)
91+
endif()
92+
add_custom_command(
93+
TARGET ${target}
94+
POST_BUILD
95+
COMMAND
96+
install_name_tool
97+
-change
98+
${__OpenMP_LIBRARY_LOCATION}
99+
"@rpath/${__OpenMP_LIBRARY_NAME}"
100+
"${__LIBXGBOOST_FILENAME_${target}}"
101+
WORKING_DIRECTORY ${__LIB_DIR}
102+
)
103+
message(STATUS
104+
"${__LIBXGBOOST_FILENAME_${target}}: "
105+
"Replacing hard-coded OpenMP install_name with '@rpath/${__OpenMP_LIBRARY_NAME}'..."
106+
)
107+
# Add RPATH entries to ensure the loader looks in the following, in the following order:
108+
#
109+
# - /opt/homebrew/opt/libomp/lib (where 'brew install' / 'brew link' puts libomp.dylib)
110+
# - ${__OpenMP_LIBRARY_DIR} (wherever find_package(OpenMP) found OpenMP at build time)
111+
#
112+
# Note: This list will only be used if libomp.dylib isn't already loaded into memory.
113+
# So Conda users will likely use ${CONDA_PREFIX}/libomp.dylib
114+
execute_process(COMMAND brew --prefix libomp
115+
OUTPUT_VARIABLE HOMEBREW_LIBOMP_PREFIX
116+
OUTPUT_STRIP_TRAILING_WHITESPACE)
117+
set_target_properties(
118+
${target}
119+
PROPERTIES
120+
BUILD_WITH_INSTALL_RPATH TRUE
121+
INSTALL_RPATH "${HOMEBREW_LIBOMP_PREFIX}/lib;${__OpenMP_LIBRARY_DIR}"
122+
INSTALL_RPATH_USE_LINK_PATH FALSE
123+
)
124+
endfunction()

cmake/Utils.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ function(xgboost_link_nccl target)
137137
set(xgboost_nccl_flags -DXGBOOST_USE_NCCL=1)
138138
if(USE_DLOPEN_NCCL)
139139
list(APPEND xgboost_nccl_flags -DXGBOOST_USE_DLOPEN_NCCL=1)
140+
target_link_libraries(${target} PRIVATE ${CMAKE_DL_LIBS})
140141
endif()
141142

142143
if(BUILD_STATIC_LIB)

jvm-packages/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,8 @@ target_include_directories(xgboost4j
2525
${PROJECT_SOURCE_DIR}/rabit/include)
2626

2727
set_output_directory(xgboost4j ${PROJECT_SOURCE_DIR}/lib)
28+
29+
# MacOS: Patch libxgboost4j.dylib to use @rpath/libomp.dylib
30+
if(USE_OPENMP AND APPLE)
31+
patch_openmp_path_macos(xgboost4j libxgboost4j)
32+
endif()

jvm-packages/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>ml.dmlc</groupId>
88
<artifactId>xgboost-jvm_2.12</artifactId>
9-
<version>2.1.0-RC1</version>
9+
<version>2.1.0</version>
1010
<packaging>pom</packaging>
1111
<name>XGBoost JVM Package</name>
1212
<description>JVM Package for XGBoost</description>

jvm-packages/xgboost4j-example/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
<parent>
77
<groupId>ml.dmlc</groupId>
88
<artifactId>xgboost-jvm_2.12</artifactId>
9-
<version>2.1.0-RC1</version>
9+
<version>2.1.0</version>
1010
</parent>
1111
<name>xgboost4j-example</name>
1212
<artifactId>xgboost4j-example_2.12</artifactId>
13-
<version>2.1.0-RC1</version>
13+
<version>2.1.0</version>
1414
<packaging>jar</packaging>
1515
<build>
1616
<plugins>

jvm-packages/xgboost4j-flink/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
<parent>
77
<groupId>ml.dmlc</groupId>
88
<artifactId>xgboost-jvm_2.12</artifactId>
9-
<version>2.1.0-RC1</version>
9+
<version>2.1.0</version>
1010
</parent>
1111

1212
<name>xgboost4j-flink</name>
1313
<artifactId>xgboost4j-flink_2.12</artifactId>
14-
<version>2.1.0-RC1</version>
14+
<version>2.1.0</version>
1515
<properties>
1616
<flink-ml.version>2.2.0</flink-ml.version>
1717
</properties>

jvm-packages/xgboost4j-gpu/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
<parent>
77
<groupId>ml.dmlc</groupId>
88
<artifactId>xgboost-jvm_2.12</artifactId>
9-
<version>2.1.0-RC1</version>
9+
<version>2.1.0</version>
1010
</parent>
1111
<artifactId>xgboost4j-gpu_2.12</artifactId>
1212
<name>xgboost4j-gpu</name>
13-
<version>2.1.0-RC1</version>
13+
<version>2.1.0</version>
1414
<packaging>jar</packaging>
1515

1616
<dependencies>

0 commit comments

Comments
 (0)