Commit f98d75fc authored by Guolin Ke's avatar Guolin Ke Committed by GitHub
Browse files

Compile R package by custom tool chain. (#584)

* add R's library file to vs project and cmake.

* support using dll built by vs.

* better search for the library file.

* remove mingw related doc .

* update document.

* Let R handle the library compile.

* try fix build from github.

* Update README.md

* cleaner build.

* fix the install problem in linux.

* Update README.md
parent a29b3ab2
......@@ -108,7 +108,7 @@ file(GLOB SOURCES
)
add_executable(lightgbm src/main.cpp ${SOURCES})
add_library(_lightgbm SHARED src/c_api.cpp ${SOURCES})
add_library(_lightgbm SHARED src/c_api.cpp src/lightgbm_R.cpp ${SOURCES})
if(MSVC)
set_target_properties(_lightgbm PROPERTIES OUTPUT_NAME "lib_lightgbm")
......
......@@ -40,4 +40,4 @@ importFrom(R6,R6Class)
importFrom(data.table,":=")
importFrom(magrittr,"%>%")
importFrom(magrittr,"%T>%")
useDynLib(lightgbm)
useDynLib(lib_lightgbm)
......@@ -31,9 +31,9 @@ lgb.call <- function(fun_name, ret, ...) {
# Check for a ret call
if (!is.null(ret)) {
call_state <- .Call(fun_name, ..., ret, call_state, PACKAGE = "lightgbm") # Call with ret
call_state <- .Call(fun_name, ..., ret, call_state, PACKAGE = "lib_lightgbm") # Call with ret
} else {
call_state <- .Call(fun_name, ..., call_state, PACKAGE = "lightgbm") # Call without ret
call_state <- .Call(fun_name, ..., call_state, PACKAGE = "lib_lightgbm") # Call without ret
}
# Check for call state value post call
......@@ -43,7 +43,7 @@ lgb.call <- function(fun_name, ret, ...) {
buf_len <- 200L
act_len <- 0L
err_msg <- raw(buf_len)
err_msg <- .Call("LGBM_GetLastError_R", buf_len, act_len, err_msg, PACKAGE = "lightgbm")
err_msg <- .Call("LGBM_GetLastError_R", buf_len, act_len, err_msg, PACKAGE = "lib_lightgbm")
# Check error buffer
if (act_len > buf_len) {
......@@ -53,7 +53,7 @@ lgb.call <- function(fun_name, ret, ...) {
buf_len,
act_len,
err_msg,
PACKAGE = "lightgbm")
PACKAGE = "lib_lightgbm")
}
# Return error
......
......@@ -4,30 +4,41 @@ LightGBM R Package
Installation
------------
Windows users may need to run with administrator rights (either R or the command prompt, depending on the way you are installing this package). Rtools must be installed for Windows. Linux users might require the appropriate user write permissions for packages.
### Preparation
You need to install *git* and [cmake](https://cmake.org/) first.
The default compiler is Visual Studio (or [MS Build](https://www.visualstudio.com/downloads/#build-tools-for-visual-studio-2017)) in Windows. You also can use MinGW64 to compile by set ```use_mingw <- TRUE``` in ```R-package/src/install.libs.R``` (We recommend *Visual Studio* for its better multi-threading efficency in Windows).
For OSX user, gcc need to be installed first (refer to https://github.com/Microsoft/LightGBM/wiki/Installation-Guide#osx).
You can use a command prompt to install via command line:
### Install
Install LightGBM R-package by following command:
```
cd R-package
R CMD INSTALL --build .
git clone --recursive https://github.com/Microsoft/LightGBM
cd LightGBM/R-package
R CMD INSTALL --build .
```
Or build a self-contained R package then install:
```
git clone --recursive https://github.com/Microsoft/LightGBM
cd LightGBM/R-package
Rscript build_package.R
R CMD INSTALL lightgbm_0.1.tar.gz
```
You can also install directly from R using the repository with `devtools`:
```r
devtools::install_github("Microsoft/LightGBM", subdir = "R-package")
```
Windows users may need to run with administrator rights (either R or the command prompt, depending on the way you are installing this package). Rtools must be installed for Windows. Linux users might require the appropriate user write permissions for packages.
For the `devtools` install scenario, you can safely ignore this message:
Set ```use_gpu <- TRUE``` in ```R-package/src/install.libs.R``` can enable the build with GPU support (Need to install *Boost* and *OpenCL* first, details can be found in [gpu-support](https://github.com/Microsoft/LightGBM/wiki/Installation-Guide#with-gpu-support)).
You can also install directly from R using the repository with `devtools`:
```r
Warning message:
GitHub repo contains submodules, may not function as expected!
devtools::install_github("Microsoft/LightGBM", subdir = "R-package")
```
If you want to build the self-contained R package, you can run ```unix_build_package.sh```(for UNIX) or ```win_build_package.cmd ```(for Windows). Then use ```R CMD INSTALL lightgbm_0.1.tar.gz``` to install.
When your package installation is done, you can check quickly if your LightGBM R package is working by running the following:
```r
......@@ -38,50 +49,6 @@ dtrain <- lgb.Dataset(train$data, label=train$label)
params <- list(objective="regression", metric="l2")
model <- lgb.cv(params, dtrain, 10, nfold=5, min_data=1, learning_rate=1, early_stopping_rounds=10)
```
### OSX installation
The default installation cannot successfully complete in OSX because clang doesn't support OpenMP.
You can use the following script to change default compiler to gcc, then compile LightGBM R package:
```bash
brew install gcc --without-multilib
mkdir -p ~/.R
touch ~/.R/Makevars
cat <<EOF >>~/.R/Makevars
C=gcc-6
CXX=g++-6
CXX1X=g++-6
LDFLAGS=-L/usr/local/Cellar/gcc/6.3.0/lib
CPPFLAGS=-I/usr/local/Cellar/gcc/6.3.0/include
SHLIB_OPENMP_CFLAGS = -fopenmp
SHLIB_OPENMP_CXXFLAGS = -fopenmp
SHLIB_OPENMP_FCFLAGS = -fopenmp
SHLIB_OPENMP_FFLAGS = -fopenmp
EOF
```
Note:
* For `LDFLAGS=-L/usr/local/Cellar/gcc/6.3.0/lib` and `CPPFLAGS=-I/usr/local/Cellar/gcc/6.3.0/include`, you may need to change `6.3.0` to your gcc version.
* For `gcc-6` and `g++-6`, you may need to change to your gcc version (like `gcc-7` and `g++7` if using gcc with version 7).
* For `CXX1X`, if you are using R 3.4 or a more recent version, you must change it to `CXX11`.
To check your LightGBM installation, the test is identical to Linux/Windows versions (check the test provided just before OSX Installation part)
Performance note
------------
With `gcc`, it is recommended to use `-O3 -mtune=native` instead of the default `-O2 -mtune=core2` by modifying the appropriate file (`Makeconf` or `Makevars`) if you want to achieve maximum speed.
Benchmark example using Intel Ivy Bridge CPU on 1M x 1K dataset:
| Compilation Flag | Performance Index |
| --- | ---: |
| `-O2 -mtune=core2` | 100.00% |
| `-O2 -mtune=native` | 100.90% |
| `-O3 -mtune=native` | 102.78% |
| `-O3 -ffast-math -mtune=native` | 100.64% |
Examples
------------
......
if(!file.copy("./../include", "src/", overwrite=TRUE, recursive = TRUE)){
stop("cannot find folder LightGBM/include")
}
if(!file.copy("./../src", "src/", overwrite=TRUE, recursive = TRUE)){
stop("cannot find folder LightGBM/src")
}
if(!file.copy("./../compute", "src/", overwrite=TRUE, recursive = TRUE)){
print("cannot find folder LightGBM/compute, will disable GPU build")
}
if(!file.copy("./../CMakeLists.txt", "src/", overwrite=TRUE, recursive=TRUE)){
stop("cannot find file LightGBM/CMakeLists.txt")
}
if(!file.exists("src/_IS_FULL_PACKAGE")){
file.create("src/_IS_FULL_PACKAGE")
}
system("R CMD build --no-build-vignettes .")
\ No newline at end of file
# package root
PKGROOT=../../
ENABLE_STD_THREAD=1
CXX_STD = CXX11
LGBM_RFLAGS = -DUSE_SOCKET
PKG_CPPFLAGS= -I$(PKGROOT)/include $(LGBM_RFLAGS) -Wno-deprecated-declarations -Wno-unknown-pragmas
PKG_CXXFLAGS= $(SHLIB_OPENMP_CFLAGS) $(SHLIB_PTHREAD_FLAGS) -std=c++11
PKG_LIBS = $(SHLIB_OPENMP_CFLAGS) $(SHLIB_PTHREAD_FLAGS)
OBJECTS = ./lightgbm-all.o ./lightgbm_R.o
# package root
PKGROOT=../../
ENABLE_STD_THREAD=1
CXX_STD = CXX11
LGBM_RFLAGS = -DUSE_SOCKET
PKG_CPPFLAGS= -I$(PKGROOT)/include $(LGBM_RFLAGS) -Wno-unknown-pragmas
PKG_CXXFLAGS= $(SHLIB_OPENMP_CFLAGS) $(SHLIB_PTHREAD_FLAGS) -std=c++11
PKG_LIBS = $(SHLIB_OPENMP_CFLAGS) $(SHLIB_PTHREAD_FLAGS) -lws2_32 -liphlpapi
OBJECTS = ./lightgbm-all.o ./lightgbm_R.o
# package root
PKGROOT=.
ENABLE_STD_THREAD=1
CXX_STD = CXX11
LGBM_RFLAGS = -DUSE_SOCKET
PKG_CPPFLAGS= -I$(PKGROOT)/include $(LGBM_RFLAGS) -Wno-deprecated-declarations -Wno-unknown-pragmas
PKG_CXXFLAGS= $(SHLIB_OPENMP_CFLAGS) $(SHLIB_PTHREAD_FLAGS) -std=c++11
PKG_LIBS = $(SHLIB_OPENMP_CFLAGS) $(SHLIB_PTHREAD_FLAGS)
OBJECTS = ./lightgbm-fullcode.o ./lightgbm_R.o
# package root
PKGROOT=.
ENABLE_STD_THREAD=1
CXX_STD = CXX11
LGBM_RFLAGS = -DUSE_SOCKET
PKG_CPPFLAGS= -I$(PKGROOT)/include $(LGBM_RFLAGS) -Wno-unknown-pragmas
PKG_CXXFLAGS= $(SHLIB_OPENMP_CFLAGS) $(SHLIB_PTHREAD_FLAGS) -std=c++11
PKG_LIBS = $(SHLIB_OPENMP_CFLAGS) $(SHLIB_PTHREAD_FLAGS) -lws2_32 -liphlpapi
OBJECTS = ./lightgbm-fullcode.o ./lightgbm_R.o
use_gpu <- FALSE
use_mingw <- FALSE
source_dir <- paste0(R_PACKAGE_SOURCE, '/src')
setwd(source_dir)
if(!file.exists("_IS_FULL_PACKAGE")){
if(!file.copy("./../../include", "./", overwrite=TRUE, recursive = TRUE)){
stop("cannot find folder LightGBM/include")
}
if(!file.copy("./../../src", "./", overwrite=TRUE, recursive = TRUE)){
stop("cannot find folder LightGBM/src")
}
if(use_gpu){
if(!file.copy("./../../compute", "./", overwrite=TRUE, recursive = TRUE)){
print("cannot find folder LightGBM/compute, will disable GPU build")
use_gpu <- FALSE
}
}
if(!file.copy("./../../CMakeLists.txt", "./", overwrite=TRUE, recursive=TRUE)){
stop("cannot find file LightGBM/CMakeLists.txt")
}
}
build_dir <- paste0(source_dir, "/build")
dir.create(build_dir, recursive = TRUE, showWarnings = FALSE)
setwd(build_dir)
cmake_cmd <- "cmake"
build_cmd <- "make -j"
lib_folder <- paste0(R_PACKAGE_SOURCE, '/src')
if (WINDOWS) {
if(use_mingw){
cmake_cmd <- paste0(cmake_cmd, " -G \"MinGW Makefiles\" ")
build_cmd <- "mingw32-make.exe -j"
} else{
cmake_cmd <- paste0(cmake_cmd, " -DCMAKE_GENERATOR_PLATFORM=x64 ")
build_cmd <- "cmake --build . --target _lightgbm --config Release"
lib_folder <- paste0(R_PACKAGE_SOURCE, '/src/Release')
}
}
if(use_gpu) {
cmake_cmd <- paste0(cmake_cmd, " -DUSE_GPU=1 ")
}
system(paste0(cmake_cmd, " .."))
system(build_cmd)
dest <- file.path(R_PACKAGE_DIR, paste0('libs', R_ARCH))
dir.create(dest, recursive = TRUE, showWarnings = FALSE)
src <- paste0(lib_folder, '/lib_lightgbm', SHLIB_EXT)
if(file.exists(src)){
print(paste0("find library file: ", src))
file.copy(src, dest, overwrite = TRUE)
} else {
stop("cannot find lib_lightgbm.dll")
}
// application
#include "../../src/application/application.cpp"
// boosting
#include "../../src/boosting/boosting.cpp"
#include "../../src/boosting/gbdt.cpp"
#include "../../src/boosting/gbdt_prediction.cpp"
#include "../../src/boosting/prediction_early_stop.cpp"
// io
#include "../../src/io/bin.cpp"
#include "../../src/io/config.cpp"
#include "../../src/io/dataset.cpp"
#include "../../src/io/dataset_loader.cpp"
#include "../../src/io/metadata.cpp"
#include "../../src/io/parser.cpp"
#include "../../src/io/tree.cpp"
// metric
#include "../../src/metric/dcg_calculator.cpp"
#include "../../src/metric/metric.cpp"
// network
#include "../../src/network/linker_topo.cpp"
#include "../../src/network/linkers_socket.cpp"
#include "../../src/network/network.cpp"
// objective
#include "../../src/objective/objective_function.cpp"
// treelearner
#include "../../src/treelearner/data_parallel_tree_learner.cpp"
#include "../../src/treelearner/feature_parallel_tree_learner.cpp"
#include "../../src/treelearner/serial_tree_learner.cpp"
#include "../../src/treelearner/gpu_tree_learner.cpp"
#include "../../src/treelearner/tree_learner.cpp"
#include "../../src/treelearner/voting_parallel_tree_learner.cpp"
// c_api
#include "../../src/c_api.cpp"
// application
#include "./src/application/application.cpp"
// boosting
#include "./src/boosting/boosting.cpp"
#include "./src/boosting/gbdt.cpp"
#include "./src/boosting/gbdt_prediction.cpp"
#include "./src/boosting/prediction_early_stop.cpp"
// io
#include "./src/io/bin.cpp"
#include "./src/io/config.cpp"
#include "./src/io/dataset.cpp"
#include "./src/io/dataset_loader.cpp"
#include "./src/io/metadata.cpp"
#include "./src/io/parser.cpp"
#include "./src/io/tree.cpp"
// metric
#include "./src/metric/dcg_calculator.cpp"
#include "./src/metric/metric.cpp"
// network
#include "./src/network/linker_topo.cpp"
#include "./src/network/linkers_socket.cpp"
#include "./src/network/network.cpp"
// objective
#include "./src/objective/objective_function.cpp"
// treelearner
#include "./src/treelearner/data_parallel_tree_learner.cpp"
#include "./src/treelearner/feature_parallel_tree_learner.cpp"
#include "./src/treelearner/serial_tree_learner.cpp"
#include "./src/treelearner/gpu_tree_learner.cpp"
#include "./src/treelearner/tree_learner.cpp"
#include "./src/treelearner/voting_parallel_tree_learner.cpp"
// c_api
#include "./src/c_api.cpp"
cp ../include ./src/include -rf
cp ../src ./src/src -rf
rm ./src/Makevars
cp ./src/Makevars_fullcode ./src/Makevars -f
R CMD build --no-build-vignettes .
\ No newline at end of file
xcopy ..\include src\include /e /i /y
xcopy ..\src src\src /e /i /y
del .\src\Makevars.win
copy .\src\Makevars_fullcode.win .\src\Makevars.win /y
R CMD build --no-build-vignettes .
\ No newline at end of file
......@@ -3,7 +3,7 @@ GPU Windows Compilation
This guide is for the MinGW build.
For the MSVC build with GPU, please refer to https://github.com/Microsoft/LightGBM/wiki/Installation-Guide#windows-2
For the MSVC (Visual Studio) build with GPU, please refer to https://github.com/Microsoft/LightGBM/wiki/Installation-Guide#windows-2
# Install LightGBM GPU version in Windows (CLI / R / Python), using MinGW/gcc
......@@ -277,253 +277,6 @@ To learn how to target a correct CPU or GPU for training, please see: [GPU SDK C
---
## LightGBM Setup and Installation for Python (Python: final step)
### Installation in Python
**Python users, extra steps**
Installing in Python is as straightforward as CLI. Assuming you already have `numpy`, `scipy`, `scikit-learn`, and `setuptools`, run the following in the Git Console:
```
cd C:/github_repos/LightGBM/python-package/
python setup.py install
```
![LightGBM with GPU support in Python](https://cloud.githubusercontent.com/assets/9083669/24957399/f14d0da2-1f8b-11e7-8f90-e8a606266265.png)
### Testing in Python
You can try to run the following demo script in Python to test if it works:
```python
import lightgbm as lgb
import pandas as pd
import os
# load or create your dataset
print('Load data...')
os.chdir('C:/github_repos/LightGBM/examples/regression')
df_train = pd.read_csv('regression.train', header=None, sep='\t')
df_test = pd.read_csv('regression.test', header=None, sep='\t')
y_train = df_train[0].values
y_test = df_test[0].values
X_train = df_train.drop(0, axis=1).values
X_test = df_test.drop(0, axis=1).values
# create dataset for lightgbm
lgb_train = lgb.Dataset(X_train, y_train)
lgb_eval = lgb.Dataset(X_test, y_test, reference=lgb_train)
# specify your configurations as a dict
params = {
'task': 'train',
'objective': 'regression',
'metric': 'l2',
'verbose': 2,
'device': 'gpu'
}
print('Start training...')
# train
gbm = lgb.train(params,
lgb_train,
num_boost_round=20,
valid_sets=lgb_eval,
early_stopping_rounds=5)
```
![LightGBM GPU in Python](https://cloud.githubusercontent.com/assets/9083669/24959269/9202a670-1f92-11e7-94a1-a7c062eaf91c.png)
Congratulations for reaching this stage!
To learn how to target a correct CPU or GPU for training, please see: [GPU SDK Correspondence and Device Targeting Table](./GPU-Targets.md).
---
## LightGBM Setup and Installation for R (R: final step)
### Preparation for R
**R users**
This gets a bit complicated for this step.
First of all, you need to to find the correct paths for the following, and keep them in a notepad:
* `BOOST_INCLUDE_DIR = "C:/boost/boost-build/include"`: if you followed the instructions, it is `C:/boost/boost-build/include`.
* `BOOST_LIBRARY = "C:/boost/boost-build/lib"`: if you followed the instructions, it is `C:/boost/boost-build/lib`.
* `OpenCL_INCLUDE_DIR = "C:/Program Files (x86)/AMD APP SDK/3.0/include"`: this varies, it must be the OpenCL SDK folder containing the file `CL/CL.h` (caps do not matter). For instance, using AMD APP SDK, it becomes `C:/Program Files (x86)/AMD APP SDK/3.0/include`.
* `OpenCL_LIBRARY = "C:/Program Files (x86)/AMD APP SDK/3.0/lib/x86_64"`: this varies, it must be the OpenCL SDK folder containing the file `OpenCL.lib` (caps do not matter). For instance, using AMD APP SDK, it becomes `C:/Program Files (x86)/AMD APP SDK/3.0/lib/x86_64`.
Second, you need to find out where is `Makeconf`, as it is the essential file you will need to use to specify the PATH for R. Run the following code to get the file path to your `Makeconf` file:
```r
file.path(R.home("etc"), "Makeconf"))
```
For instance, `"C:/PROGRA~1/MIE74D~1/RCLIEN~1/R_SERVER/etc/Makeconf"` means `"C:\Program Files\Microsoft\R_Client\R_SERVER\etc\Makeconf"`.
Third, edit the `Makeconf` file **as an Administrator**. Remember the first step we had to do where we store four different values in a notepad? We apply them right now.
For instance, for this installation and using AMD OpenCL SDK, we are doing the following below `LINKFLAGS`:
```r
BOOST_INCLUDE_DIR = "C:/boost/boost-build/include"
BOOST_LIBRARY = "C:/boost/boost-build/lib"
OpenCL_INCLUDE_DIR = "C:/Program Files (x86)/AMD APP SDK/3.0/include"
OpenCL_LIBRARY = "C:/Program Files (x86)/AMD APP SDK/3.0/lib/x86_64"
```
![Getting R Makeconf](https://cloud.githubusercontent.com/assets/9083669/24978322/8f374ac0-1fd0-11e7-9164-ace708d600cc.png)
From there, you have two solutions:
* Installation Method 1 (hard): Use your local LightGBM repository with the latest and recent development features
* Installation Method 2 (easy): Use ez_lgb, [Laurae2/LightGBM 's repository](https://github.com/Laurae2/LightGBM) for installing LightGBM easily, but it might not be up to date. It uses compute to patch boostorg/compute#704 (boostorg/compute@6de7f64)
### Installation Method 1
Edit 1 to do: you need to include proper GPU compilation support to the R package by adding the following to `R-package\src\lightgbm-all.cpp`:
```r
// gpu support
#include "../../src/treelearner/gpu_tree_learner.cpp"
```
The `lightgbm-all.cpp` becomes:
```r
// application
#include "../../src/application/application.cpp"
// boosting
#include "../../src/boosting/boosting.cpp"
#include "../../src/boosting/gbdt.cpp"
// io
#include "../../src/io/bin.cpp"
#include "../../src/io/config.cpp"
#include "../../src/io/dataset.cpp"
#include "../../src/io/dataset_loader.cpp"
#include "../../src/io/metadata.cpp"
#include "../../src/io/parser.cpp"
#include "../../src/io/tree.cpp"
// metric
#include "../../src/metric/dcg_calculator.cpp"
#include "../../src/metric/metric.cpp"
// network
#include "../../src/network/linker_topo.cpp"
#include "../../src/network/linkers_socket.cpp"
#include "../../src/network/network.cpp"
// objective
#include "../../src/objective/objective_function.cpp"
// treelearner
#include "../../src/treelearner/data_parallel_tree_learner.cpp"
#include "../../src/treelearner/feature_parallel_tree_learner.cpp"
#include "../../src/treelearner/serial_tree_learner.cpp"
#include "../../src/treelearner/tree_learner.cpp"
#include "../../src/treelearner/voting_parallel_tree_learner.cpp"
// c_api
#include "../../src/c_api.cpp"
// gpu support
#include "../../src/treelearner/gpu_tree_learner.cpp"
```
Edit 2 to do: you need to edit the `Makevars.win` in `R-package\src` appropriately by overwriting the following flags (`LGBM_RFLAGS`, `PKG_CPPFLAGS`, `PKG_LIBS`) with the following:
```r
LGBM_RFLAGS = -DUSE_SOCKET -DUSE_GPU=1
PKG_CPPFLAGS= -I$(PKGROOT)/include -I$(BOOST_INCLUDE_DIR) -I$(OpenCL_INCLUDE_DIR) -I../compute/include $(LGBM_RFLAGS)
PKG_LIBS = $(SHLIB_OPENMP_CFLAGS) $(SHLIB_PTHREAD_FLAGS) -lws2_32 -liphlpapi -L$(BOOST_LIBRARY) -lboost_filesystem -lboost_system -L$(OpenCL_LIBRARY) -lOpenCL
```
Your `Makevars.win` will look like this:
![Makevars look](https://cloud.githubusercontent.com/assets/9083669/24978371/b9124674-1fd0-11e7-8e3d-4ebb3d6340dd.png)
Or, copy & paste this:
```r
# package root
PKGROOT=../../
ENABLE_STD_THREAD=1
CXX_STD = CXX11
LGBM_RFLAGS = -DUSE_SOCKET -DUSE_GPU=1
PKG_CPPFLAGS= -I$(PKGROOT)/include -I$(BOOST_INCLUDE_DIR) -I$(OpenCL_INCLUDE_DIR) -I../compute/include $(LGBM_RFLAGS)
PKG_CXXFLAGS= $(SHLIB_OPENMP_CFLAGS) $(SHLIB_PTHREAD_FLAGS) -std=c++11
PKG_LIBS = $(SHLIB_OPENMP_CFLAGS) $(SHLIB_PTHREAD_FLAGS) -lws2_32 -liphlpapi -L$(BOOST_LIBRARY) -lboost_filesystem -lboost_system -L$(OpenCL_LIBRARY) -lOpenCL
OBJECTS = ./lightgbm-all.o ./lightgbm_R.o
```
Now, we need to install LightGBM as usual:
* Open an interactive R console.
* Assuming you have the LightGBM folder in `C:/LightGBM`, run `devtools::install("C:/github_repos/LightGBM/R-package")`.
![LightGBM installed with GPU support](https://cloud.githubusercontent.com/assets/9083669/24955074/40179df8-1f82-11e7-909b-d64e62e92641.png)
### Installation Method 2
This is very simple, as you only need to open an R interactive console and run:
```r
devtools::install_github("Laurae2/LightGBM", subdir = "R-package")
```
It will install automatically LightGBM for R with GPU support, without the need to edit manually the `Makevars.win` and `lightgbm-all.cpp`.
Laurae's LightGBM has all the steps of installation method 1 done for you. Therefore, this is a GPU-only version. You can check how many days it is behind Microsoft/LightGBM master branch and the latest master branch commit made here:
![image](https://cloud.githubusercontent.com/assets/9083669/25041428/3cacfc00-2110-11e7-8000-a783cde6f124.png)
Self-contained packages are not provided are untested. It might work but it was untested, and requires to modify the `fullcode` files instead of the regular files (`lightgbm-fullcode.cpp` and `Makevars_fullcode.win`).
### Testing in R
When you run LightGBM with a specific amount of bins, it will create the appropriate kernels. This will be obviously leading to poor performance during the first usages of LightGBM. But once the kernels are built for the number of bins you are using, you do not have to care about building them again.
Test GPU support with the following:
```r
library(lightgbm)
data(agaricus.train, package = "lightgbm")
train <- agaricus.train
dtrain <- lgb.Dataset(train$data, label = train$label)
data(agaricus.test, package = "lightgbm")
test <- agaricus.test
dtest <- lgb.Dataset.create.valid(dtrain, test$data, label = test$label)
params <- list(objective = "regression", metric = "l2", device = "gpu")
valids <- list(test = dtest)
model <- lgb.train(params,
dtrain,
100,
valids,
min_data = 1,
learning_rate = 1,
early_stopping_rounds = 10)
```
![LightGBM with GPU support running](https://cloud.githubusercontent.com/assets/9083669/24955029/0c7dc17a-1f82-11e7-8b75-89a5173f7276.png)
Congratulations for reaching this stage!
To learn how to target a correct CPU or GPU for training, please see: [GPU SDK Correspondence and Device Targeting Table](./GPU-Targets.md).
## Debugging LightGBM crashes in CLI
......
......@@ -11,7 +11,7 @@
#include <LightGBM/utils/text_reader.h>
#include <LightGBM/utils/common.h>
#include "./lightgbm_R.h"
#include <LightGBM/lightgbm_R.h>
#define COL_MAJOR (0)
......
......@@ -197,11 +197,13 @@
<ClInclude Include="..\include\LightGBM\dataset.h" />
<ClInclude Include="..\include\LightGBM\dataset_loader.h" />
<ClInclude Include="..\include\LightGBM\feature_group.h" />
<ClInclude Include="..\include\LightGBM\lightgbm_R.h" />
<ClInclude Include="..\include\LightGBM\meta.h" />
<ClInclude Include="..\include\LightGBM\metric.h" />
<ClInclude Include="..\include\LightGBM\network.h" />
<ClInclude Include="..\include\LightGBM\objective_function.h" />
<ClInclude Include="..\include\LightGBM\prediction_early_stop.h" />
<ClInclude Include="..\include\LightGBM\R_object_helper.h" />
<ClInclude Include="..\include\LightGBM\tree.h" />
<ClInclude Include="..\include\LightGBM\tree_learner.h" />
<ClInclude Include="..\include\LightGBM\utils\array_args.h" />
......@@ -254,6 +256,7 @@
<ClCompile Include="..\src\io\metadata.cpp" />
<ClCompile Include="..\src\io\parser.cpp" />
<ClCompile Include="..\src\io\tree.cpp" />
<ClCompile Include="..\src\lightgbm_R.cpp" />
<ClCompile Include="..\src\metric\dcg_calculator.cpp" />
<ClCompile Include="..\src\metric\metric.cpp" />
<ClCompile Include="..\src\network\network.cpp" />
......@@ -271,4 +274,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
\ No newline at end of file
......@@ -186,6 +186,12 @@
<ClInclude Include="..\src\metric\map_metric.hpp">
<Filter>src\metric</Filter>
</ClInclude>
<ClInclude Include="..\include\LightGBM\lightgbm_R.h">
<Filter>include\LightGBM</Filter>
</ClInclude>
<ClInclude Include="..\include\LightGBM\R_object_helper.h">
<Filter>include\LightGBM</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\src\application\application.cpp">
......@@ -266,6 +272,8 @@
<ClCompile Include="..\src\boosting\prediction_early_stop.cpp">
<Filter>src\boosting</Filter>
</ClCompile>
<ClCompile Include="..\src\lightgbm_R.cpp">
<Filter>src</Filter>
</ClCompile>
</ItemGroup>
</Project>
</Project>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment