You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows 11环境下R语言中GPU版XGBoost安装失败求助

解决Windows 11下R语言安装GPU版XGBoost的编译错误

结论

Windows 11的R语言完全可以使用GPU版XGBoost,不建议手动编译源码(容易踩依赖坑),优先用预编译二进制包;如果一定要编译,需要处理子模块依赖。

方法1:使用预编译二进制包(推荐)

直接安装带GPU支持的预编译版本,跳过编译流程:

install.packages("xgboost", repos = "https://cloud.r-project.org", type = "binary")

安装完成后验证GPU功能:

library(xgboost)
# 检查GPU是否可用
print(xgb.gpu.available())
# 运行GPU训练示例
data(agaricus.train, package='xgboost')
train <- agaricus.train
bst <- xgboost(data = train$data, label = train$label, max_depth = 2, 
               eta = 1, nthread = 2, nrounds = 2, objective = "binary:logistic",
               tree_method = "gpu_hist") # 指定GPU训练模式

若上述二进制包未包含GPU支持,可通过conda环境安装:

  1. 激活你的R对应conda环境
  2. 执行终端命令:
conda install -c conda-forge r-xgboost-gpu

之后在R中加载包即可使用GPU功能。

方法2:修复源码编译的依赖问题(适合自定义编译场景)

你遇到的dmlc/common.h找不到的问题,根源是GitHub仓库的子模块(dmlc-core、rabit等)未被自动拉取,解决步骤:

  1. 手动克隆仓库并拉取所有子模块:
git clone --recursive https://github.com/dmlc/xgboost.git
  1. 在R中指定本地路径安装,带上GPU编译参数:
remotes::install_local("你的xgboost克隆路径/R-package", configure.args = "--use-gpu")
  1. 编译前确认环境满足:
    • CUDA版本与XGBoost兼容(建议CUDA 11.x或12.x)
    • Rtools版本匹配你的R版本(如R4.3对应Rtools43)
    • 系统环境变量已配置CUDA_PATH指向CUDA安装目录

内容的提问来源于stack exchange,提问作者james_rodriguez

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 03:42:51