lightgbm GPU編譯以及安裝超詳細講解

以下安裝基於Ubuntu 18.04.3 Python 3.6.8

1. lightgbm GPU編譯

點擊鏈接 找到Build GPU Version或者直接看如下內容。
下面說的內容用到相關測軟件確保沒問題,1.檢查是否安裝,2.檢查安裝版本是否滿要求!!!

Linux
On Linux GPU version of LightGBM can be built using OpenCL, Boost, CMake and gcc or Clang.

The following dependencies should be installed before compilation:

OpenCL 1.2 headers and libraries, which is usually provided by GPU manufacture.

The generic OpenCL ICD packages (for example, Debian package ocl-icd-libopencl1 and ocl-icd-opencl-dev) can also be used.

libboost 1.56 or later (1.61 or later is recommended).

We use Boost.Compute as the interface to GPU, which is part of the Boost library since version 1.61. However, since we include the source code of Boost.Compute as a submodule, we only require the host has Boost 1.56 or later installed. We also use Boost.Align for memory allocation. Boost.Compute requires Boost.System and Boost.Filesystem to store offline kernel cache.

The following Debian packages should provide necessary Boost libraries: libboost-dev, libboost-system-dev, libboost-filesystem-dev.

CMake 3.2 or later.

To build LightGBM GPU version, run the following commands:

注意:下面編譯的時候和官網給的不太一樣,咱們指定路徑就行,別讓程序找路徑。

git clone --recursive https://github.com/microsoft/LightGBM ; cd LightGBM
mkdir build ; cd build
# if you have installed NVIDIA CUDA to a customized location, you should specify paths to OpenCL headers and library like the following:
cmake -DUSE_GPU=1 -DOpenCL_LIBRARY=/usr/local/cuda/lib64/libOpenCL.so -DOpenCL_INCLUDE_DIR=/usr/local/cuda/include/ ..
# 官網用的下面的命令,咱們在此就棄用下面的改爲上面指定路徑去執行
# cmake -DUSE_GPU=1 ..
make -j4

2. 安裝其他依賴

下面流程必須走一遍,別問我爲什麼。

2.1 安裝軟件依賴
sudo apt-get install --no-install-recommends git cmake build-essential libboost-dev libboost-system-dev libboost-filesystem-dev 
2.2 安裝python庫
pip install setuptools wheel numpy scipy scikit-learn -U

如果報錯,說明問題很多,一個個去解決ok?
在這裏插入圖片描述

① 解決ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/usr/local/bin/easy_install' Consider using the–useroption or check the permissions. 問題。
對策:增加大權限,改用:

pip install setuptools wheel numpy scipy scikit-learn -U --user

②解決Python一系列版本問題ERROR: mxnet-cu100 1.5.1.post0 has requirement graphviz<0.9.0,>=0.8.1, but you'll have graphviz 0.13 which is incompatible.

ERROR: chainer 6.4.0 has requirement protobuf<3.8.0rc1,>=3.0.0, but you'll have protobuf 3.10.0 which is incompatible.

ERROR: chainer 6.4.0 has requirement typing<=3.6.6, but you'll have typing 3.7.4.1 which is incompatible.
對策:上面三個py庫版本過高,重新安裝

# 卸
pip uninstall graphviz
# 安
pip install graphviz==0.8.2 --user

# 卸
pip uninstall protobuf
# 安
pip install protobuf==3.7.0 --user

# 卸
pip uninstall typing
# 安
pip install typing==3.6.6 --user

如果有卸載不了的直接安吧。

2.3 安裝lightGBM-GPU
sudo pip install lightgbm --install-option=--gpu --install-option="--opencl-include-dir=/usr/local/cuda/include/" --install-option="--opencl-library=/usr/local/cuda/lib64/libOpenCL.so"

3. 測試

測試代碼省略,如果遇到python腳本報錯
Error: No OpenCL Device Found
對策:

# 終端手動添加路徑文件
mkdir -p /etc/OpenCL/vendors && echo "libnvidia-opencl.so.1" > /etc/OpenCL/vendors/nvidia.icd

如果執行上面命令報錯:mkdir: cannot create directory '/etc/OpenCL': Permission denied

改用root權限:

# 終端手動添加路徑文件
sudo mkdir -p /etc/OpenCL/vendors && echo "libnvidia-opencl.so.1" > /etc/OpenCL/vendors/nvidia.icd

如果還是沒權限-bash: /etc/OpenCL/vendors/nvidia.icd: Permission denied,並且你不知道root密碼,就去改密碼吧,哈哈。。。。


# 切換到root用戶創建
su

# 如果root用戶不知道密碼,那你就改,責任自己承擔,哈哈
sudo passwd

上面權限解決了,就完全ok了。
重啓機器,再次測試。如果還是不行,請自行搜索,或者推倒重新來一遍。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章