From 70b1bc60f5cb05efc32743a241103ed09dd6c761 Mon Sep 17 00:00:00 2001 From: Laurae Date: Fri, 30 Jun 2017 08:36:31 +0200 Subject: [PATCH 01/13] Change VS -> MinGW for CRAN --- R-package/src/install.libs.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R-package/src/install.libs.R b/R-package/src/install.libs.R index 6b7f28d37e07..77a119590c0d 100644 --- a/R-package/src/install.libs.R +++ b/R-package/src/install.libs.R @@ -1,7 +1,7 @@ # User options use_precompile <- FALSE use_gpu <- FALSE -use_mingw <- FALSE +use_mingw <- TRUE if (.Machine$sizeof.pointer != 8){ stop("Only support 64-bit R, please check your the version of your R and Rtools.") From 757071505e8798f816760c2aa7837683b988682a Mon Sep 17 00:00:00 2001 From: Laurae Date: Fri, 30 Jun 2017 08:47:20 +0200 Subject: [PATCH 02/13] Documentation to switch to MinGW by default --- R-package/README.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/R-package/README.md b/R-package/README.md index ea07c90ea42e..e9b992de9acd 100644 --- a/R-package/README.md +++ b/R-package/README.md @@ -7,11 +7,11 @@ Installation ### 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 Rtools (default) or [MinGW64](https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/) (x86_64-posix-seh) to compile by setting `use_mingw` to `TRUE` in `R-package/src/install.libs.R`. For MinGW users who wants to install online, please check the end of this document for installation using a helper package ([Laurae2/lgbdl](https://github.com/Laurae2/lgbdl/)). +The default compiler is gcc (Linux) or Rtools' MinGW (Windows). You may also compile with Visual Studio (or [MS Build](https://www.visualstudio.com/downloads/#build-tools-for-visual-studio-2017)) by setting `use_mingw` to `TRUE` in `R-package/src/install.libs.R`. It is also possible to compile with [MinGW64](https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/) (x86_64-posix-seh) in Windows. For Visual Studio users who wants to install online, please check the end of this document for installation using a helper package ([Laurae2/lgbdl](https://github.com/Laurae2/lgbdl/)). It is recommended to use *Visual Studio* for its better multi-threading efficency in Windows for many core systems. For very simple systems (dual core computers or worse), MinGW64 is recommended for maximum performance. If you do not know what to choose, it is recommended to use [Visual Studio](https://www.visualstudio.com/downloads/#build-tools-for-visual-studio-2017). -For Windows users, installing [Rtools](https://cran.r-project.org/bin/windows/Rtools/) is mandatory. +For Windows users, installing [Rtools](https://cran.r-project.org/bin/windows/Rtools/) is mandatory even when using Visual Studio compilation. For Mac OS X users, gcc with OpenMP support must be installed first. Refer to [wiki](https://github.com/Microsoft/LightGBM/wiki/Installation-Guide#osx) for installing gcc with OpenMP support. @@ -81,13 +81,12 @@ In addition, if you are using a Visual Studio precompiled DLL, assuming you do n Once you have all this setup, you can use `lgb.dl` from `lgbdl` package to install LightGBM from repository. -For instance, you can install the R package from LightGBM master commit of GitHub using the following from R: +For instance, you can install the R package from LightGBM master commit of GitHub with Visual Studio using the following from R: ```r lgb.dl(commit = "master", - compiler = "gcc", - repo = "https://github.com/Microsoft/LightGBM", - cores = 4) + compiler = "vs", + repo = "https://github.com/Microsoft/LightGBM") ``` You may also install using a precompiled dll/lib using the following from R: From 2c5ea8e992ef4dca99f54c46fea2ebe3c46eec0a Mon Sep 17 00:00:00 2001 From: Laurae Date: Thu, 6 Jul 2017 08:54:18 +0200 Subject: [PATCH 03/13] Force cmake to run twice --- R-package/src/install.libs.R | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/R-package/src/install.libs.R b/R-package/src/install.libs.R index 77a119590c0d..9d33ccd9c5a5 100644 --- a/R-package/src/install.libs.R +++ b/R-package/src/install.libs.R @@ -43,7 +43,7 @@ if (!use_precompile) { # Prepare installation steps cmake_cmd <- "cmake " - build_cmd <- "make _lightgbm -j4" + build_cmd <- "make _lightgbm -j" lib_folder <- file.path(R_PACKAGE_SOURCE, "src", fsep = "/") # Check if Windows installation (for gcc vs Visual Studio) @@ -64,6 +64,9 @@ if (!use_precompile) { # Install system(paste0(cmake_cmd, " ..")) + if (WINDOWS && use_mingw) { + system(build_cmd) # Must build twice for Windows due sh.exe in Rtools + } system(build_cmd) src <- file.path(lib_folder, paste0("lib_lightgbm", SHLIB_EXT), fsep = "/") From 4098fc1af127df4725b1c43855322186d6385484 Mon Sep 17 00:00:00 2001 From: Laurae Date: Thu, 6 Jul 2017 09:00:52 +0200 Subject: [PATCH 04/13] Try again dual build for Rtools --- R-package/src/install.libs.R | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/R-package/src/install.libs.R b/R-package/src/install.libs.R index 9d33ccd9c5a5..78545341001f 100644 --- a/R-package/src/install.libs.R +++ b/R-package/src/install.libs.R @@ -50,7 +50,8 @@ if (!use_precompile) { if (WINDOWS) { if (use_mingw) { cmake_cmd <- paste0(cmake_cmd, " -G \"MinGW Makefiles\" ") - build_cmd <- "mingw32-make.exe _lightgbm -j4" + build_cmd <- "mingw32-make.exe _lightgbm -j" + system(build_cmd) # Must build twice for Windows due sh.exe in Rtools } else { cmake_cmd <- paste0(cmake_cmd, " -DCMAKE_GENERATOR_PLATFORM=x64 ") build_cmd <- "cmake --build . --target _lightgbm --config Release" @@ -64,9 +65,6 @@ if (!use_precompile) { # Install system(paste0(cmake_cmd, " ..")) - if (WINDOWS && use_mingw) { - system(build_cmd) # Must build twice for Windows due sh.exe in Rtools - } system(build_cmd) src <- file.path(lib_folder, paste0("lib_lightgbm", SHLIB_EXT), fsep = "/") From 48f8f4407f9fd151f86a9c3d4ef6a173e2d7b3ae Mon Sep 17 00:00:00 2001 From: Laurae Date: Thu, 6 Jul 2017 09:02:51 +0200 Subject: [PATCH 05/13] Switch to cmake for building twice --- R-package/src/install.libs.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R-package/src/install.libs.R b/R-package/src/install.libs.R index 78545341001f..c7524d336c6d 100644 --- a/R-package/src/install.libs.R +++ b/R-package/src/install.libs.R @@ -51,7 +51,7 @@ if (!use_precompile) { if (use_mingw) { cmake_cmd <- paste0(cmake_cmd, " -G \"MinGW Makefiles\" ") build_cmd <- "mingw32-make.exe _lightgbm -j" - system(build_cmd) # Must build twice for Windows due sh.exe in Rtools + system(paste0(cmake_cmd, " ..")) # Must build twice for Windows due sh.exe in Rtools } else { cmake_cmd <- paste0(cmake_cmd, " -DCMAKE_GENERATOR_PLATFORM=x64 ") build_cmd <- "cmake --build . --target _lightgbm --config Release" From ed00f7bae2849e0a8e80fc307536b2ffb7602a96 Mon Sep 17 00:00:00 2001 From: Laurae Date: Thu, 13 Jul 2017 17:27:13 +0200 Subject: [PATCH 06/13] Try with Visual Studio as default, MinGW as fallback --- R-package/src/install.libs.R | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/R-package/src/install.libs.R b/R-package/src/install.libs.R index c7524d336c6d..c7f575091ac7 100644 --- a/R-package/src/install.libs.R +++ b/R-package/src/install.libs.R @@ -1,7 +1,7 @@ # User options use_precompile <- FALSE use_gpu <- FALSE -use_mingw <- TRUE +use_mingw <- FALSE if (.Machine$sizeof.pointer != 8){ stop("Only support 64-bit R, please check your the version of your R and Rtools.") @@ -42,18 +42,24 @@ if (!use_precompile) { setwd(build_dir) # Prepare installation steps - cmake_cmd <- "cmake " + cmake_base <- "cmake " build_cmd <- "make _lightgbm -j" lib_folder <- file.path(R_PACKAGE_SOURCE, "src", fsep = "/") # Check if Windows installation (for gcc vs Visual Studio) if (WINDOWS) { if (use_mingw) { - cmake_cmd <- paste0(cmake_cmd, " -G \"MinGW Makefiles\" ") + cmake_cmd <- paste0(cmake_base, " -G \"MinGW Makefiles\" ") build_cmd <- "mingw32-make.exe _lightgbm -j" system(paste0(cmake_cmd, " ..")) # Must build twice for Windows due sh.exe in Rtools } else { - cmake_cmd <- paste0(cmake_cmd, " -DCMAKE_GENERATOR_PLATFORM=x64 ") + cmake_cmd <- paste0(cmake_base, " -DCMAKE_GENERATOR_PLATFORM=x64 ") + tryVS <- system(paste0(cmake_cmd, " .."), intern = TRUE) + cat(tryVS, "\n", sep = "") # try building with Visual Studio + if (regexpr("(does not support platform specification, but platform)", tryVS) != -1) { + cmake_cmd <- paste0(cmake_base, " -G \"MinGW Makefiles\" ") # Switch to MinGW on failure, try build once + system(paste0(cmake_cmd, " ..")) # Must build twice for Windows due sh.exe in Rtools + } build_cmd <- "cmake --build . --target _lightgbm --config Release" lib_folder <- file.path(R_PACKAGE_SOURCE, "src/Release", fsep = "/") } From 2914c1ff76051d5db3e2d5ba12b0412f0b3d782d Mon Sep 17 00:00:00 2001 From: Laurae Date: Thu, 13 Jul 2017 17:35:23 +0200 Subject: [PATCH 07/13] Try to remove VS appropriately when failing --- R-package/src/install.libs.R | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/R-package/src/install.libs.R b/R-package/src/install.libs.R index c7f575091ac7..6924334a26aa 100644 --- a/R-package/src/install.libs.R +++ b/R-package/src/install.libs.R @@ -54,9 +54,8 @@ if (!use_precompile) { system(paste0(cmake_cmd, " ..")) # Must build twice for Windows due sh.exe in Rtools } else { cmake_cmd <- paste0(cmake_base, " -DCMAKE_GENERATOR_PLATFORM=x64 ") - tryVS <- system(paste0(cmake_cmd, " .."), intern = TRUE) - cat(tryVS, "\n", sep = "") # try building with Visual Studio - if (regexpr("(does not support platform specification, but platform)", tryVS) != -1) { + tryVS <- system(paste0(cmake_cmd, " ..")) + if (tryVS == 1) { cmake_cmd <- paste0(cmake_base, " -G \"MinGW Makefiles\" ") # Switch to MinGW on failure, try build once system(paste0(cmake_cmd, " ..")) # Must build twice for Windows due sh.exe in Rtools } From 52276e6f9e446ce5b0b64ca86702168669ce0305 Mon Sep 17 00:00:00 2001 From: Laurae Date: Thu, 13 Jul 2017 17:39:58 +0200 Subject: [PATCH 08/13] Attempt to get rid of build folder first --- R-package/src/install.libs.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R-package/src/install.libs.R b/R-package/src/install.libs.R index 6924334a26aa..472e3a429966 100644 --- a/R-package/src/install.libs.R +++ b/R-package/src/install.libs.R @@ -56,6 +56,7 @@ if (!use_precompile) { cmake_cmd <- paste0(cmake_base, " -DCMAKE_GENERATOR_PLATFORM=x64 ") tryVS <- system(paste0(cmake_cmd, " ..")) if (tryVS == 1) { + system("rm -rf .") cmake_cmd <- paste0(cmake_base, " -G \"MinGW Makefiles\" ") # Switch to MinGW on failure, try build once system(paste0(cmake_cmd, " ..")) # Must build twice for Windows due sh.exe in Rtools } From 9557b6151817a10376023dc634737ab75440d52e Mon Sep 17 00:00:00 2001 From: Laurae Date: Thu, 13 Jul 2017 17:45:30 +0200 Subject: [PATCH 09/13] Switch to unlink from rm rf --- R-package/src/install.libs.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R-package/src/install.libs.R b/R-package/src/install.libs.R index 472e3a429966..fc015e49ebd6 100644 --- a/R-package/src/install.libs.R +++ b/R-package/src/install.libs.R @@ -56,7 +56,7 @@ if (!use_precompile) { cmake_cmd <- paste0(cmake_base, " -DCMAKE_GENERATOR_PLATFORM=x64 ") tryVS <- system(paste0(cmake_cmd, " ..")) if (tryVS == 1) { - system("rm -rf .") + unlink("./*", recursive = TRUE) # Clean up build directory cmake_cmd <- paste0(cmake_base, " -G \"MinGW Makefiles\" ") # Switch to MinGW on failure, try build once system(paste0(cmake_cmd, " ..")) # Must build twice for Windows due sh.exe in Rtools } From 6a4c23c39d1ddf3b1cfbf98a78137cf7b8f63eba Mon Sep 17 00:00:00 2001 From: Laurae Date: Thu, 13 Jul 2017 17:51:26 +0200 Subject: [PATCH 10/13] Change lib_folder correctly when VS fails --- R-package/src/install.libs.R | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/R-package/src/install.libs.R b/R-package/src/install.libs.R index fc015e49ebd6..1b73eaeb36f2 100644 --- a/R-package/src/install.libs.R +++ b/R-package/src/install.libs.R @@ -59,9 +59,11 @@ if (!use_precompile) { unlink("./*", recursive = TRUE) # Clean up build directory cmake_cmd <- paste0(cmake_base, " -G \"MinGW Makefiles\" ") # Switch to MinGW on failure, try build once system(paste0(cmake_cmd, " ..")) # Must build twice for Windows due sh.exe in Rtools + build_cmd <- "mingw32-make.exe _lightgbm -j" + } else { + build_cmd <- "cmake --build . --target _lightgbm --config Release" + lib_folder <- file.path(R_PACKAGE_SOURCE, "src/Release", fsep = "/") } - build_cmd <- "cmake --build . --target _lightgbm --config Release" - lib_folder <- file.path(R_PACKAGE_SOURCE, "src/Release", fsep = "/") } } From 31bbe8481a2a73445756fbd51688305d4ff8c0b6 Mon Sep 17 00:00:00 2001 From: Laurae Date: Thu, 13 Jul 2017 17:56:50 +0200 Subject: [PATCH 11/13] Add README updates from Microsoft/LightGBM@1c8355c --- R-package/README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/R-package/README.md b/R-package/README.md index 7511553b6794..785272899ea1 100644 --- a/R-package/README.md +++ b/R-package/README.md @@ -33,7 +33,7 @@ Install LightGBM R-package with the following command: ```sh git clone --recursive https://github.com/Microsoft/LightGBM cd LightGBM/R-package -R CMD INSTALL --build . +R CMD INSTALL --build . --no-multiarch ``` Or build a self-contained R package which can be installed afterwards: @@ -42,7 +42,7 @@ Or build a self-contained R package which can be installed afterwards: git clone --recursive https://github.com/Microsoft/LightGBM cd LightGBM/R-package Rscript build_package.R -R CMD INSTALL lightgbm_2.0.2.tar.gz +R CMD INSTALL lightgbm_2.0.2.tar.gz --no-multiarch ``` Note: for the build with Visual Studio/MSBuild in Windows, you should use the Windows CMD or Powershell. @@ -54,7 +54,9 @@ Set `use_gpu` to `TRUE` in `R-package/src/install.libs.R` to enable the build wi You can also install directly from R using the repository with `devtools`: ```r -devtools::install_github("Microsoft/LightGBM", subdir = "R-package") +library(devtools) +options(devtools.install.args = "--no-multiarch") # if you have 64-bit R only, you can skip this +install_github("Microsoft/LightGBM", subdir = "R-package") ``` If you are using a precompiled dll/lib locally, you can move the dll/lib into LightGBM root folder, modify `LightGBM/R-package/src/install.libs.R`'s 2nd line (change `use_precompile <- FALSE` to `use_precompile <- TRUE`), and install R-package as usual. From 91bcdb3aa612565ce14997dca518d74532ad8258 Mon Sep 17 00:00:00 2001 From: Laurae Date: Thu, 13 Jul 2017 18:03:44 +0200 Subject: [PATCH 12/13] Update default compiler doc and add GPU online install doc --- R-package/README.md | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/R-package/README.md b/R-package/README.md index 785272899ea1..36b46e9ba0fa 100644 --- a/R-package/README.md +++ b/R-package/README.md @@ -16,11 +16,13 @@ Installing [Rtools](https://cran.r-project.org/bin/windows/Rtools/) is mandatory [cmake](https://cmake.org/) must be version 3.8 or higher. -The default compiler is Rtools or any [MinGW64](https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/) (x86_64-posix-seh) to compile by setting `use_mingw` to `TRUE` in `R-package/src/install.libs.R`. You also can use Visual Studio (or [MS Build](https://www.visualstudio.com/downloads/#build-tools-for-visual-studio-2017)) in Windows. +The default compiler is Visual Studio (or [MS Build](https://www.visualstudio.com/downloads/#build-tools-for-visual-studio-2017)) in Windows, with an automatic fallback to Rtools or any [MinGW64](https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/) (x86_64-posix-seh) available (this means if you have only Rtools and cmake, it will compile fine). -For Visual Studio users who wants to install online, please check the end of this document for installation using a helper package ([Laurae2/lgbdl](https://github.com/Laurae2/lgbdl/)). +To force the usage of Rtools / MinGW, you can set `use_mingw` to `TRUE` in `R-package/src/install.libs.R`. -It is recommended to use *Visual Studio* for its better multi-threading efficency in Windows for many core systems. For very simple systems (dual core computers or worse), MinGW64 is recommended for maximum performance. If you do not know what to choose, it is recommended to use [Visual Studio](https://www.visualstudio.com/downloads/#build-tools-for-visual-studio-2017). +For users who wants to install online with GPU, please check the end of this document for installation using a helper package ([Laurae2/lgbdl](https://github.com/Laurae2/lgbdl/)). + +It is recommended to use *Visual Studio* for its better multi-threading efficency in Windows for many core systems. For very simple systems (dual core computers or worse), MinGW64 is recommended for maximum performance. If you do not know what to choose, it is recommended to use [Visual Studio](https://www.visualstudio.com/downloads/#build-tools-for-visual-studio-2017), the default compiler. #### Mac OS X Preparation @@ -111,6 +113,14 @@ lgb.dl(commit = "master", repo = "https://github.com/Microsoft/LightGBM") ``` +You may also install online using a LightGBM with proper GPU support using the following from R: + +```r +lgb.dl(commit = "master", + repo = "https://github.com/Microsoft/LightGBM", + use_gpu = TRUE) +``` + For more details about options, please check [Laurae2/lgbdl](https://github.com/Laurae2/lgbdl/) R-package. Examples From 9ccac03cd46075f76f95f5c1e19d1837f431f2f3 Mon Sep 17 00:00:00 2001 From: Laurae Date: Thu, 13 Jul 2017 18:05:41 +0200 Subject: [PATCH 13/13] Better GPU doc --- R-package/README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/R-package/README.md b/R-package/README.md index 36b46e9ba0fa..ff7136bba07b 100644 --- a/R-package/README.md +++ b/R-package/README.md @@ -20,7 +20,7 @@ The default compiler is Visual Studio (or [MS Build](https://www.visualstudio.co To force the usage of Rtools / MinGW, you can set `use_mingw` to `TRUE` in `R-package/src/install.libs.R`. -For users who wants to install online with GPU, please check the end of this document for installation using a helper package ([Laurae2/lgbdl](https://github.com/Laurae2/lgbdl/)). +For users who wants to install online with GPU or want to choose a specific compiler, please check the end of this document for installation using a helper package ([Laurae2/lgbdl](https://github.com/Laurae2/lgbdl/)). It is recommended to use *Visual Studio* for its better multi-threading efficency in Windows for many core systems. For very simple systems (dual core computers or worse), MinGW64 is recommended for maximum performance. If you do not know what to choose, it is recommended to use [Visual Studio](https://www.visualstudio.com/downloads/#build-tools-for-visual-studio-2017), the default compiler. @@ -113,10 +113,11 @@ lgb.dl(commit = "master", repo = "https://github.com/Microsoft/LightGBM") ``` -You may also install online using a LightGBM with proper GPU support using the following from R: +You may also install online using a LightGBM with proper GPU support using Visual Studio (as an example here) using the following from R: ```r lgb.dl(commit = "master", + compiler = "vs", # Remove this for MinGW + GPU installation repo = "https://github.com/Microsoft/LightGBM", use_gpu = TRUE) ```