Ubuntu16.04安装GPU版xgboost

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Perfect_Accepted/article/details/81989486

首先需要声明:xgboost的GPU版需要CUDA8.0以上与英伟达显卡计算能力3.5以上(查看显卡计算能力:http://https//developer.nvidia.com/cuda-gpus)。如果不满足,请放弃!!!

CUDA8.0支持Ubuntu16.0的5.4GCC,因此不需要进行降级。

ubuntu安装xgboost CPU版

第一种方法采用pip安装:

pip install xgboost

出现如下报错:Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-aLZ4rC/xgboost/

百度了几乎所有关于pip安装xgboost的方法都不行。实在时太坑了,后采用第二种git源码安装成功。

第二种git源码安装:

第一步从git安装源码:会在主文件夹下出现一个xgboost文件

$git clone --recursive https://github.com/dmlc/xgboost

第二步编译:这里需要高级的GCC版本,我原本好像gcc版本时4.7的编译一直出错,后来升级gcc到4.9版本成功编译,升级方法可以参考GCC升级

 
  1. $cd xgboost

  2. $make -j4

第三步安装python包,在xgboost目录下cd 到python-package

 
  1. $cd python-package

  2. $sudo python setup.py install

执行完上面步骤后,就可以使用CPU版本的xgboost了,如果你嫌CPU跑的太慢,下面是GPU的安装教程,前提是你有一块好的显卡,并且安装了CUDA8.0.

GPU版配置。

安装官方的步骤

先cd到xgboost目录下,然后执行下面的几行命令

  1. $ mkdir build

  2. $ cd build

  3. $ cmake .. -DUSE_CUDA=ON

  4. $ make -j

如果能成功执行上面几步,在执行下一步,官方文档中,没有下面这一步骤,是因为是从安装xgboost到GPU版本是一步到位的,如果你是先安装的CPU版本,并且后面才打算使用GPU,那么除了官方的几步后还必须使用下面的步骤,我就是在这步卡了很久,明明按照官方步骤来,却一直无法使用GPU,后来突然灵光一闪,使用下面命令就可以了。

  1. $cd python-package

  2. $sudo python setup.py install

测试GPU
在tests\benchmark目录下

分别执行

  1. python benchmark.py --tree_method gpu_hist

  2. python benchmark.py --tree_method hist

  3. python benchmark.py --tree_method gpu_exact

  4. python benchmark.py --tree_method exact

我只执行了上面两个用时分别是34s和134s,可以看到GPU跑起来还是很快。

在实际的代码中,只要在添加下面的参数就行了

param['tree_method'] = 'gpu_hist'

如果你的显卡满足计算能力在3.5之上,可是出现error:

terminate called after throwing an instance of 'thrust::system :: xgboost with GPU on Ubuntu16.04
What(): function_attributes(): after cudaFuncGetAttributes: invalid device function

这时候,更改文件:xgboost/cmake/Utils.cmake

Line 65 in 4ed8a88

 

set(flags "35;50;52;60;61")

改为: set(flags "xx;35;50;52;60;61")

and re-compile XGBoost. (Notice the added number xx. This is to account for older cards.) 

猜你喜欢

转载自blog.csdn.net/Perfect_Accepted/article/details/81989486