昇腾CANN开发&运行环境搭建

举报
胡琦 发表于 2021/04/01 13:03:19 2021/04/01
【摘要】 学废了,Copy攻城狮暗探昇腾CANN环境搭建。

大家好,我是Copy攻城狮,有幸参加了【昇腾CANN训练营】。昇腾CANN训练营包含一营(应用开发营)、二营(模型开发营)、三营(算子开发营),每营分别开设3节课程,共计9节课程。今天是和一营长学习【昇腾CANN开发&运行环境部署】,谨以此文记录一下学习过程。

目标

  • 开通 AIECS 并升级环境
  • 安装驱动
  • 安装 nnrt
  • 安装 Toolkit
  • 安装 MindStudio
  • 跑通 MindStudio 模板APP之ResNet50

坑点

  1. MindStudio 运行依赖特定的环境,因此网页版的 CloudShell 和 本地的 Xshell 都不能成功调起 MindStudio 界面,按照老师的教程,可以使用MobaXterm
  2. 推荐使用默认的 HwHiAIUser 用户,但需留意有些过程需要使用 root 用户,比如驱动的安装。
  3. 各种环境变量配到吐血,稍不留意就会掉入深坑中;此外在安装 Toolkit 时如果遇到终端窗口意外退出之后,可尝试先卸载再重新安装。
  4. 一定要留意 HwHiAiUser 的权限,在安装 MindStudio 时也需文件读写的权限。

流水

时间如流水,学习完再操作完到简单记录流水账,就差不多可以遇见凌晨4点的羊城了……

此处记录方便自己后续查阅。

AIECS 开通

值得留意的是规格选 AI加速型,AI加速型实例提供AI芯片,主要用于机器视觉、图像分类、语音识别等AI推理场景,此次用单片的 Ascend 310;系统选用的Ubuntu 18.04 server 64bit for Ai1s(40GB),当然还需绑定一个公网IP,让我们在本地通终端工具能够访问到ECS。

账号准备

登录修改HwHiAiUser 密码

cat /etc/passwd
# (推荐)如果创建的运行用户是HwHiAiUser,其为CANN软件包的默认运行用户,在安装时无需指定该运行用户
passwd HwHiAiUser

# (按需)修改sh --> bash
vim  /etc/passwd

资源下载

基本上昇腾相关的资料都可以通过访问 ascend.huawei.cn 获取,因此我们要下载的驱动、工具也可以在昇腾官网上找到。

  • 驱动

上文我们已经选用了昇腾310的环境,因此我们需要按照场景二来安装环境。 驱动选用的是Atlas300 3010 X86 Ubuntu18.04驱动包。

  • 工具

安装x86平台开发套件软件包及x86平台推理引擎软件包。

  • 软件
image.pngimage.png
mkdir downloads
wget https://repo.huaweicloud.cn/ascend/autoarchive/CANN/3.3.0.alpha001/Ascend-cann-toolkit_3.3.0.alpha001_linux-x86_64.run --no-check-certificate
wget https://repo.huaweicloud.cn/ascend/autoarchive/CANN/3.3.0.alpha001/Ascend-cann-nnrt_3.3.0.alpha001_linux-x86_64.run --no-check-certificate
wget https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/turing/resourcecenter/Software/20.2.0/A300-3010%201.0.9/A300-3010-npu-driver_20.2.0_ubuntu18.04-x86_64.run --no-check-certificate
wget https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/turing/resource/mindstudio/2.0.0-beta3/MindStudio_2.0.0-beta3_linux.tar.gz --no-check-certificate

修改 apt 源

一切为了加速,一切使用镜像!

cd /etc/apt
ll
cp sources.list sources.list.bak
vim sources.list
# :%d

## 中科大源
## 先备份源文件
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
apt-get update

安装依赖

依赖的安装也并非一帆风顺,遇到一些错误中断了安装,需要重新安装一下 python: apt-get install python3.7。当前环境只支持特定版本的Python。

sudo apt-get install -y gcc g++ make cmake zlib1g zlib1g-dev libbz2-dev libsqlite3-dev libssl-dev libxslt1-dev libffi-dev unzip pciutils net-tools libncursesw5-dev 

Errors were encountered while processing:
 python3-lib2to3
 python3-distutils
 libglib2.0-dev-bin
 libglib2.0-dev:amd64
 libharfbuzz-dev:amd64
 libicu-le-hb-dev:amd64
 libicu-dev
 libxml2-dev:amd64
 libxslt1-dev:amd64
E: Sub-process /usr/bin/dpkg returned an error code (1)
# 解决
apt-get install python3.7
# 再重新执行安装
# 安装python 依赖
exit   # 退回到HwHiAIUser
cd ~/.pip
vi pip.conf
[global]
#以华为源为例,请根据实际情况进行替换。
index-url = https://mirrors.huaweicloud.cn/repository/pypi/simple
trusted-host = mirrors.huaweicloud.cn
timeout = 120
# 软连接
su
ln -s /usr/local/python3.7.5/bin/python3 /usr/local/python3.7.5/bin/python3.7.5
ln -s /usr/local/python3.7.5/bin/pip3 /usr/local/python3.7.5/bin/pip3.7.5
exit
# python 环境变量
vim .bashrc

# 修改之后使之生效
source .bashrc
#用于设置python3.7.5库文件路径
export LD_LIBRARY_PATH=/usr/local/python3.7.5/lib:$LD_LIBRARY_PATH
#如果用户环境存在多个python3版本,则指定使用python3.7.5版本
export PATH=/usr/local/python3.7.5/bin:$PATH

# 安装依赖
pip3.7.5 install attrs numpy decorator sympy==1.4 cffi==1.12.3 pyyaml pathlib2 psutil protobuf scipy requests xlrd==1.2.0 --user

安装软件

# 给 downloads 目录添加权限
cd downloads
# chmod +x A*
su
chown -R HwHiAiUser:HwHiAiUser ./

# 驱动用 root 装
su
./A300-3010-npu-driver_20.2.0_ubuntu18.04-x86_64.run --full

## 替换原来的 再重启
reboot

# 其他用 HwHiAIUser 安装
./Ascend-cann-nnrt_3.3.0.alpha001_linux-x86_64.run --install
# 环境变量配置 41‘50

# 安装 toolkit
./Ascend-cann-toolkit_3.3.0.alpha001_linux-x86_64.run --install

## 注意保持环境变量配置 45‘47
## 有三组: 离线推理、在线推理、模型转换
[NNRT] [20210330-00:56:17] [INFO] Please make sure that:
LD_LIBRARY_PATH includes :
        /home/HwHiAiUser/Ascend/nnrt/latest/acllib/lib64:
PYTHONPATH includes :
        /home/HwHiAiUser/Ascend/nnrt/latest/pyACL/python/site-packages/acl:
ASCEND_AICPU_PATH includes :
        /home/HwHiAiUser/Ascend/nnrt/latest:
[NNRT] [20210330-00:56:17] [INFO] Ascend-cann-nnrt_3.3.0.alpha001_linux-x86_64.run install success,The install path is /home/HwHiAiUser/Ascend !
#用于设置python3.7.5库文件路径
export LD_LIBRARY_PATH=/home/HwHiAiUser/Ascend/nnrt/latest/acllib/lib64:/usr/local/python3.7.5/lib:$LD_LIBRARY_PATH
#如果用户环境存在多个python3版本,则指定使用python3.7.5版本
export PATH=/usr/local/python3.7.5/bin:$PATH
export PYTHONPATH=/home/HwHiAiUser/Ascend/nnrt/latest/pyACL/python/site-packages/acl:${PYTHONPATHG}
export ASCEND_AICPU_PATH=/home/HwHiAiUser/Ascend/nnrt/latest:${ASCEND_AICPU_PATH}

记得 source ~/.bashrc

离线、在线、模型转换三种场景对应的环境变量:

Offline infer develop (cannot coexist with other scenes):
        PATH includes :
                /home/HwHiAiUser/Ascend/ascend-toolkit/latest/toolkit/bin:
        LD_LIBRARY_PATH includes :
                /home/HwHiAiUser/Ascend/ascend-toolkit/latest/acllib/lib64:
        PYTHONPATH includes :
                /home/HwHiAiUser/Ascend/ascend-toolkit/latest/pyACL/python/site-packages/acl:
                /home/HwHiAiUser/Ascend/ascend-toolkit/latest/toolkit/python/site-packages:
        ASCEND_AICPU_PATH includes :
                /home/HwHiAiUser/Ascend/ascend-toolkit/latest:
        ASCEND_OPP_PATH includes :
                /home/HwHiAiUser/Ascend/ascend-toolkit/latest/opp:
        TOOLCHAIN_HOME includes :
                /home/HwHiAiUser/Ascend/ascend-toolkit/latest/toolkit:
Third party AI framework develop (cannot coexist with other scenes):
        PATH includes :
                /home/HwHiAiUser/Ascend/ascend-toolkit/latest/fwkacllib/ccec_compiler/bin:
                /home/HwHiAiUser/Ascend/ascend-toolkit/latest/fwkacllib/bin:
                /home/HwHiAiUser/Ascend/ascend-toolkit/latest/toolkit/bin:
        LD_LIBRARY_PATH includes :
                /home/HwHiAiUser/Ascend/ascend-toolkit/latest/fwkacllib/lib64:
        PYTHONPATH includes :
                /home/HwHiAiUser/Ascend/ascend-toolkit/latest/fwkacllib/python/site-packages:
                /home/HwHiAiUser/Ascend/ascend-toolkit/latest/toolkit/python/site-packages:
        ASCEND_OPP_PATH includes :
                /home/HwHiAiUser/Ascend/ascend-toolkit/latest/opp:
        ASCEND_AICPU_PATH includes :
                /home/HwHiAiUser/Ascend/ascend-toolkit/latest:
        TOOLCHAIN_HOME includes :
                /home/HwHiAiUser/Ascend/ascend-toolkit/latest/toolkit:
Model transformation and operator develop (cannot coexist with other scenes):
        PATH includes :
                /home/HwHiAiUser/Ascend/ascend-toolkit/latest/atc/ccec_compiler/bin:
                /home/HwHiAiUser/Ascend/ascend-toolkit/latest/atc/bin:
                /home/HwHiAiUser/Ascend/ascend-toolkit/latest/toolkit/bin:
        LD_LIBRARY_PATH includes :
                /home/HwHiAiUser/Ascend/ascend-toolkit/latest/atc/lib64:
        PYTHONPATH includes :
                /home/HwHiAiUser/Ascend/ascend-toolkit/latest/atc/python/site-packages:
                /home/HwHiAiUser/Ascend/ascend-toolkit/latest/toolkit/python/site-packages:
        ASCEND_OPP_PATH includes :
                /home/HwHiAiUser/Ascend/ascend-toolkit/latest/opp:
        TOOLCHAIN_HOME includes :
                /home/HwHiAiUser/Ascend/ascend-toolkit/latest/toolkit:
# 解压mindstudio
tar zxvf MindStudio_2.0.0-beta3_linux.tar.gz
# 运行
mindstudio/bin/mindstudio.sh

遇到错误按照提示操作,先用root权限安装写apt依赖;再用HwHiAiUser安装python依赖。

sudo  apt-get -y install xterm firefox xdg-utils openjdk-8-jdk fonts-droid-fallback fonts-wqy-zenhei fonts-wqy-microhei fonts-arphic-ukai fonts-arphic-uming gnome-keyring  && /usr/local/python3.7.5/bin/pip3 install --user  coverage gnureadline pylint matplotlib pandas absl-py 

MindStudio端操作

最后

记得截图保存留念并删除资源!

晚安!


【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。