非昇腾设备开发环境搭建-Ubuntu安装CANN

举报
jackwangcumt 发表于 2021/11/13 20:20:12 2021/11/13
【摘要】 基于华为Ascend处理器开发AI应用程序,一般需要搭建开发环境和运行环境。这里我们基于在非昇腾设备上(X86架构的PC)安装CANN开发环境。非昇腾AI设备无需安装固件(NPU)与驱动(driver),仅能用于代码开发、编译等不依赖于昇腾设备的开发活动。

1 前提准备


       基于华为Ascend处理器开发AI应用程序,一般需要搭建开发环境和运行环境。这里我们基于在非昇腾设备上(X86架构的PC)安装CANN开发环境。非昇腾AI设备无需安装固件(NPU)与驱动(driver),仅能用于代码开发、编译等不依赖于昇腾设备的开发活动。非昇腾AI设备开发环境示意图如下所示:

8.jpg
其中的Linux 操作系统的安装是基于Vitual Box虚拟机进行安装的,可以参考之前的博文《VitualBox安装Ubuntu并安装增强功能》。由图可知,CANN toolkit依赖性于Linux OS依赖项,如Python3.7等。因此,首先需要安装OS依赖项,这里我们选用Ubuntu18.04,关于依赖性安装可以参考之前的博客《Ubuntu安装CANN相关依赖》。本文重点在于介绍如何安装CANN toolkit。

2 CANN toolkit安装


       在基础Linux环境搭建完成后,需要登录华为相关网站(下载软件有权限要求,否则可能无法下载),并获取相关权限后,首先可以在Windows操作系统上下载两种架构(x86和aarch64)的CANN toolkit开发套件包Ascend-cann-toolkit_xxx.run 。例如本次安装的版本为CANN 5.0.2 (版本需要和其他软硬件匹配,比如MindStudio 3.0.2 匹配CANN 5.0.2)
Ascend-cann-toolkit_5.0.2.1_linux-aarch64.run
Ascend-cann-toolkit_5.0.2.1_linux-x86_64.run

注意:若开发环境为x86_64架构,运行环境为aarch64架构,开发环境上需同时部署x86_64和aarch64架构的开发套件,后续编译应用时需要调用aarch64架构开发套件的ACLlib库。另外,安装CANN toolkit开发套件包前请确保安装目录可用空间大于7G

      这里为了方便从Windows操作系统和虚拟机直接传递文件,可以在Vitual Box中设置共享文件夹,示意图如下:

9.jpg

另外,就需要将文件下载到C:\share_folder 共享文件中,示意图如下:

10.jpg

此时启动虚拟机Ubuntu后,可以通过命令行访问共享文件夹中的文件,下面首先切换到root用户进行CANN安装。示意图如下:

11.jpg

然后打开终端命令行,执行如下命令进行CANN toolkit安装:

jack@jack-pc:~$ su root
Password: 
root@jack-pc:/home/jack# cd /media/sf_share_folder/
#设置可执行权限
chmod +x Ascend-cann-toolkit_5.0.2.1_linux-x86_64.run 
chmod +x Ascend-cann-toolkit_5.0.2.1_linux-aarch64.run 
#安装
./Ascend-cann-toolkit_5.0.2.1_linux-x86_64.run --install
./Ascend-cann-toolkit_5.0.2.1_linux-aarch64.run --install

输出过程示意如下:

Verifying archive integrity...  100%   SHA256 checksums are OK. All good.
Uncompressing ASCEND_RUN_PACKAGE  100%  
[Toolkit] [20211113-19:52:13] [INFO] mkdir /usr/local/Ascend/ascend-toolkit/5.0.2.1/x86_64-linux
[Toolkit] [20211113-19:52:14] [INFO] mkdir /var/log/ascend_seclog/
[Toolkit] [20211113-19:52:14] [INFO] touch /var/log/ascend_seclog/ascend_toolkit_install.log
[Toolkit] [20211113-19:52:14] [INFO] LogFile:/var/log/ascend_seclog/ascend_toolkit_install.log
[Toolkit] [20211113-19:52:14] [INFO] install start
[Toolkit] [20211113-19:52:14] [INFO] The install path is /usr/local/Ascend !
[Toolkit] [20211113-19:52:14] [WARNING] driver package maybe not installed
[Toolkit] [20211113-19:52:14] [WARNING] driver package maybe not installed
[Toolkit] [20211113-19:52:15] [INFO] install package Ascend-acllib-1.78.23.34.230-linux.x86_64.run start
[Toolkit] [20211113-19:52:26] [INFO] Ascend-acllib-1.78.23.34.230-linux.x86_64.run --devel --quiet --nox11 install success
[Toolkit] [20211113-19:52:26] [INFO] install package Ascend-pyACL-5.0.2.1-linux.x86_64.run start
[Toolkit] [20211113-19:52:29] [INFO] Ascend-pyACL-5.0.2.1-linux.x86_64.run --devel --quiet --nox11 install success
[Toolkit] [20211113-19:52:29] [INFO] install package Ascend-atc-1.78.23.34.230-linux.x86_64.run start
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
[Toolkit] [20211113-19:54:26] [INFO] Ascend-atc-1.78.23.34.230-linux.x86_64.run --devel --pylocal --quiet --nox11 install success
[Toolkit] [20211113-19:54:26] [INFO] install package Ascend-opp-1.78.23.34.230-linux.x86_64.run start
[Toolkit] [20211113-19:56:21] [INFO] Ascend-opp-1.78.23.34.230-linux.x86_64.run --devel --quiet --nox11 install success
[Toolkit] [20211113-19:56:23] [INFO] install package Ascend-toolkit-1.78.23.34.230-linux.x86_64.run start
[Toolkit] [20211113-19:59:14] [INFO] Ascend-toolkit-1.78.23.34.230-linux.x86_64.run --devel --pylocal --quiet --nox11 install success
[Toolkit] [20211113-19:59:14] [INFO] install package Ascend310-aicpu_kernels-1.78.23.34.230.run start
[Toolkit] [20211113-19:59:15] [INFO] Ascend310-aicpu_kernels-1.78.23.34.230.run --devel --quiet --nox11 install success
[Toolkit] [20211113-19:59:15] [INFO] install package Ascend910-aicpu_kernels-1.78.23.34.230.run start
[Toolkit] [20211113-19:59:17] [INFO] Ascend910-aicpu_kernels-1.78.23.34.230.run --devel --quiet --nox11 install success
[Toolkit] [20211113-19:59:17] [INFO] install package Ascend710-aicpu_kernels-1.78.23.34.230.run start
[Toolkit] [20211113-19:59:18] [INFO] Ascend710-aicpu_kernels-1.78.23.34.230.run --devel --quiet --nox11 install success
[Toolkit] [20211113-19:59:18] [INFO] install package Ascend310-aicpu_kernels_minirc-1.78.23.34.230.run start
[Toolkit] [20211113-19:59:20] [INFO] Ascend310-aicpu_kernels_minirc-1.78.23.34.230.run --devel --quiet --nox11 install success
[Toolkit] [20211113-19:59:20] [INFO] install package Ascend-test-ops-5.0.2.1.run start
[Toolkit] [20211113-19:59:20] [INFO] Ascend-test-ops-5.0.2.1.run --full --quiet --nox11 install success
[Toolkit] [20211113-19:59:20] [INFO] /etc/Ascend/ascend_cann_install.info generate success
[Toolkit] [20211113-19:59:20] [INFO] Please make sure that:
Offline infer develop (cannot coexist with other scenes):
    LD_LIBRARY_PATH includes :
        /usr/local/Ascend/ascend-toolkit/latest/acllib/lib64:
    PYTHONPATH includes :
        /usr/local/Ascend/ascend-toolkit/latest/pyACL/python/site-packages/acl:
        /usr/local/Ascend/ascend-toolkit/latest/toolkit/python/site-packages:
    ASCEND_AICPU_PATH includes :
        /usr/local/Ascend/ascend-toolkit/latest:
    ASCEND_OPP_PATH includes :
        /usr/local/Ascend/ascend-toolkit/latest/opp:
    TOOLCHAIN_HOME includes :
        /usr/local/Ascend/ascend-toolkit/latest/toolkit:
Third party AI framework develop (cannot coexist with other scenes):
    PATH includes :
        /usr/local/Ascend/ascend-toolkit/latest/fwkacllib/ccec_compiler/bin:
        /usr/local/Ascend/ascend-toolkit/latest/fwkacllib/bin:
    LD_LIBRARY_PATH includes :
        /usr/local/Ascend/ascend-toolkit/latest/fwkacllib/lib64:
    PYTHONPATH includes :
        /usr/local/Ascend/ascend-toolkit/latest/fwkacllib/python/site-packages:
        /usr/local/Ascend/ascend-toolkit/latest/toolkit/python/site-packages:
    ASCEND_OPP_PATH includes :
        /usr/local/Ascend/ascend-toolkit/latest/opp:
    ASCEND_AICPU_PATH includes :
        /usr/local/Ascend/ascend-toolkit/latest:
    TOOLCHAIN_HOME includes :
        /usr/local/Ascend/ascend-toolkit/latest/toolkit:
Model transformation and operator develop (cannot coexist with other scenes):
    PATH includes :
        /usr/local/Ascend/ascend-toolkit/latest/atc/ccec_compiler/bin:
        /usr/local/Ascend/ascend-toolkit/latest/atc/bin:
    LD_LIBRARY_PATH includes :
        /usr/local/Ascend/ascend-toolkit/latest/atc/lib64:
    PYTHONPATH includes :
        /usr/local/Ascend/ascend-toolkit/latest/atc/python/site-packages:
        /usr/local/Ascend/ascend-toolkit/latest/toolkit/python/site-packages:
    ASCEND_OPP_PATH includes :
        /usr/local/Ascend/ascend-toolkit/latest/opp:
    TOOLCHAIN_HOME includes :
        /usr/local/Ascend/ascend-toolkit/latest/toolkit:
[Toolkit] [20211113-19:59:20] [INFO] If your service is started using the shell script, you can call the /usr/local/Ascend/ascend-toolkit/set_env.sh script to configure environment variables. Note that this script can not be executed mannually.
[Toolkit] [20211113-19:59:21] [INFO] Ascend-cann-toolkit_5.0.2.1_linux-x86_64 install success,The install path is /usr/local/Ascend !

下面可以到安装的目录中 /usr/local/Ascend进行查看,命令如下:

jack@jack-pc:/usr/local/Ascend/ascend-toolkit/5.0.2.1$ cd ~
jack@jack-pc:~$ cd /usr/local/Ascend/
jack@jack-pc:/usr/local/Ascend$ ls
ascend-toolkit
jack@jack-pc:/usr/local/Ascend$ cd ascend-toolkit/
jack@jack-pc:/usr/local/Ascend/ascend-toolkit$ ls
5.0  5.0.2.1  latest  set_env.sh
jack@jack-pc:/usr/local/Ascend/ascend-toolkit$ cd latest
jack@jack-pc:/usr/local/Ascend/ascend-toolkit/latest$ ls
acllib               arm64-linux  opp_linux.arm64   python   tools
acllib_linux.arm64   atc          opp_linux.x86_64  targets  var
acllib_linux.x86_64  opp          pyACL             toolkit  x86_64-linux
jack@jack-pc:/usr/local/Ascend/ascend-toolkit/latest$ 

 示意图如下所示: 

12.jpg

3 配置交叉编译环境


       最后,对于Atlas 200 AI加速模块 (RC场景)和Atlas 500 小站(运行环境aarch64架构)来说,当开发环境是一台X86 PC进行环境搭建时,需要在开发环境中安装交叉编译工具,具体命令如下:

#检查是否安装
aarch64-linux-gnu-g++ --version
#安装(root)
apt-get install g++-aarch64-linux-gnu

安装成功后,再次验证,执行如下命令:

root@jack-pc:/home/jack# aarch64-linux-gnu-g++ --version
aarch64-linux-gnu-g++ (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04) 7.5.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

具体CANN更多安装细节文档,可以参考官网 https://support.huawei.cn/enterprise/zh/doc/EDOC1100206656/4f20a9ed 。

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

评论(0

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

全部回复

上滑加载中

设置昵称

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

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

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