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

[R-package] how do I build a GPU-enabled version of the R package? #6378

Closed
nipnipj opened this issue Mar 22, 2024 · 8 comments
Closed

[R-package] how do I build a GPU-enabled version of the R package? #6378

nipnipj opened this issue Mar 22, 2024 · 8 comments

Comments

@nipnipj
Copy link

nipnipj commented Mar 22, 2024

I followed these steps:

git clone --recursive https://github.com/microsoft/LightGBM
cd LightGBM
mkdir build
cd build
cmake -DUSE_GPU=1 ..
make -j4

At this point everything compiled/built. My question is. How do I make R recognize it as a package?

@jameslamb
Copy link
Collaborator

Thanks for using LightGBM.

Those steps product the LightGBM CLI (./lightgbm) and shared library (./lib_lightgbm.so) but not the R package. They're not necessary to build the R package.

To build the R package from sources here on GitHub, follow the instructions at https://github.com/microsoft/LightGBM/tree/master/R-package#installation.

Since it looks like you'd like to build a GPU-accelerated version of the package, pay particular attention to https://github.com/microsoft/LightGBM/tree/master/R-package#installing-a-gpu-enabled-build.

Rscript build_r.R --use-gpu

The CRAN-style distribution of the package does not support GPU acceleration at this time. That feature is tracked in these:

@jameslamb jameslamb changed the title Installing LGBM [R-package] how do I build a GPU-enabled version of the R package? Mar 22, 2024
@nipnipj
Copy link
Author

nipnipj commented Mar 22, 2024

Whe I use Rscript build_r.R --use-gpu, I get another error, it asks me to recomplile with cmake -DUSE_CUDA=1.
Basically I just want to test the GPU capabilities.

@jameslamb
Copy link
Collaborator

it asks me to recompile with cmake -DUSE_CUDA=1

Running the command Rscript build_r.R --use-gpu generates an error telling you to pass -DUSE_CUDA=1? That doesn't sound right to me.

Can you please share the exact text of that error message?

@nipnipj
Copy link
Author

nipnipj commented Mar 22, 2024

Ok I opened terminal from LightGBM folder and used Rscript build_r.R --use-gpu. Then I tried to fit a model and the following message appears:

[LightGBM] [Fatal] CUDA Tree Learner was not enabled in this build.
Please recompile with CMake option -DUSE_CUDA=1
Error in initialize(...) : 
  CUDA Tree Learner was not enabled in this build.
Please recompile with CMake option -DUSE_CUDA=1

@jameslamb
Copy link
Collaborator

Then I tried to fit a model

Ah! Ok, so it wasn't coming from the build command.

I strongly suspect you passed device = "cuda" in params to lgb.train(). If you've built the library with Rscript build_r.R --use-gpu, pass device = "gpu" instead.

The R package currently only supports LightGBM's GPU build, which uses OpenCL to generate GPU kernels that work across GPUs from several manufacturers.

The R package doesn't support LightGBM's newer and faster CUDA build, a direct reimplementation of key operations in LightGBM as CUDA kernels. That is tracked in #3465 and #5378.

@nipnipj
Copy link
Author

nipnipj commented Mar 22, 2024

Ok I opened terminal from LightGBM folder and used Rscript build_r.R --use-gpu. Then I tried to fit a model and the following message appears:

[LightGBM] [Fatal] CUDA Tree Learner was not enabled in this build.
Please recompile with CMake option -DUSE_CUDA=1
Error in initialize(...) : 
  CUDA Tree Learner was not enabled in this build.
Please recompile with CMake option -DUSE_CUDA=1

No error when using "gpu" instead of "cuda".

@jameslamb
Copy link
Collaborator

No error when using "gpu" instead of "cuda".

hmmmm that sounds like a bug. Because that error is only raised in one place...the constructor of CUDASingleGPUTreeLearner if you compiled the library without passing -DUSE_CUDA=ON.

class CUDASingleGPUTreeLearner: public SerialTreeLearner {
public:
#pragma warning(disable : 4702)
explicit CUDASingleGPUTreeLearner(const Config* tree_config, const bool /*boosting_on_cuda*/) : SerialTreeLearner(tree_config) {
Log::Fatal("CUDA Tree Learner was not enabled in this build.\n"
"Please recompile with CMake option -DUSE_CUDA=1");
}
};

And the library will only try to instantiate one of those if you passed device = "cuda" in params.

} else if (device_type == std::string("cuda")) {
if (learner_type == std::string("serial")) {
if (config->num_gpu == 1) {
return new CUDASingleGPUTreeLearner(config, boosting_on_cuda);

Can you please provide a minimal, reproducible example?

That's a small, self-contained snippet of R code that exactly produces this error. Something I could copy and run without modification.

And answers to these questions please:

  • version of LightGBM
  • version of R
  • exact command(s) you ran to install the R package

@jameslamb
Copy link
Collaborator

Ah I see you closed this. @nipnipj did passing device = "gpu" fix this for you?

It'd be helpful if you could share the resolution you found, so we could learn if there is some bug that needs to be fixed and so other people finding this from search engines will be able to learn from your experience.

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

No branches or pull requests

2 participants