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了。
重启机器,再次测试。如果还是不行,请自行搜索,或者推倒重新来一遍。

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