Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PKG Add Xgboost #2537

Merged
merged 21 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/project/changelog.md
Expand Up @@ -173,7 +173,7 @@ substitutions:
- New packages: opencv-python v4.5.5.64 {pr}`2305`, ffmpeg {pr}`2305`, libwebp {pr}`2305`,
h5py, pkgconfig and libhdf5 {pr}`2411`, bitarray {pr}`2459`, gsw {pr}`2511`, cftime {pr}`2504`,
svgwrite, jsonschema, tskit {pr}`2506`, xarray {pr}`2538`, demes, libgsl, newick,
ruamel, msprime {pr}`2548`, gmpy2 {pr}`2665`.
ruamel, msprime {pr}`2548`, gmpy2 {pr}`2665`, xgboost {pr}`2537`.

## Version 0.20.0

Expand Down
30 changes: 30 additions & 0 deletions packages/xgboost/cmake/TestBigEndian.cmake
@@ -0,0 +1,30 @@
#.rst:
# TestBigEndian
# -------------
#
# The TestBigEndian.cmake module that ships with CMake, which
# checks if the system is big endian or little endian, assumes
# that a binary is produced that will have bytes that correspond to the
# endianness on the target system. Since emscripten produces Javascript, we
# override the default behavior and always return little endian.
#
# ::
#
# TEST_BIG_ENDIAN(VARIABLE)
# VARIABLE - variable to store the result to
#=============================================================================
# Copyright 2002-2009 Kitware, Inc.
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)

function(TEST_BIG_ENDIAN VARIABLE)
set(${VARIABLE} 0 CACHE INTERNAL "Result of TEST_BIG_ENDIAN" FORCE)
endfunction()
26 changes: 26 additions & 0 deletions packages/xgboost/cmake/Toolchain.cmake
@@ -0,0 +1,26 @@
set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like it would be good to share this stuff with other CMake packages? Of course you would be better equipped to know about that than me. Perhaps as a followup to this PR or when you and @henryiii figure out more of the CMake stuff we could move this maybe to the tools directory and add a section to the package building docs about it?

For comparison, in #2378 I put the toolchain file into tools. It's not clear that this is the best place for these files, they might be better off in a folder called toolchains or something.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps as a followup to this PR or when you and @henryiii figure out more of the CMake stuff we could move this maybe to the tools directory and add a section to the package building docs about it?

Yeah, I think I should update our build system to use emscripten's cmake toolchain file directly if possible, instead of making a custom toolchain file for each package. I think it is possible if we set some compiler variables correctly but I haven't checked yet.

set(CMAKE_SKIP_COMPATIBILITY_TESTS 1)
set(CMAKE_SIZEOF_CHAR 1)
set(CMAKE_SIZEOF_UNSIGNED_SHORT 2)
set(CMAKE_SIZEOF_SHORT 2)
set(CMAKE_SIZEOF_INT 4)
set(CMAKE_SIZEOF_UNSIGNED_LONG 4)
set(CMAKE_SIZEOF_UNSIGNED_INT 4)
set(CMAKE_SIZEOF_LONG 4)
set(CMAKE_SIZEOF_VOID_P 4)
set(CMAKE_SIZEOF_FLOAT 4)
set(CMAKE_SIZEOF_DOUBLE 8)
set(CMAKE_C_SIZEOF_DATA_PTR 4)
set(CMAKE_CXX_SIZEOF_DATA_PTR 4)
set(CMAKE_HAVE_LIMITS_H 1)
set(CMAKE_HAVE_UNISTD_H 1)
set(CMAKE_HAVE_PTHREAD_H 1)
set(CMAKE_HAVE_SYS_PRCTL_H 1)
set(CMAKE_WORDS_BIGENDIAN 0)
set(CMAKE_DL_LIBS)
set(CMAKE_RANLIB echo)
set(CMAKE_CROSSCOMPILING TRUE)
set(CMAKE_SYSTEM_PROCESSOR x86)
set(UNIX 1)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
31 changes: 31 additions & 0 deletions packages/xgboost/meta.yaml
@@ -0,0 +1,31 @@
package:
name: xgboost
version: 1.6.0
source:
url: https://files.pythonhosted.org/packages/77/89/92b399140a7688443fc182b54240822c903e906121d63446eb2f84350e99/xgboost-1.6.0.tar.gz
sha256: 9c944c2495cb426b8a365021565755c39ee0b53156cf5e53a4346bdad2e3b734
patches:
- patches/0001-Add-missing-template-type.patch
- patches/0002-Add-library-loading-path.patch
build:
cflags: |
-DDMLC_USE_FOPEN64=0
-DDMLC_ENABLE_STD_THREAD=0
-DDMLC_CXX11_THREAD_LOCAL=0
-DUSE_OPENMP=0
script: |
# export VERBOSE=1
export CMAKE_TOOLCHAIN_FILE=$PYODIDE_ROOT/packages/xgboost/cmake/Toolchain.cmake
requirements:
run:
- numpy
- scipy
- setuptools
test:
imports:
- xgboost
about:
home: https://github.com/dmlc/xgboost
PyPI: https://pypi.org/project/xgboost
summary: XGBoost Python Package
license: Apache-2.0
37 changes: 37 additions & 0 deletions packages/xgboost/patches/0001-Add-missing-template-type.patch
@@ -0,0 +1,37 @@
From 4ac9a00d9e16b0879b4e734a4b604c7ce672894e Mon Sep 17 00:00:00 2001
From: Gyeongjae Choi <def6488@gmail.com>
Date: Mon, 9 May 2022 06:42:07 +0000
Subject: [PATCH 1/2] Add missing template type

ryanking13 marked this conversation as resolved.
Show resolved Hide resolved
TODO: Remove this patch when XGBoost version is updated.
(Upstream PR: https://github.com/dmlc/xgboost/pull/7954)

---
src/common/host_device_vector.cc | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/xgboost/src/common/host_device_vector.cc b/xgboost/src/common/host_device_vector.cc
index 3a4a59db..fc33317b 100644
--- a/xgboost/src/common/host_device_vector.cc
+++ b/xgboost/src/common/host_device_vector.cc
@@ -180,13 +180,16 @@ template class HostDeviceVector<uint64_t>; // bst_row_t
template class HostDeviceVector<uint32_t>; // bst_feature_t
template class HostDeviceVector<RegTree::Segment>;

-#if defined(__APPLE__)
+#if defined(__APPLE__) || defined(__EMSCRIPTEN__)
/*
* On OSX:
*
* typedef unsigned int uint32_t;
* typedef unsigned long long uint64_t;
* typedef unsigned long __darwin_size_t;
+ *
+ * On Emscripten:
+ * typedef unsigned long size_t;
*/
template class HostDeviceVector<std::size_t>;
#endif // defined(__APPLE__)
--
2.35.1

29 changes: 29 additions & 0 deletions packages/xgboost/patches/0002-Add-library-loading-path.patch
@@ -0,0 +1,29 @@
From 54c2a9faeb0b0169172c5ab53367e6092f132c5a Mon Sep 17 00:00:00 2001
From: Gyeongjae Choi <def6488@gmail.com>
Date: Mon, 9 May 2022 12:07:44 +0000
Subject: [PATCH 2/2] Add library loading path

TODO: Remove this patch when XGBoost version is updated.
(Upstream PR: https://github.com/dmlc/xgboost/pull/7954)

---
python-package/xgboost/libpath.py | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/xgboost/libpath.py b/xgboost/libpath.py
index f7a7d9cd..1ab41cbe 100644
--- a/xgboost/libpath.py
+++ b/xgboost/libpath.py
@@ -43,8 +43,7 @@ def find_lib_path() -> List[str]:
# directory here
dll_path.append(os.path.join(curr_path, './windows/Release/'))
dll_path = [os.path.join(p, 'xgboost.dll') for p in dll_path]
- elif sys.platform.startswith('linux') or sys.platform.startswith(
- 'freebsd'):
+ elif sys.platform.startswith(('linux', 'freebsd', 'emscripten')):
dll_path = [os.path.join(p, 'libxgboost.so') for p in dll_path]
elif sys.platform == 'darwin':
dll_path = [os.path.join(p, 'libxgboost.dylib') for p in dll_path]
--
2.35.1