Linux下安装Xgboost并支持GPU

Phedra ·
更新时间:2024-09-21
· 657 次阅读

Linux下安装Xgboost并支持GPU下载源码支持GPU正常流程报错:nvcc fatal : redefinition of argument 'std'查看本机cmake版本查找报错原因确认报错原因解决办法安装Python支持查看安装包 下载源码 git clone --recursive https://github.com/dmlc/xgboost #若安装CPU版,直接执行以下命令 cd xgboost make -j4 支持GPU 正常流程 $ cd xgboost $ mkdir build $ cd build $ cmake .. -DUSE_CUDA=ON

切记:不要返回上一层目录(不要执行cd …)

直接执行:

$ make -j4 报错:nvcc fatal : redefinition of argument ‘std’

原因:编译参数中重复出现 -std=c++11

上网搜索的主要原因是:cmake版本新旧导致。

查看本机cmake版本 $ cmake --version cmake version 3.17.0-rc2 CMake suite maintained and supported by Kitware (kitware.com/cmake).

本机cmake版本是3.17

查看CMakeList.txt要求版本:

$ vim CMakeLists.txt

结果

cmake_minimum_required(VERSION 3.12)

要求3.12以上,按道理符合要求

查找报错原因 $ rm -rf * #删除build路径下的所有文件和文件夹 $ cmake .. -DUSE_CUDA=ON #重新cmake $ make -j4 VERBOSE=1 #make同时打印信息 确认报错原因 [ 76%] Building CUDA object src/CMakeFiles/objxgboost.dir/c_api/c_api.cu.o cd /home/zhendongwu/molecule/xgboost/build/src && /usr/local/cuda-10.0/bin/nvcc -ccbin=/usr/local/bin/c++ -DDMLC_LOG_CUSTOMIZE=1 -DXGBOOST_BUILTIN_PREFETCH_PRESENT=1 -DXGBOOST_MM_PREFETCH_PRESENT=1 -DXGBOOST_USE_CUDA=1 -D_MWAITXINTRIN_H_INCLUDED -I/home/zhendongwu/molecule/xgboost/cub -I/home/zhendongwu/molecule/xgboost/include -I/home/zhendongwu/molecule/xgboost/dmlc-core/include -I/home/zhendongwu/molecule/xgboost/rabit/include -O3 -DNDEBUG -Xcompiler=-fPIC --expt-extended-lambda --expt-relaxed-constexpr -lineinfo --std=c++11 --generate-code=arch=compute_35,code=sm_35 --generate-code=arch=compute_50,code=sm_50 --generate-code=arch=compute_52,code=sm_52 --generate-code=arch=compute_60,code=sm_60 --generate-code=arch=compute_61,code=sm_61 --generate-code=arch=compute_70,code=sm_70 --generate-code=arch=compute_75,code=sm_75 --generate-code=arch=compute_75,code=compute_75 -Xcompiler=-fopenmp -std=c++11 -x cu -c /home/zhendongwu/molecule/xgboost/src/c_api/c_api.cu -o CMakeFiles/objxgboost.dir/c_api/c_api.cu.o nvcc fatal : redefinition of argument 'std' make[2]: *** [src/CMakeFiles/objxgboost.dir/c_api/c_api.cu.o] Error 1 make[2]: *** Waiting for unfinished jobs.... make[2]: Leaving directory `/home/zhendongwu/molecule/xgboost/build' make[1]: *** [src/CMakeFiles/objxgboost.dir/all] Error 2 make[1]: Leaving directory `/home/zhendongwu/molecule/xgboost/build' make: *** [all] Error 2

从信息中可以看出,确实存在2个 -std=c++11

解决办法

找到 xgboost/src/ CMakeList.txt文件

$ vim ../src/CMakeLists.txt

删除带有-std=c++11的那一行

$<$<AND:$<NOT:$>,$>:--std=c++11>

重新编译,顺利通过

安装Python支持 $ cd python-package $ sudo python setup.py install 查看安装包 $ pip list xgboost 1.1.0-SNAPSHOT

大功告成,可以使用GPU支持的 Xgboost 了 !


作者:东子YouOnlyLiveOnce



xgboost Linux

需要 登录 后方可回复, 如果你还没有账号请 注册新账号