当前位置:   article > 正文

华为云AI加速型(昇腾Ascend310)Ubuntu18.04系统下使用msame模型推理工具

msame

弹性云服务器ECS信息

  • 规格:AI加速型 | ai1s.large.4 | 2vCPUs | 8GiB
  • 镜像:Ubuntu 18.04 server 64bit for Ai1s | 公共镜像

默认分配的服务器,toolkit的版本为20.1.rc1,而msame模型推理工具的版本现在要求5.0.3.alpha001及以上版本。虽然官方也有提供5.0.3.alpha001前的版本,但我下载后编译会报错,所以还是升级一下CANN开发环境,同时更新硬件驱动。

更新Ascend310驱动

系统自带原驱动信息如下:

## 查询驱动信息
npu-smi info
## 返回如下结果
+------------------------------------------------------------------------------+
| npu-smi 20.1.0                       Version: 20.1.0                         |
+-------------------+-----------------+----------------------------------------+
| NPU     Name      | Health          | Power(W)          Temp(C)              |
| Chip    Device    | Bus-Id          | AICore(%)         Memory-Usage(MB)     |
+===================+=================+========================================+
| 0       310       | OK              | 12.8              45                   |
| 0       0         | 0000:00:0D.0    | 0                 2703 / 8192          |
+===================+=================+========================================+
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

在华为官网下载支持CANN 5.1.RC1.alpha001版本的驱动1.0.13.aplha
这里我下载的软件名称为:
A300-3010-npu_21.0.4_linux-x86_64.zip
可在服务器上执行如下命令进行下载并安装:

## 创建driver目录并进入driver目录
mkdir driver && cd driver
## 下载驱动安装包
wget --no-check-certificate https://obs-9be7.obs.cn-east-2.myhuaweicloud.com/turing/resourcecenter/Software/AtlasI/A300-3010%201.0.13/A300-3010-npu_21.0.4_linux-x86_64.zip
## 解压安装包到指定目录A310
unzip -d A310 A300-3010-npu_21.0.4_linux-x86_64.zip
## 进入A310目录
cd A310
## 再次执行解压命令(官方下载的默认解压有一个同名ZIP,需要二次解压)
## 解压出来后还有一个是固件,但云服务器无法更新固件所以更新固件
unzip A300-3010-npu_21.0.4_linux-x86_64.zip
## 安装驱动
./npu-driver_21.0.4_linux-x86_64.run --full
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

安装过程会得到如下提示:

Verifying archive integrity...  100%   SHA256 checksums are OK. All good.
Uncompressing npu-driver-run-package  100%  
[Driver] [2022-03-04 13:23:04] [INFO]Start time: 2022-03-04 13:23:04
[Driver] [2022-03-04 13:23:04] [INFO]LogFile: /var/log/ascend_seclog/ascend_install.log
[Driver] [2022-03-04 13:23:04] [INFO]OperationLogFile: /var/log/ascend_seclog/operation.log
[Driver] [2022-03-04 13:23:04] [INFO]base version is 20.1.0.
[Driver] [2022-03-04 13:23:04] [WARNING]Do not power off or restart the system during the installation/upgrade
[Driver] [2022-03-04 13:23:04] [INFO]set username and usergroup, HwHiAiUser:HwHiAiUser
[Driver] [2022-03-04 13:23:04] [INFO]Driver package has been installed on the path /usr/local/Ascend, the version is 20.1.0, and the version of this package is 21.0.4,do you want to continue?  [y/n]
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

输入y确认更新驱动,最终提示如下:

deleting install files...
remove install files successfully!
deleting installed folders...
remove install folders successfully!
[Driver] [2022-03-04 13:24:12] [INFO]driver install type: DKMS
[Driver] [2022-03-04 13:24:12] [INFO]upgradePercentage:10%
[Driver] [2022-03-04 13:24:16] [INFO]upgradePercentage:30%
[Driver] [2022-03-04 13:24:16] [INFO]upgradePercentage:40%
[Driver] [2022-03-04 13:25:09] [INFO]upgradePercentage:90%
[Driver] [2022-03-04 13:25:09] [INFO]upgradePercentage:100%
[Driver] [2022-03-04 13:25:10] [INFO]Driver package installed successfully! Reboot needed for installation/upgrade to take effect! 
[Driver] [2022-03-04 13:25:10] [INFO]End time: 2022-03-04 13:25:10
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

提示重启生效,此时执行reboot命令进行重启。
重启后执行npu-smi info命令得到如下结果:

+--------------------------------------------------------------------------------------------+
| npu-smi 21.0.4                       Version: 21.0.4                                       |
+-------------------+-----------------+------------------------------------------------------+
| NPU     Name      | Health          | Power(W)     Temp(C)           Hugepages-Usage(page) |
| Chip    Device    | Bus-Id          | AICore(%)    Memory-Usage(MB)                        |
+===================+=================+======================================================+
| 13      310       | OK              | 12.8         45                0    / 970            |
| 0       0         | 0000:00:0D.0    | 0            608  / 7765                             |
+===================+=================+======================================================+
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

即可看到驱动版本已更新为21.0.4

更新CANN开发环境

在华为官网上下载CANN社区版,需要下载机器对应CPU架构的平台开发套件软件包,这里我下载的是x86_64架构的,对应软件名称为:
Ascend-cann-toolkit_5.1.RC1.alpha001_linux-x86_64.run
可在服务器上执行如下命令进行下载并安装:

推荐使用此方式下载,实测下载速度最高可达4.66MB/s,超过了我外网IP的固定带宽10 Mbit/s。

## 创建cann目录并进入cann目录
mkdir cann && cd cann
## 下载toolkit安装包
wget --no-check-certificate https://ascend-repo.obs.cn-east-2.myhuaweicloud.com/CANN/5.1.RC1.alpha001/Ascend-cann-toolkit_5.1.RC1.alpha001_linux-x86_64.run
## 添加可执行权限
chmod +x Ascend-cann-toolkit_5.1.RC1.alpha001_linux-x86_64.run
## 执行安装
./Ascend-cann-toolkit_5.1.RC1.alpha001_linux-x86_64.run --install
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

安装过程可得到如下提示:

Verifying archive integrity...  100%   SHA256 checksums are OK. All good.
Uncompressing ASCEND_RUN_PACKAGE  100%  
[Toolkit] [20220304-13:27:35] [INFO] mkdir /usr/local/Ascend/ascend-toolkit/5.1.RC1.alpha001/x86_64-linux
[Toolkit] [20220304-13:27:35] [INFO] touch /var/log/ascend_seclog/ascend_toolkit_install.log
[Toolkit] [20220304-13:27:35] [INFO] LogFile:/var/log/ascend_seclog/ascend_toolkit_install.log
[Toolkit] [20220304-13:27:35] [INFO] install start
[Toolkit] [20220304-13:27:35] [INFO] The install path is /usr/local/Ascend !
[Toolkit] [20220304-13:27:35] [INFO] install package CANN-runtime-5.1.RC1.alpha001-linux.x86_64.run start
[Toolkit] [20220304-13:27:37] [INFO] CANN-runtime-5.1.RC1.alpha001-linux.x86_64.run --full --quiet --nox11 install success
[Toolkit] [20220304-13:27:37] [INFO] install package CANN-compiler-5.1.RC1.alpha001-linux.x86_64.run start
WARNING: You are using pip version 19.2.3, however version 22.0.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
WARNING: You are using pip version 19.2.3, however version 22.0.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
WARNING: You are using pip version 19.2.3, however version 22.0.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
WARNING: You are using pip version 19.2.3, however version 22.0.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
WARNING: You are using pip version 19.2.3, however version 22.0.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
WARNING: You are using pip version 19.2.3, however version 22.0.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
[Toolkit] [20220304-13:28:13] [INFO] CANN-compiler-5.1.RC1.alpha001-linux.x86_64.run --full --pylocal --quiet --nox11 install success
[Toolkit] [20220304-13:28:13] [INFO] install package CANN-opp-5.1.RC1.alpha001-linux.x86_64.run start
[Toolkit] [20220304-13:28:33] [INFO] CANN-opp-5.1.RC1.alpha001-linux.x86_64.run --full --quiet --nox11 install success
[Toolkit] [20220304-13:28:33] [INFO] install package CANN-toolkit-5.1.RC1.alpha001-linux.x86_64.run start
[Toolkit] [20220304-13:29:13] [INFO] CANN-toolkit-5.1.RC1.alpha001-linux.x86_64.run --full --pylocal --quiet --nox11 install success
[Toolkit] [20220304-13:29:13] [INFO] install package Ascend-mindstudio-toolkit_3.0.3.B120_linux-x86_64.run start
[Toolkit] [20220304-13:29:14] [INFO] Ascend-mindstudio-toolkit_3.0.3.B120_linux-x86_64.run --full --quiet --nox11 install success
[Toolkit] [20220304-13:29:14] [INFO] install package CANN-aoe-5.1.RC1.alpha001-linux.x86_64.run start
WARNING: You are using pip version 19.2.3, however version 22.0.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
[Toolkit] [20220304-13:29:16] [INFO] CANN-aoe-5.1.RC1.alpha001-linux.x86_64.run --full --quiet --nox11 install success
[Toolkit] [20220304-13:29:16] [INFO] install package Ascend-test-ops_5.0.3_linux.run start
[Toolkit] [20220304-13:29:17] [INFO] Ascend-test-ops_5.0.3_linux.run --full --quiet --nox11 install success
[Toolkit] [20220304-13:29:17] [INFO] install package Ascend-pyACL_5.0.3_linux-x86_64.run start
[Toolkit] [20220304-13:29:17] [INFO] Ascend-pyACL_5.0.3_linux-x86_64.run --full --quiet --nox11 install success
[Toolkit] [20220304-13:29:17] [INFO] /etc/Ascend/ascend_cann_install.info generate success
[Toolkit] [20220304-13:29:17] [INFO] Please make sure that:
PATH includes :
	/usr/local/Ascend/ascend-toolkit/latest/bin:
	/usr/local/Ascend/ascend-toolkit/latest/compiler/ccec_compiler/bin:
LD_LIBRARY_PATH includes :
	/usr/local/Ascend/ascend-toolkit/latest/lib64:
	/usr/local/Ascend/ascend-toolkit/latest/compiler/lib64/plugin/opskernel:
	/usr/local/Ascend/ascend-toolkit/latest/compiler/lib64/plugin/nnengine:
PYTHONPATH includes :
	/usr/local/Ascend/ascend-toolkit/latest/python/site-packages:
	/usr/local/Ascend/ascend-toolkit/latest/opp/op_impl/built-in/ai_core/tbe:
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:
ASCEND_HOME_PATH includes :
	/usr/local/Ascend/ascend-toolkit/latest:
[Toolkit] [20220304-13:29:17] [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] [20220304-13:29:17] [INFO] Ascend-cann-toolkit_5.1.RC1.alpha001_linux-x86_64 install success,The install path is /usr/local/Ascend !
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59

下载并编译msame模型推理工具

## 下载msame源码
git clone https://gitee.com/ascend/tools.git
## 切换到代码目录
cd tools/msame
## 添加可执行权限
chmod +x build.sh
## 开始编译工具
./build.sh g++
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

提示编译成功

-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/g++
-- Check for working CXX compiler: /usr/bin/g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- env INC_PATH: /usr/local/Ascend/ascend-toolkit/latest
-- env LIB_PATH: /usr/local/Ascend/ascend-toolkit/latest/acllib/lib64/stub
-- Configuring done
-- Generating done
-- Build files have been written to: /root/cann/tools/msame/build/intermediates/host
Scanning dependencies of target main
[ 20%] Building CXX object CMakeFiles/main.dir/utils.cpp.o
[ 40%] Building CXX object CMakeFiles/main.dir/model_process.cpp.o
[ 60%] Building CXX object CMakeFiles/main.dir/sample_process.cpp.o
[ 80%] Building CXX object CMakeFiles/main.dir/main.cpp.o
[100%] Linking CXX executable /root/cann/tools/msame/out/main
[100%] Built target main
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26

下载googlenet模型

## 创建googlenet目录并进入googlenet目录
mkdir googlenet && cd googlenet
wget https://modelzoo-train-atc.obs.cn-north-4.myhuaweicloud.com/003_Atc_Models/AE/ATC%20Model/classification/googlenet.om
  • 1
  • 2
  • 3

进行空数据推理

../out/msame --model ./googlenet.om --output ./output --outfmt BIN --loop 1
[INFO] acl init success
[INFO] open device 0 success
[INFO] create context success
[INFO] create stream success
[INFO] get run mode success
[INFO] load model ./googlenet.om success
[INFO] create model description success
[INFO] get input dynamic gear count success
[INFO] create model output success
./output/202234_12_58_29_218043
[INFO] model execute success
Inference time: 1.963ms
[INFO] get max dynamic batch size success
[INFO] output data success
Inference average time: 1.963000 ms
[INFO] destroy model input success
[INFO] unload model success, model Id is 1
[INFO] Execute sample success
[INFO] end to destroy stream
[INFO] end to destroy context
[INFO] end to reset device is 0
[INFO] end to finalize acl
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

上述输出结果提示成功,无报错!

参考来源

麒麟系统安装CANN开发环境
CANN 社区版下载-昇腾社区
固件与驱动-昇腾社区

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/842701
推荐阅读
相关标签
  

闽ICP备14008679号