大家好,我是极智视界,本文介绍一下 昇腾开发环境搭建 CANN & MindStudio,没有坑。
本文介绍的方法适用于:
- 系统:ubuntu18.04 (注:[centos7.6 类似])
- 昇腾卡:Atlas300I Pro、Atlas300I(3000 & 3010) (注:[这些卡都尝试过,没毛病])
这里以 ubuntu1804、Atlas300I (3010) 为例, 话不多说,直接开始。
1. 系统安装
ubuntu18.04 系统安装,可以采用 u盘启动安装,略过。
2. 安装包下载
安装包主要分为:固件与驱动、CANN、MindStudio,如下:
固件与驱动下载地址:driver & firmware
CANN下载地址:cann
MindStudio下载地址:mindstudio
昇腾有个比较麻烦的地方:要是你要下载商用版需要申请,比较麻烦。这里咱们以社区版的安装包为例进行,下载好这些文件 (我这里是 x86 的,如果你是 arm 的机器就下载 arm 版本的):
3. 安装依赖
创建 HwHiAiUser 用户 (如果你是用 root 用户进行依赖安装的话,可以忽略这一点):
# 创建 HwHiAiUser 用户组 sudo groupadd HwHiAiUser # 创建 HwHiAiUser 用户 sudo useradd -g HwHiAiUser -r -m -s /bin/bash HwHiAiUser
这个时候你 ls /home
已经能够发现有了 HwHiAiUser 用户目录了。
华为的开发环境强依赖于 python3.7.5,所以我们得先装上它。这里不选择采用源码安装的方式 (采用源码编译安装,后面可能会遇到挺多坑),而采用先装 Anaconda3,然后用 conda 安装 python3.7.5 环境。同样安装 Anaconda3 略过,附上不限速下载源:anaconda。
# 使用conda管理python3.7.5环境 # 创建 python3.7.5 环境 conda create -n conda_py375 python=3.7.5 # 安装 python 依赖 conda activate conda_py375 pip install attrs \ psutil \ decorator \ numpy \ protobuf==3.11.3 \ scipy \ sympy \ cffi \ grpcio \ grpcio-tools \ requests # 安装驱动依赖 sudo apt -y update sudo apt-get install -y gcc \ g++ \ make \ cmake \ zlib1g \ zlib1g-dev \ libsqlite3-dev \ openssl \ libssl-dev \ libffi-dev \ unzip \ pciutils \ net-tools \ dkms
4. 开始安装
# 切到 root 用户 su root # 安装驱动 chmod +x ./A300-3010-npu-driver_5.1.rc2_linux-x86_64.run ./A300-3010-npu-driver_5.1.rc2_linux-x86_64.run --full # 安装固件 chmod +x ./A300-3010-npu-firmware_5.1.rc2.run ./A300-3010-npu-firmware_5.1.rc2.run --full # 安装CANN chmod +x ./Ascend-cann-nnrt_6.0.0.alpha002_linux-x86_64.run ./Ascend-cann-nnrt_6.0.0.alpha002_linux-x86_64.run --install chmod +x ./Ascend-cann-nnae_6.0.0.alpha002_linux-x86_64.run ./Ascend-cann-nnae_6.0.0.alpha002_linux-x86_64.run --install chmod +x ./Ascend-cann-toolkit_6.0.0.alpha002_linux-x86_64.run ./Ascend-cann-toolkit_6.0.0.alpha002_linux-x86_64.run --install
这些安装后,配置一份 source_env.sh
激活环境的脚本,当然你也可以直接写进 ~/.bashrc
或 /etc/profile
。
# source_env.sh export PYTHONPATH=$PYTHONPATH:/usr/local/Ascend/nnrt/6.0.0.alpha002/pyACL/python/site-packages/acl:/usr/local/Ascend/ascend-toolkit/6.0.0.alpha002/pyACL/python/site-packages/acl:/usr/local/Ascend/ascend-toolkit/6.0.0.alpha002/atc/python/site-packages/te:/usr/local/Ascend/ascend-toolkit/6.0.0.alpha002/atc/python/site-packages/topi:/usr/local/Ascend/ascend-toolkit/6.0.0.alpha002/atc/python/site-packages/auto_tune.egg/auto_tune:/usr/local/Ascend/ascend-toolkit/6.0.0.alpha002/atc/python/site-packages/schedule_search.egg:/usr/local/Ascend/ascend-toolkit/6.0.0.alpha002/opp/built-in/op_impl/ai_core/tbe export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/Ascend/nnrt/6.0.0.alpha002/acllib/lib64:/usr/local/Ascend/ascend-toolkit/6.0.0.alpha002/acllib/lib64:/usr/local/Ascend/ascend-toolkit/6.0.0.alpha002/toolkit/toolchain/hcc/lib64:/usr/local/Ascend/ascend-toolkit/6.0.0.alpha002/atc/lib64:/usr/local/Ascend/ascend-toolkit/6.0.0.alpha002/atc/bin export PATH=$PATH:/usr/local/Ascend/ascend-toolkit/6.0.0.alpha002/toolkit/bin:/root/anaconda3/envs/conda_py375/bin:/usr/local/Ascend/ascend-toolkit/6.0.0.alpha002/atc/ccec_compiler/bin:/usr/local/Ascend/ascend-toolkit/6.0.0.alpha002/atc/bin export ASCEND_OPP_PATH=/usr/local/Ascend/ascend-toolkit/6.0.0.alpha002/opp export install_path=/usr/local/Ascend/ascend-toolkit/latest export PATH=$PATH:/root/anaconda3/envs/conda_py375/bin:${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin export PYTHONPATH=$PYTHONPATH:${install_path}/atc/python/site-packages/te:${install_path}/atc/python/site-packages/topi:${install_path}/atc/python/site-packages/auto_tune.egg/auto_tune:${install_path}/atc/python/site-packages/schedule_search.egg:${install_path}/opp/built-in/op_impl/ai_core/tbe export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${install_path}/atc/lib64:${install_path}/acllib/lib64:${install_path}/atc/lib64 export ASCEND_OPP_PATH=${install_path}/opp
最后进行 MindStudio 的安装:
# 解压 tar -zxvf MindStudio_5.0.RC2_linux.tar.gz cd MindStudio/bin # 启动 MindStudio sudo ./MindStudio.sh
另外你也可以验证一下输入命令 npu-smi info
就可以查看显卡信息了。
好了,以上分享了 昇腾开发环境搭建 CANN & MindStudio (无坑版),希望我的分享能对你的学习有一点帮助。