前言
MXNet预编译包目前支持CUDA8.0至CUDA11.0等常用版本,可以直接通过pip安装。而在新的GeForce 3090显卡上,如果安装了CUDA11.1,则无法采用这种便捷方式安装MXNet。通过查找资料,发现可以通过源码安装的方式兼容CUDA11.1。
安装
-
下载源码
git clone --recursive https://github.com/apache/incubator-mxnet mxnet cd mxnet git checkout 1.8.0.rc2
若采用下面这种方式下载源码的话,则需要额外下载子模块。
git clone https://github.com/apache/incubator-mxnet.git mxnet cd mxnet git submodule update --init --recursive git checkout 1.8.0.rc2
-
下载依赖库
sudo apt-get update sudo apt-get install -y build-essential git ninja-build ccache libopenblas-dev libopencv-dev cmake sudo apt install gfortran
-
修改编译选项
cp make/config.mk . vi config.mk
打开CUDA支持:
USE_CUDA = 1 USE_CUDA_PATH = /usr/local/cuda
-
增加3090显卡算力代码(86)
vi Makefile
KNOWN_CUDA_ARCHS := 30 35 50 52 60 61 70 75 80 86
-
编译
make 或 make -j8 或 make -$(nproc) [推荐]
-
安装Python支持
正常情况下,编译很长一段时间后,最后出现下面提示后说明编译通过。Finished processing dependencies for mxnet==1.8.0
通过下面命令生成Python支持:
cd python python setup.py install
-
测试
>>> import mxnet as mx >>> a=mx.nd.ones((2,3),mx.cpu()) >>> print((a*2).asnumpy()) [[2. 2. 2.] [2. 2. 2.]]
问题汇总
源码编译过程中可能会出现下面的问题,做个记录:
-
缺少BLAS
报错/usr/bin/ld: cannot find -lcblas
,
采用sudo apt-get install libatlas-base-dev
解决。
-
Git工程缺少子模块
Makefile:23: mshadow/make/mshadow.mk: No such file or directory Makefile:24: /home/usr/incubator-mxnet-0.7.0/dmlc-core/make/dmlc.mk: No such file or directory Makefile:86: /home/usr/incubator-mxnet-0.7.0/ps-lite/make/ps.mk: No such file or directory make: *** No rule to make target `/home/usr/incubator-mxnet-0.7.0/ps-lite/make/ps.mk'. Stop.
需要拉取子模块:
git submodule update --init --recursive
-
测试通过的版本是Tag 1.8.0.rc2,下载工程后需要
git checkout 1.8.0.rc2
-
CUDA11.0的mxnet可以直接安装mxnet-cu110
pip install mxnet-cu110==1.9.0b20201117 -f https://dist.mxnet.io/python/cu110
注:更多安装包可以直接通过https://dist.mxnet.io/python/获取。
参考资料
[1] GitHub - apache / incubator-mxnet
[2] mxnet包官网分发
[3] GitHub issues - apache / incubator-mxnet - Using mxnet on RTX3090 #19520
[4] Build MXNet from Source
[5] Mxnet编译安装
[6] Install MxNet from sources on Ubuntu
[7] sudo apt-get install libatlas-base-dev