-
Notifications
You must be signed in to change notification settings - Fork 652
[LightGBM] build v4.3.0 with OpenCL/CUDA support #8593
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
Changes from 5 commits
36e5fb7
89cc382
0e0932c
7c91295
16681bf
4fb837d
1765d5b
70a89db
457202b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,18 @@ | ||
| # Note that this script can accept some limited command-line arguments, run | ||
| # `julia build_tarballs.jl --help` to see a usage message. | ||
| using BinaryBuilder, Pkg | ||
| using Base.BinaryPlatforms: arch, tags | ||
|
|
||
| name = "LightGBM" | ||
| version = v"3.3.5" | ||
| version = v"4.3.0" | ||
|
|
||
| const YGGDRASIL_DIR = "../.." | ||
| include(joinpath(YGGDRASIL_DIR, "fancy_toys.jl")) | ||
| include(joinpath(YGGDRASIL_DIR, "platforms", "cuda.jl")) | ||
|
|
||
| # Collection of sources required to complete build | ||
| sources = [ | ||
| GitSource("https://github.com/microsoft/LightGBM.git", "ca035b2ee0c2be85832435917b1e0c8301d2e0e0"), | ||
| GitSource("https://github.com/microsoft/LightGBM.git", "252828fd86627d7405021c3377534d6a8239dd69"), | ||
| DirectorySource("./bundled"), | ||
| ] | ||
|
|
||
|
|
@@ -17,27 +22,46 @@ cd $WORKSPACE/srcdir/LightGBM | |
| git submodule update --init --depth=1 | ||
| git submodule update --checkout --depth=1 | ||
|
|
||
|
|
||
| if [[ $target == *"apple-darwin"* ]]; then | ||
| cmake_extra_args="-DAPPLE=1 -DAPPLE_OUTPUT_DYLIB=1" | ||
| fi | ||
| for p in $WORKSPACE/srcdir/patches/*.patch; do | ||
| atomic_patch -p1 "${p}" | ||
| done | ||
giordano marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| FLAGS=() | ||
| cmake_extra_args="" | ||
|
|
||
| if [[ "${bb_full_target}" == *"apple-darwin"* ]]; then | ||
| cmake_extra_args+="-DAPPLE=1 -DAPPLE_OUTPUT_DYLIB=1 " | ||
| fi | ||
|
|
||
| if [[ "${target}" == *-mingw* ]]; then | ||
| # Parches windows | ||
| for p in $WORKSPACE/srcdir/patches/windows/*.patch; do | ||
| atomic_patch -p1 "${p}" | ||
| done | ||
| cmake_extra_args="-DWIN32=1 -DMINGW=1" | ||
| if [[ "${bb_full_target}" == *-mingw* ]]; then | ||
| cmake_extra_args+="-DWIN32=1 -DMINGW=1 " | ||
| FLAGS+=(LDFLAGS="-no-undefined") | ||
| fi | ||
|
|
||
| cmake \ | ||
| if [[ "${bb_full_target}" == *-linux* ]]; then | ||
| cmake_extra_args+="-DUSE_GPU=1 " | ||
| fi | ||
|
|
||
| if [[ ("${bb_full_target}" == *-cuda*) && ("${bb_full_target}" != *-cuda+none*) ]]; then | ||
| # nvcc writes to /tmp, which is a small tmpfs in our sandbox. | ||
| # make it use the workspace instead | ||
| export TMPDIR=${WORKSPACE}/tmpdir | ||
| mkdir ${TMPDIR} | ||
| export CUDA_PATH=${WORKSPACE}/destdir/cuda | ||
| export PATH=$PATH:$CUDA_PATH/bin/ | ||
|
|
||
| ln -s $CUDA_PATH/lib $CUDA_PATH/lib64 | ||
|
||
|
|
||
| cmake_extra_args+="\ | ||
| -DUSE_CUDA=1 " | ||
| fi | ||
|
|
||
| cmake . \ | ||
| -DCMAKE_INSTALL_PREFIX=$prefix\ | ||
| -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TARGET_TOOLCHAIN} \ | ||
| -DCMAKE_BUILD_TYPE=Release \ | ||
| $cmake_extra_args | ||
|
|
||
| make -j${nproc} "${FLAGS[@]}" | ||
| make install | ||
| install_license LICENSE | ||
|
|
@@ -46,20 +70,43 @@ install_license LICENSE | |
| # These are the platforms we will build for by default, unless further | ||
| # platforms are passed in on the command line | ||
| platforms = expand_cxxstring_abis(supported_platforms()) | ||
| cuda_platforms = expand_cxxstring_abis(CUDA.supported_platforms(; min_version=v"11")) | ||
|
|
||
| # CUDA errors for other platforms | ||
| filter!(p -> (Sys.islinux(p) && arch(p) == "x86_64"), cuda_platforms) | ||
|
|
||
| # The products that we will ensure are always built | ||
| products = [ | ||
| LibraryProduct("lib_lightgbm", :lib_lightgbm), | ||
| ExecutableProduct("lightgbm", :lightgbm), | ||
| ] | ||
|
|
||
| all_platforms = [platforms; cuda_platforms] | ||
|
|
||
| # Dependencies that must be installed before this package can be built | ||
| dependencies = [ | ||
| # For OpenMP we use libomp from `LLVMOpenMP_jll` where we use LLVM as compiler (BSD | ||
| # systems), and libgomp from `CompilerSupportLibraries_jll` everywhere else. | ||
| Dependency(PackageSpec(name="CompilerSupportLibraries_jll", uuid="e66e0078-7015-5450-92f7-15fbd957f2ae"); platforms=filter(!Sys.isbsd, platforms)), | ||
| Dependency(PackageSpec(name="LLVMOpenMP_jll", uuid="1d63c593-3942-5779-bab2-d838dc0a180e"); platforms=filter(Sys.isbsd, platforms)), | ||
| Dependency(PackageSpec(name="CompilerSupportLibraries_jll", uuid="e66e0078-7015-5450-92f7-15fbd957f2ae"); platforms=filter(!Sys.isbsd, all_platforms)), | ||
| Dependency(PackageSpec(name="LLVMOpenMP_jll", uuid="1d63c593-3942-5779-bab2-d838dc0a180e"); platforms=filter(Sys.isbsd, all_platforms)), | ||
|
|
||
| # GPU support is enabled via OpenCL and is hard to cross compile for other platforms | ||
| Dependency(PackageSpec(name="OpenCL_jll", uuid="6cb37087-e8b6-5417-8430-1f242f1e46e4"); platforms=filter(Sys.islinux, all_platforms)), | ||
| BuildDependency(PackageSpec(name="OpenCL_Headers_jll", uuid="a7aa756b-2b7f-562a-9e9d-e94076c5c8ee"); platforms=filter(Sys.islinux, all_platforms)), | ||
|
|
||
| Dependency(PackageSpec(name="boost_jll", uuid="28df3c45-c428-5900-9ff8-a3135698ca75"); compat="=1.76.0", platforms=filter(Sys.islinux, all_platforms)), | ||
| ] | ||
|
|
||
| # Build the tarballs, and possibly a `build.jl` as well. | ||
| build_tarballs(ARGS, name, version, sources, script, platforms, products, dependencies; julia_compat="1.6", preferred_gcc_version = v"8.1.0") | ||
| for platform in all_platforms | ||
| if platform in platforms && CUDA.is_supported(platform) | ||
| platform["cuda"] = "none" | ||
| end | ||
|
|
||
| deps = [dependencies; CUDA.required_dependencies(platform; static_sdk=true)] | ||
|
|
||
| should_build_platform(triplet(platform)) || continue | ||
|
|
||
| # Build the tarballs, and possibly a `build.jl` as well. | ||
| build_tarballs(ARGS, name, version, sources, script, [platform], products, deps; | ||
| julia_compat="1.6", preferred_gcc_version = v"8.1", augment_platform_block=CUDA.augment) | ||
| end | ||
characat0 marked this conversation as resolved.
Show resolved
Hide resolved
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| diff --git a/CMakeLists.txt b/CMakeLists.txt | ||
| index 1ff289b9..e71d5b99 100644 | ||
| --- a/CMakeLists.txt | ||
| +++ b/CMakeLists.txt | ||
| @@ -198,32 +198,28 @@ if(__INTEGRATE_OPENCL) | ||
| endif() | ||
|
|
||
| if(USE_CUDA) | ||
| - find_package(CUDA 11.0 REQUIRED) | ||
| - include_directories(${CUDA_INCLUDE_DIRS}) | ||
| + find_package(CUDAToolkit 11.0 REQUIRED) | ||
| + include_directories(${CUDAToolkit_INCLUDE_DIRS}) | ||
| set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcompiler=${OpenMP_CXX_FLAGS} -Xcompiler=-fPIC -Xcompiler=-Wall") | ||
|
|
||
| # reference for mapping of CUDA toolkit component versions to supported architectures ("compute capabilities"): | ||
| # https://en.wikipedia.org/wiki/CUDA#GPUs_supported | ||
| - set(CUDA_ARCHS "6.0" "6.1" "6.2" "7.0" "7.5") | ||
| - if(CUDA_VERSION VERSION_GREATER_EQUAL "11.0") | ||
| - list(APPEND CUDA_ARCHS "8.0") | ||
| + set(CUDA_ARCHS "60" "61" "62" "70" "75") | ||
| + if(CUDA_VERSION VERSION_GREATER_EQUAL "110") | ||
| + list(APPEND CUDA_ARCHS "80") | ||
| endif() | ||
| - if(CUDA_VERSION VERSION_GREATER_EQUAL "11.1") | ||
| - list(APPEND CUDA_ARCHS "8.6") | ||
| + if(CUDA_VERSION VERSION_GREATER_EQUAL "111") | ||
| + list(APPEND CUDA_ARCHS "86") | ||
| endif() | ||
| - if(CUDA_VERSION VERSION_GREATER_EQUAL "11.5") | ||
| - list(APPEND CUDA_ARCHS "8.7") | ||
| + if(CUDA_VERSION VERSION_GREATER_EQUAL "115") | ||
| + list(APPEND CUDA_ARCHS "87") | ||
| endif() | ||
| - if(CUDA_VERSION VERSION_GREATER_EQUAL "11.8") | ||
| - list(APPEND CUDA_ARCHS "8.9") | ||
| - list(APPEND CUDA_ARCHS "9.0") | ||
| + if(CUDA_VERSION VERSION_GREATER_EQUAL "118") | ||
| + list(APPEND CUDA_ARCHS "89") | ||
| + list(APPEND CUDA_ARCHS "90") | ||
| endif() | ||
| list(POP_BACK CUDA_ARCHS CUDA_LAST_SUPPORTED_ARCH) | ||
| list(APPEND CUDA_ARCHS "${CUDA_LAST_SUPPORTED_ARCH}+PTX") | ||
| - cuda_select_nvcc_arch_flags(CUDA_ARCH_FLAGS ${CUDA_ARCHS}) | ||
| - string(REPLACE ";" " " CUDA_ARCH_FLAGS "${CUDA_ARCH_FLAGS}") | ||
| - | ||
| - set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} ${CUDA_ARCH_FLAGS}") | ||
| if(USE_DEBUG) | ||
| set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -g") | ||
| else() | ||
| @@ -260,7 +256,7 @@ if(USE_CUDA) | ||
| function(add_histogram hsize hname hadd hconst hdir) | ||
| add_library(histo${hsize}${hname} OBJECT src/treelearner/kernels/histogram${hsize}.cu) | ||
| set_target_properties(histo${hsize}${hname} PROPERTIES CUDA_SEPARABLE_COMPILATION ON) | ||
| - set_target_properties(histo${hsize}${hname} PROPERTIES CUDA_ARCHITECTURES OFF) | ||
| + set_target_properties(histo${hsize}${hname} PROPERTIES CUDA_ARCHITECTURES ${CUDA_ARCHS}) | ||
| if(hadd) | ||
| list(APPEND histograms histo${hsize}${hname}) | ||
| set(histograms ${histograms} PARENT_SCOPE) | ||
| @@ -600,10 +596,10 @@ if(USE_CUDA) | ||
| # Disable cmake warning about policy CMP0104. Refer to issue #3754 and PR #4268. | ||
| # Custom target properties does not propagate, thus we need to specify for | ||
| # each target that contains or depends on cuda source. | ||
| - set_target_properties(lightgbm_objs PROPERTIES CUDA_ARCHITECTURES OFF) | ||
| - set_target_properties(_lightgbm PROPERTIES CUDA_ARCHITECTURES OFF) | ||
| + set_target_properties(lightgbm_objs PROPERTIES CUDA_ARCHITECTURES ${CUDA_ARCHS}) | ||
| + set_target_properties(_lightgbm PROPERTIES CUDA_ARCHITECTURES ${CUDA_ARCHS}) | ||
| if(BUILD_CLI) | ||
| - set_target_properties(lightgbm PROPERTIES CUDA_ARCHITECTURES OFF) | ||
| + set_target_properties(lightgbm PROPERTIES CUDA_ARCHITECTURES ${CUDA_ARCHS}) | ||
| endif() | ||
|
|
||
| set_target_properties(lightgbm_objs PROPERTIES CUDA_SEPARABLE_COMPILATION ON) |
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.