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

Lightgbm does not work on GPU? #6205

Closed
code1704 opened this issue Nov 22, 2023 · 8 comments
Closed

Lightgbm does not work on GPU? #6205

code1704 opened this issue Nov 22, 2023 · 8 comments
Labels

Comments

@code1704
Copy link

code1704 commented Nov 22, 2023

Description

It's really hard to install a gpu version.

"Please recompile with CMake option -DUSE_CUDAP=1"

??? What is CUDAP?

cmake -DUSE_CUDAP=1 ..
but still got the same error.

Reproducible example

import lightgbm as lgb
import numpy as np

X = np.random.rand(500, 10) 
y = np.random.randint(2, size=500)
dataset = lgb.Dataset(X, label=y)
# params = {'device': 'gpu'}
params = {'device': 'cuda'}
gbm = lgb.train(params, dataset)

Environment info

centos 7 (in docker)

LightGBM version or commit hash:
master branch (4.1?)

Command(s) you used to install LightGBM

cmake -DUSE_CUDAP=1 ..
sh ./build-python.sh install --precompile
# the command above upgrades numpy and lightgbm will fails to import (numpy.float error). why do you upgrade that then?
pip3 install numpy==1.20

Additional Comments

@jameslamb
Copy link
Collaborator

jameslamb commented Nov 22, 2023

LightGBM does not work on GPU

That is absolutely not true. There are 2 GPU-accelerated builds of LightGBM:

  • "device": "gpu" (-DUSE_GPU=1) = OpenCL-based implementation targeting a wide range of GPUs from multiple manufacturers
  • "device": "cuda" (-DUSE_CUDA=1) = CUDA kernel targeting NVIDIA GPUs

To install the Python package using these builds, see the guide in https://github.com/microsoft/LightGBM/blob/master/python-package/README.rst.

What is CUDAP?

Thanks for pointing this out! That's a typo.

I found that error message using GitHub search: https://github.com/search?q=repo%3Amicrosoft%2FLightGBM+%22Please+recompile+with+CMake+option+-DUSE_CUDAP%3D1%22&type=code

"Please recompile with CMake option -DUSE_CUDAP=1");

It should be -DUSE_CUDA (no P). We'd be grateful if you'd open a pull request fixing that. Are you interested in contributing?

@code1704
Copy link
Author

Thanks I will try USE_CUDA later.

I just compiled with opencl. It tells "LightGBMError: No OpenCL device found", which clinfo founds nvidia cuda.

image
clinfo
Number of platforms                               1
  Platform Name                                   NVIDIA CUDA
  Platform Vendor                                 NVIDIA Corporation
  Platform Version                                OpenCL 3.0 CUDA 11.8.87
  Platform Profile                                FULL_PROFILE
  Platform Extensions                             cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_fp64 cl_khr_3d_image_writes cl_khr_byte_addressable_store cl_khr_icd cl_khr_gl_sharing cl_nv_compiler_options cl_nv_device_attribute_query cl_nv_pragma_unroll cl_nv_copy_opts cl_nv_create_buffer cl_khr_int64_base_atomics cl_khr_int64_extended_atomics cl_khr_device_uuid cl_khr_pci_bus_info cl_khr_external_semaphore cl_khr_external_memory cl_khr_external_semaphore_opaque_fd cl_khr_external_memory_opaque_fd
  Platform Host timer resolution                  0ns
  Platform Extensions function suffix             NV

  Platform Name                                   NVIDIA CUDA
Number of devices                                 1
  Device Name                                     NVIDIA GeForce GTX 1080 Ti

@jameslamb
Copy link
Collaborator

No OpenCL device found

Please see the advice in #5914 (comment).

@code1704
Copy link
Author

Thanks, this works. Will use USE_CUDA much faster than USE_GPU for nvidia GPU?

And this is another typo DUSE_GPU :)
image

@jameslamb
Copy link
Collaborator

another typo

ha sorry about that! Thanks, just edited

USE_CUDA much faster than USE_GPU for nvidia GPU?

Yes. The "device": "cuda" build should be faster, as:

  1. it handles more operations on the GPU (i.e. not falling back to CPU) than the "device": "gpu" version
  2. it was written much more recently, and takes advantage of newer versions of CUDA which have performance enhancements for newer NVIDIA GPUs

If you have an NVIDIA GPU, use the USE_CUDA version.

this works

great, we'll close this issue

@code1704
Copy link
Author

great thanks

jameslamb added a commit that referenced this issue Nov 22, 2023
Per the report in #6205.

Fixes a typo in an error message from the CUDA version of the library.
@code1704
Copy link
Author

code1704 commented Nov 22, 2023

Can lightgbm use multi gpu cards? I have 4 cards, seems it uses only one.

image

@jmoralez
Copy link
Collaborator

Not yet, that's being tracked in #5076.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants