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

[CUDA] consolidate CUDA versions #5677

Merged
merged 21 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 9 additions & 26 deletions .ci/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -199,41 +199,24 @@ if [[ $TASK == "gpu" ]]; then
elif [[ $METHOD == "source" ]]; then
cmake -DUSE_GPU=ON ..
fi
elif [[ $TASK == "cuda" || $TASK == "cuda_exp" ]]; then
if [[ $TASK == "cuda" ]]; then
sed -i'.bak' 's/std::string device_type = "cpu";/std::string device_type = "cuda";/' $BUILD_DIRECTORY/include/LightGBM/config.h
grep -q 'std::string device_type = "cuda"' $BUILD_DIRECTORY/include/LightGBM/config.h || exit -1 # make sure that changes were really done
else
sed -i'.bak' 's/std::string device_type = "cpu";/std::string device_type = "cuda_exp";/' $BUILD_DIRECTORY/include/LightGBM/config.h
grep -q 'std::string device_type = "cuda_exp"' $BUILD_DIRECTORY/include/LightGBM/config.h || exit -1 # make sure that changes were really done
# by default ``gpu_use_dp=false`` for efficiency. change to ``true`` here for exact results in ci tests
sed -i'.bak' 's/gpu_use_dp = false;/gpu_use_dp = true;/' $BUILD_DIRECTORY/include/LightGBM/config.h
grep -q 'gpu_use_dp = true' $BUILD_DIRECTORY/include/LightGBM/config.h || exit -1 # make sure that changes were really done
fi
elif [[ $TASK == "cuda" ]]; then
sed -i'.bak' 's/std::string device_type = "cpu";/std::string device_type = "cuda";/' $BUILD_DIRECTORY/include/LightGBM/config.h
grep -q 'std::string device_type = "cuda"' $BUILD_DIRECTORY/include/LightGBM/config.h || exit -1 # make sure that changes were really done
# by default ``gpu_use_dp=false`` for efficiency. change to ``true`` here for exact results in ci tests
sed -i'.bak' 's/gpu_use_dp = false;/gpu_use_dp = true;/' $BUILD_DIRECTORY/include/LightGBM/config.h
grep -q 'gpu_use_dp = true' $BUILD_DIRECTORY/include/LightGBM/config.h || exit -1 # make sure that changes were really done
if [[ $METHOD == "pip" ]]; then
cd $BUILD_DIRECTORY/python-package && python setup.py sdist || exit -1
if [[ $TASK == "cuda" ]]; then
pip install --user $BUILD_DIRECTORY/python-package/dist/lightgbm-$LGB_VER.tar.gz -v --install-option=--cuda || exit -1
else
pip install --user $BUILD_DIRECTORY/python-package/dist/lightgbm-$LGB_VER.tar.gz -v --install-option=--cuda-exp || exit -1
fi
pip install --user $BUILD_DIRECTORY/python-package/dist/lightgbm-$LGB_VER.tar.gz -v --install-option=--cuda || exit -1
pytest $BUILD_DIRECTORY/tests/python_package_test || exit -1
exit 0
elif [[ $METHOD == "wheel" ]]; then
if [[ $TASK == "cuda" ]]; then
cd $BUILD_DIRECTORY/python-package && python setup.py bdist_wheel --cuda || exit -1
else
cd $BUILD_DIRECTORY/python-package && python setup.py bdist_wheel --cuda-exp || exit -1
fi
cd $BUILD_DIRECTORY/python-package && python setup.py bdist_wheel --cuda || exit -1
pip install --user $BUILD_DIRECTORY/python-package/dist/lightgbm-$LGB_VER*.whl -v || exit -1
pytest $BUILD_DIRECTORY/tests || exit -1
exit 0
elif [[ $METHOD == "source" ]]; then
if [[ $TASK == "cuda" ]]; then
cmake -DUSE_CUDA=ON ..
else
cmake -DUSE_CUDA_EXP=ON ..
fi
cmake -DUSE_CUDA=ON ..
fi
elif [[ $TASK == "mpi" ]]; then
if [[ $METHOD == "pip" ]]; then
Expand Down
20 changes: 5 additions & 15 deletions .github/workflows/cuda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,21 @@ jobs:
fail-fast: false
matrix:
include:
- method: source
compiler: gcc
python_version: "3.8"
cuda_version: "11.7.1"
task: cuda
- method: pip
compiler: clang
python_version: "3.9"
cuda_version: "10.0"
task: cuda
- method: wheel
compiler: gcc
python_version: "3.10"
cuda_version: "9.0"
cuda_version: "11.7.1"
task: cuda
- method: source
compiler: gcc
python_version: "3.8"
cuda_version: "11.7.1"
task: cuda_exp
cuda_version: "10.0"
task: cuda
- method: pip
compiler: clang
python_version: "3.9"
cuda_version: "10.0"
task: cuda_exp
cuda_version: "11.7.1"
task: cuda
steps:
- name: Setup or update software on host machine
run: |
Expand Down
33 changes: 14 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ option(USE_GPU "Enable GPU-accelerated training" OFF)
option(USE_SWIG "Enable SWIG to generate Java API" OFF)
option(USE_HDFS "Enable HDFS support (EXPERIMENTAL)" OFF)
option(USE_TIMETAG "Set to ON to output time costs" OFF)
option(USE_CUDA "Enable CUDA-accelerated training (EXPERIMENTAL)" OFF)
option(USE_CUDA_EXP "Enable CUDA-accelerated training with more acceleration (EXPERIMENTAL)" OFF)
option(USE_CUDA "Enable CUDA-accelerated training " OFF)
option(USE_CUDA_EXP "(DEPRECATED) Alias for 'USE_CUDA'. Use 'USE_CUDA' instead." OFF)
jameslamb marked this conversation as resolved.
Show resolved Hide resolved
option(USE_DEBUG "Set to ON for Debug mode" OFF)
option(USE_SANITIZER "Use santizer flags" OFF)
set(
Expand All @@ -31,7 +31,7 @@ elseif(USE_SWIG)
cmake_minimum_required(VERSION 3.8)
elseif(USE_GPU OR APPLE)
cmake_minimum_required(VERSION 3.2)
elseif(USE_CUDA OR USE_CUDA_EXP)
elseif(USE_CUDA)
jameslamb marked this conversation as resolved.
Show resolved Hide resolved
cmake_minimum_required(VERSION 3.16)
else()
cmake_minimum_required(VERSION 3.0)
Expand Down Expand Up @@ -137,7 +137,12 @@ else()
add_definitions(-DUSE_SOCKET)
endif()

if(USE_CUDA OR USE_CUDA_EXP)
if(USE_CUDA_EXP)
message(WARNING "Option -DUSE_CUDA_EXP=ON is deprecated. Use -DUSE_CUDA=ON instead.")
set(USE_CUDA ON CACHE BOOL "Building CUDA-enabled version" FORCE)
endif()

if(USE_CUDA)
set(CMAKE_CUDA_HOST_COMPILER "${CMAKE_CXX_COMPILER}")
enable_language(CUDA)
set(USE_OPENMP ON CACHE BOOL "CUDA requires OpenMP" FORCE)
Expand Down Expand Up @@ -192,12 +197,8 @@ if(__INTEGRATE_OPENCL)
endif()
endif()

if(USE_CUDA OR USE_CUDA_EXP)
if(USE_CUDA)
find_package(CUDA 9.0 REQUIRED)
else()
find_package(CUDA 10.0 REQUIRED)
endif()
if(USE_CUDA)
find_package(CUDA 10.0 REQUIRED)
include_directories(${CUDA_INCLUDE_DIRS})
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcompiler=${OpenMP_CXX_FLAGS} -Xcompiler=-fPIC -Xcompiler=-Wall")

Expand All @@ -224,11 +225,7 @@ if(USE_CUDA OR USE_CUDA_EXP)
endif()
message(STATUS "CMAKE_CUDA_FLAGS: ${CMAKE_CUDA_FLAGS}")

if(USE_CUDA)
add_definitions(-DUSE_CUDA)
elseif(USE_CUDA_EXP)
add_definitions(-DUSE_CUDA_EXP)
endif()
add_definitions(-DUSE_CUDA)

if(NOT DEFINED CMAKE_CUDA_STANDARD)
set(CMAKE_CUDA_STANDARD 11)
Expand Down Expand Up @@ -411,10 +408,8 @@ file(
src/objective/*.cpp
src/network/*.cpp
src/treelearner/*.cpp
if(USE_CUDA OR USE_CUDA_EXP)
if(USE_CUDA)
src/treelearner/*.cu
endif()
if(USE_CUDA_EXP)
src/boosting/cuda/*.cpp
src/boosting/cuda/*.cu
src/metric/cuda/*.cpp
Expand Down Expand Up @@ -549,7 +544,7 @@ if(__INTEGRATE_OPENCL)
target_link_libraries(lightgbm_objs PUBLIC ${INTEGRATED_OPENCL_LIBRARIES} ${CMAKE_DL_LIBS})
endif()

if(USE_CUDA OR USE_CUDA_EXP)
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.
Expand Down
8 changes: 3 additions & 5 deletions docs/Installation-Guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -605,8 +605,8 @@ Docker

Refer to `GPU Docker folder <https://github.com/microsoft/LightGBM/tree/master/docker/gpu>`__.

Build CUDA Version (Experimental)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Build CUDA Version
~~~~~~~~~~~~~~~~~~

The `original GPU build <#build-gpu-version>`__ of LightGBM (``device_type=gpu``) is based on OpenCL.

Expand All @@ -621,7 +621,7 @@ On Linux a CUDA version of LightGBM can be built using **CUDA**, **CMake** and *

The following dependencies should be installed before compilation:

- **CUDA** 9.0 or later libraries. Please refer to `this detailed guide`_. Pay great attention to the minimum required versions of host compilers listed in the table from that guide and use only recommended versions of compilers.
- **CUDA** 10.0 or later libraries. Please refer to `this detailed guide`_. Pay great attention to the minimum required versions of host compilers listed in the table from that guide and use only recommended versions of compilers.

- **CMake** 3.16 or later.

Expand All @@ -636,8 +636,6 @@ To build LightGBM CUDA version, run the following commands:
cmake -DUSE_CUDA=1 ..
make -j4

Recently, a new CUDA version with better efficiency is implemented as an experimental feature. To build the new CUDA version, replace ``-DUSE_CUDA`` with ``-DUSE_CUDA_EXP`` in the above commands. Please note that new version requires **CUDA** 10.0 or later libraries.

**Note**: glibc >= 2.14 is required.

**Note**: In some rare cases you may need to install OpenMP runtime library separately (use your package manager and search for ``lib[g|i]omp`` for doing this).
Expand Down
6 changes: 1 addition & 5 deletions docs/Parameters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ Core Parameters

- **Note**: please **don't** change this during training, especially when running multiple jobs simultaneously by external packages, otherwise it may cause undesirable errors

- ``device_type`` :raw-html:`<a id="device_type" title="Permalink to this parameter" href="#device_type">&#x1F517;&#xFE0E;</a>`, default = ``cpu``, type = enum, options: ``cpu``, ``gpu``, ``cuda``, ``cuda_exp``, aliases: ``device``
- ``device_type`` :raw-html:`<a id="device_type" title="Permalink to this parameter" href="#device_type">&#x1F517;&#xFE0E;</a>`, default = ``cpu``, type = enum, options: ``cpu``, ``gpu``, ``cuda``, aliases: ``device``

- device for the tree learning, you can use GPU to achieve the faster learning
jameslamb marked this conversation as resolved.
Show resolved Hide resolved

Expand All @@ -215,10 +215,6 @@ Core Parameters

- **Note**: refer to `Installation Guide <./Installation-Guide.rst#build-gpu-version>`__ to build LightGBM with GPU support

- **Note**: ``cuda_exp`` is an experimental CUDA version, the installation guide for ``cuda_exp`` is identical with ``cuda``

- **Note**: ``cuda_exp`` is faster than ``cuda`` and will replace ``cuda`` in the future

- ``seed`` :raw-html:`<a id="seed" title="Permalink to this parameter" href="#seed">&#x1F517;&#xFE0E;</a>`, default = ``None``, type = int, aliases: ``random_seed``, ``random_state``

- this seed is used to generate other seeds, e.g. ``data_random_seed``, ``feature_fraction_seed``, etc.
Expand Down
4 changes: 2 additions & 2 deletions include/LightGBM/bin.h
Original file line number Diff line number Diff line change
Expand Up @@ -480,13 +480,13 @@ class MultiValBin {

virtual MultiValBin* Clone() = 0;

#ifdef USE_CUDA_EXP
#ifdef USE_CUDA
virtual const void* GetRowWiseData(uint8_t* bit_type,
size_t* total_size,
bool* is_sparse,
const void** out_data_ptr,
uint8_t* data_ptr_bit_type) const = 0;
#endif // USE_CUDA_EXP
#endif // USE_CUDA
};

inline uint32_t BinMapper::ValueToBin(double value) const {
Expand Down
4 changes: 1 addition & 3 deletions include/LightGBM/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,12 @@ struct Config {

// [doc-only]
// type = enum
// options = cpu, gpu, cuda, cuda_exp
// options = cpu, gpu, cuda
// alias = device
// desc = device for the tree learning, you can use GPU to achieve the faster learning
// desc = **Note**: it is recommended to use the smaller ``max_bin`` (e.g. 63) to get the better speed up
// desc = **Note**: for the faster speed, GPU uses 32-bit float point to sum up by default, so this may affect the accuracy for some tasks. You can set ``gpu_use_dp=true`` to enable 64-bit float point, but it will slow down the training
// desc = **Note**: refer to `Installation Guide <./Installation-Guide.rst#build-gpu-version>`__ to build LightGBM with GPU support
// desc = **Note**: ``cuda_exp`` is an experimental CUDA version, the installation guide for ``cuda_exp`` is identical with ``cuda``
// desc = **Note**: ``cuda_exp`` is faster than ``cuda`` and will replace ``cuda`` in the future
std::string device_type = "cpu";

// [doc-only]
Expand Down
4 changes: 2 additions & 2 deletions include/LightGBM/cuda/cuda_algorithms.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#ifndef LIGHTGBM_CUDA_CUDA_ALGORITHMS_HPP_
#define LIGHTGBM_CUDA_CUDA_ALGORITHMS_HPP_

#ifdef USE_CUDA_EXP
#ifdef USE_CUDA

#include <cuda.h>
#include <cuda_runtime.h>
Expand Down Expand Up @@ -577,5 +577,5 @@ __device__ VAL_T PercentileDevice(const VAL_T* values,

} // namespace LightGBM

#endif // USE_CUDA_EXP
#endif // USE_CUDA
#endif // LIGHTGBM_CUDA_CUDA_ALGORITHMS_HPP_
4 changes: 2 additions & 2 deletions include/LightGBM/cuda/cuda_column_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See LICENSE file in the project root for license information.
*/

#ifdef USE_CUDA_EXP
#ifdef USE_CUDA

#ifndef LIGHTGBM_CUDA_CUDA_COLUMN_DATA_HPP_
#define LIGHTGBM_CUDA_CUDA_COLUMN_DATA_HPP_
Expand Down Expand Up @@ -137,4 +137,4 @@ class CUDAColumnData {

#endif // LIGHTGBM_CUDA_CUDA_COLUMN_DATA_HPP_

#endif // USE_CUDA_EXP
#endif // USE_CUDA
4 changes: 2 additions & 2 deletions include/LightGBM/cuda/cuda_metadata.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See LICENSE file in the project root for license information.
*/

#ifdef USE_CUDA_EXP
#ifdef USE_CUDA

#ifndef LIGHTGBM_CUDA_CUDA_METADATA_HPP_
#define LIGHTGBM_CUDA_CUDA_METADATA_HPP_
Expand Down Expand Up @@ -55,4 +55,4 @@ class CUDAMetadata {

#endif // LIGHTGBM_CUDA_CUDA_METADATA_HPP_

#endif // USE_CUDA_EXP
#endif // USE_CUDA
4 changes: 2 additions & 2 deletions include/LightGBM/cuda/cuda_metric.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#ifndef LIGHTGBM_CUDA_CUDA_METRIC_HPP_
#define LIGHTGBM_CUDA_CUDA_METRIC_HPP_

#ifdef USE_CUDA_EXP
#ifdef USE_CUDA

#include <LightGBM/metric.h>

Expand Down Expand Up @@ -36,6 +36,6 @@ class CUDAMetricInterface: public HOST_METRIC {

} // namespace LightGBM

#endif // USE_CUDA_EXP
#endif // USE_CUDA

#endif // LIGHTGBM_CUDA_CUDA_METRIC_HPP_
4 changes: 2 additions & 2 deletions include/LightGBM/cuda/cuda_objective_function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#ifndef LIGHTGBM_CUDA_CUDA_OBJECTIVE_FUNCTION_HPP_
#define LIGHTGBM_CUDA_CUDA_OBJECTIVE_FUNCTION_HPP_

#ifdef USE_CUDA_EXP
#ifdef USE_CUDA

#include <LightGBM/cuda/cuda_utils.h>
#include <LightGBM/objective_function.h>
Expand Down Expand Up @@ -73,6 +73,6 @@ class CUDAObjectiveInterface: public HOST_OBJECTIVE {

} // namespace LightGBM

#endif // USE_CUDA_EXP
#endif // USE_CUDA

#endif // LIGHTGBM_CUDA_CUDA_OBJECTIVE_FUNCTION_HPP_
4 changes: 2 additions & 2 deletions include/LightGBM/cuda/cuda_random.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifndef LIGHTGBM_CUDA_CUDA_RANDOM_HPP_
#define LIGHTGBM_CUDA_CUDA_RANDOM_HPP_

#ifdef USE_CUDA_EXP
#ifdef USE_CUDA

#include <cuda.h>
#include <cuda_runtime.h>
Expand Down Expand Up @@ -69,6 +69,6 @@ class CUDARandom {

} // namespace LightGBM

#endif // USE_CUDA_EXP
#endif // USE_CUDA

#endif // LIGHTGBM_CUDA_CUDA_RANDOM_HPP_
4 changes: 2 additions & 2 deletions include/LightGBM/cuda/cuda_row_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See LICENSE file in the project root for license information.
*/

#ifdef USE_CUDA_EXP
#ifdef USE_CUDA

#ifndef LIGHTGBM_CUDA_CUDA_ROW_DATA_HPP_
#define LIGHTGBM_CUDA_CUDA_ROW_DATA_HPP_
Expand Down Expand Up @@ -176,4 +176,4 @@ class CUDARowData {
} // namespace LightGBM
#endif // LIGHTGBM_CUDA_CUDA_ROW_DATA_HPP_

#endif // USE_CUDA_EXP
#endif // USE_CUDA
4 changes: 2 additions & 2 deletions include/LightGBM/cuda/cuda_split_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* license information.
*/

#ifdef USE_CUDA_EXP
#ifdef USE_CUDA

#ifndef LIGHTGBM_CUDA_CUDA_SPLIT_INFO_HPP_
#define LIGHTGBM_CUDA_CUDA_SPLIT_INFO_HPP_
Expand Down Expand Up @@ -102,4 +102,4 @@ class CUDASplitInfo {

#endif // LIGHTGBM_CUDA_CUDA_SPLIT_INFO_HPP_

#endif // USE_CUDA_EXP
#endif // USE_CUDA
4 changes: 2 additions & 2 deletions include/LightGBM/cuda/cuda_tree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See LICENSE file in the project root for license information.
*/

#ifdef USE_CUDA_EXP
#ifdef USE_CUDA

#ifndef LIGHTGBM_CUDA_CUDA_TREE_HPP_
#define LIGHTGBM_CUDA_CUDA_TREE_HPP_
Expand Down Expand Up @@ -170,4 +170,4 @@ class CUDATree : public Tree {

#endif // LIGHTGBM_CUDA_CUDA_TREE_HPP_

#endif // USE_CUDA_EXP
#endif // USE_CUDA
Loading