Atlas 200I DK A2安装MindSpore Ascend版本

news2024/9/8 22:54:09

一、参考资料

mindspore快速安装

二、重要说明

经过博主多次尝试多个版本,Atlas 200I DK A2无法安装MindSpore Ascend版本

也有其他博主测试,也未尝成功,例如:【MindSpore易点通·漫游世界】在Atlas 200I DK A2 (CANN6.2.RC2)上安装MindSpore Ascend版的踩坑记录

mindspore 1.5.2 报错无法运行(./tensor_add_sample: symbol lookup error: /home/HwHiAiUser/.local/lib/python3.9/site-packages/mindspore/lib/libmindspore.so: undefined symbol: _ZN2ge5Model8SetGraphERKNS_5GraphE)

mindspore 1.6.2 报错无法运行(./tensor_add_sample: symbol lookup error: /home/HwHiAiUser/.local/lib/python3.9/site-packages/mindspore/lib/libmindspore.so: undefined symbol: _ZN2ge5Model8SetGraphERKNS_5GraphE)

mindspore 1.7.1 报错无法运行 (./tensor_add_sample: error while loading shared libraries: libhccl.so: cannot open shared object file: No such file or directory)

mindspore 1.8.1 报错无法运行(./tensor_add_sample: error while loading shared libraries: libhccl.so: cannot open shared object file: No such file or directory)

mindspore 1.9.0 报错无法运行(./tensor_add_sample: symbol lookup error: /home/HwHiAiUser/.local/lib/python3.9/site-packages/mindspore/lib/libmindspore.so: undefined symbol: _ZN2ge5Model8SetGraphERKNS_5GraphE)

mindspore 1.10.1 报错无法运行(./tensor_add_sample: symbol lookup error: /home/HwHiAiUser/.local/lib/python3.9/site-packages/mindspore/lib/libmindspore.so: undefined symbol: _ZN2ge5Model8SetGraphERKNS_5GraphE)

mindspore 2.0.0 报错无法运行(Unsupported device target Ascend)

mindspore 2.1.0 报错无法运行(Unsupported device target Ascend)

三、准备工作

1. 测试环境

设备型号:Atlas 200I DK A2
Operating System + Version: Ubuntu 22.04 LTS
CPU Type: 4核TAISHANV200M处理器
AI CPU number: 0
control CPU number: 4
RAM: 4GB 
miscroSD: 128GB
CANN Vertion: 7.0.RC1
HwHiAiUser@davinci-mini:~$ npu-smi info -t aicpu-config -i 0 -c 0
        Current AI CPU number          : 0
        Current control CPU number     : 4
        Number of AI CPUs set          : 0
        Number of control CPUs set     : 4

2. MindSpore与CANN版本对齐

通过 链接 查询MindSpore与Ascend配套软件包的版本配套关系。

在这里插入图片描述

3. 安装mindspore_ascend

详细过程,请参考:pip方式安装MindSpore Ascend 310版本

4. 验证是否安装成功

4.1 方法一

import mindspore as ms

# ms.set_context(device_target='CPU')
# ms.set_context(device_target='GPU')
ms.set_context(device_target="Ascend")
ms.set_context(device_id=0)
mindspore.run_check()

如果输出以下结果,则说明mindspore_ascend安装成功。

MindSpore version: 版本号
The result of multiplication calculation is correct, MindSpore has been installed on platform [Ascend] successfully!

4.2 方法二

import numpy as np
import mindspore as ms
import mindspore.ops as ops

ms.set_context(device_target="Ascend")
x = ms.Tensor(np.ones([1,3,3,4]).astype(np.float32))
y = ms.Tensor(np.ones([1,3,3,4]).astype(np.float32))
print(ops.add(x, y))

如果输出以下结果,则说明mindspore_ascend安装成功。

[[[[2. 2. 2. 2.]
   [2. 2. 2. 2.]
   [2. 2. 2. 2.]]

  [[2. 2. 2. 2.]
   [2. 2. 2. 2.]
   [2. 2. 2. 2.]]

  [[2. 2. 2. 2.]
   [2. 2. 2. 2.]
   [2. 2. 2. 2.]]]]

4.3 方法三

ascend310_single_op_sample

这是一个[1, 2, 3, 4][2, 3, 4, 5]相加的简单样例,代码工程目录结构如下:

└─ascend310_single_op_sample
    ├── CMakeLists.txt                    // 编译脚本
    ├── README.md                         // 使用说明
    ├── main.cc                           // 主函数
    └── tensor_add.mindir                 // MindIR模型文件
unzip ascend310_single_op_sample.zip
cd ascend310_single_op_sample

# 编译
cmake . -DMINDSPORE_PATH=`pip show mindspore-ascend | grep Location | awk '{print $2"/mindspore"}' | xargs realpath`
make

# 执行
./tensor_add_sample

如果输出以下结果,则说明mindspore_ascend安装成功。

3
5
7
9

四、测试代码

1. 示例一

用MindSpore搭建模型,并进行测试。

"""
MindSpore implementation of `MobileNetV1`.
Refer to MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications.
"""
import time

from mindspore import nn, Tensor, ops
import mindspore.common.initializer as init
import mindspore as ms
from PIL import Image
from mindcv.data import create_transforms
import numpy as np


def depthwise_separable_conv(inp: int, oup: int, stride: int) -> nn.SequentialCell:
    return nn.SequentialCell(
        # dw
        nn.Conv2d(inp, inp, 3, stride, pad_mode="pad", padding=1, group=inp, has_bias=False),
        nn.BatchNorm2d(inp),
        nn.ReLU(),
        # pw
        nn.Conv2d(inp, oup, 1, 1, pad_mode="pad", padding=0, has_bias=False),
        nn.BatchNorm2d(oup),
        nn.ReLU(),
    )


class MobileNetV1(nn.Cell):
    r"""MobileNetV1 model class, based on
    `"MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications" <https://arxiv.org/abs/1704.04861>`_

    Args:
        alpha: scale factor of model width. Default: 1.
        in_channels: number the channels of the input. Default: 3.
        num_classes: number of classification classes. Default: 1000.
    """

    def __init__(self,
                 alpha: float = 1.,
                 in_channels: int = 3,
                 num_classes: int = 1000) -> None:
        super().__init__()
        input_channels = int(32 * alpha)
        # Setting of depth-wise separable conv
        # c: number of output channel
        # s: stride of depth-wise conv
        block_setting = [
            # c, s
            [64, 1],
            [128, 2],
            [128, 1],
            [256, 2],
            [256, 1],
            [512, 2],
            [512, 1],
            [512, 1],
            [512, 1],
            [512, 1],
            [512, 1],
            [1024, 2],
            [1024, 1],
        ]

        features = [
            nn.Conv2d(in_channels, input_channels, 3, 2, pad_mode="pad", padding=1, has_bias=False),
            nn.BatchNorm2d(input_channels),
            nn.ReLU()
        ]
        for c, s in block_setting:
            output_channel = int(c * alpha)
            features.append(depthwise_separable_conv(input_channels, output_channel, s))
            input_channels = output_channel
        self.features = nn.SequentialCell(features)

        # self.pool = GlobalAvgPooling()
        self.pool = nn.AdaptiveAvgPool2d(output_size=(1, 1))
        self.classifier = nn.Dense(input_channels, num_classes)
        self._initialize_weights()

    def _initialize_weights(self) -> None:
        """Initialize weights for cells."""
        for _, cell in self.cells_and_names():
            if isinstance(cell, nn.Conv2d):
                cell.weight.set_data(init.initializer(init.XavierUniform(),
                                                             cell.weight.shape,
                                                             cell.weight.dtype))
            if isinstance(cell, nn.Dense):
                cell.weight.set_data(init.initializer(init.TruncatedNormal(),
                                                             cell.weight.shape,
                                                             cell.weight.dtype))

    def forward_features(self, x: Tensor) -> Tensor:
        x = self.features(x)
        return x

    def forward_head(self, x: Tensor) -> Tensor:
        squeeze = ops.Squeeze(0)
        x = squeeze(x)
        x = self.pool(x)
        squeeze = ops.Squeeze(2)
        x = squeeze(x)
        x = x.transpose()
        x = self.classifier(x)
        return x

    def construct(self, x: Tensor) -> Tensor:
        x = self.forward_features(x)
        x = self.forward_head(x)
        return x


def mobilenet_v1_100_224(pretrained: bool = False, num_classes: int = 1000, in_channels=3, **kwargs) -> MobileNetV1:
    """Get MobileNetV1 model without width scaling.
     Refer to the base class `models.MobileNetV1` for more details.
     """
    model = MobileNetV1(alpha=1.0, in_channels=in_channels, num_classes=num_classes, **kwargs)

    return model


if __name__ == '__main__':
    # ms.set_context(device_target='GPU')
    # ms.set_context(device_target='CPU')
    ms.set_context(device_target="Ascend")
    ms.set_context(device_id=0)

    ms.set_seed(1)
    ms.set_context(mode=ms.PYNATIVE_MODE)

    img = Image.open("image.jpg").convert("RGB")
    # create transform
    transform_list = create_transforms(
        dataset_name="imagenet",
        is_training=False,
    )
    transform_list.pop(0)
    for transform in transform_list:
        img = transform(img)
    img = np.expand_dims(img, axis=0)

    # create model
    network = mobilenet_v1_100_224()


    for i in range(100):
        # warmup
        network(ms.Tensor(img))

    time_begin = time.time()

    for i in range(1000):
        # predict
        network(ms.Tensor(img))

    time_total = (time.time() - time_begin) * 1000 / 1000

    print(f"total time is: {time_total}")

    # print(network)

2. 示例二

调用 mindcv库中的预训练模型进行测试。

"""MindSpore Inference Script
"""


import numpy as np
from PIL import Image

import mindspore as ms

from mindcv.data import create_transforms
from mindcv.models import create_model
import time


# ms.set_context(device_target='CPU')
# ms.set_context(device_target='GPU')

ms.set_context(device_target='Ascend')
ms.set_context(device_id=0)
ms.set_context(max_device_memory="3.5GB")


def main():
    ms.set_seed(1)
    ms.set_context(mode=ms.PYNATIVE_MODE)

    img = Image.open("image.jpg").convert("RGB")
    # create transform
    transform_list = create_transforms(
        dataset_name="imagenet",
        is_training=False,
    )
    transform_list.pop(0)
    for transform in transform_list:
        img = transform(img)
    img = np.expand_dims(img, axis=0)

    # create model
    network = create_model(
        model_name="mobilenet_v1_100",  # mobilenet_v1_100_224
        pretrained=False,
    )

    network.set_train(False)
    for i in range(100):
        # warmup
        network(ms.Tensor(img))

    time_begin = time.time()

    for i in range(1000):
        # predict
        network(ms.Tensor(img))

    time_total = (time.time() - time_begin) * 1000 / 1000

    print(f"total time is: {time_total}")


if __name__ == "__main__":
    main()

五、FAQ

Q:RuntimeError: Load op info form json config failed, version: Ascend310B4

[WARNING] ME(230369:255086392991776,MainProcess):2024-05-25-17:29:28.302.942 [mindspore/run_check/_check_version.py:375] MindSpore version 2.1.1 and "te" wheel package version 7.0 does not match. For details, refer to the installation guidelines: https://www.mindspore.cn/install
[WARNING] ME(230369:255086392991776,MainProcess):2024-05-25-17:29:28.305.619 [mindspore/run_check/_check_version.py:382] MindSpore version 2.1.1 and "hccl" wheel package version 7.0 does not match. For details, refer to the installation guidelines: https://www.mindspore.cn/install
[WARNING] ME(230369:255086392991776,MainProcess):2024-05-25-17:29:28.305.849 [mindspore/run_check/_check_version.py:396] Please pay attention to the above warning, countdown: 3
[WARNING] ME(230369:255086392991776,MainProcess):2024-05-25-17:29:29.307.139 [mindspore/run_check/_check_version.py:396] Please pay attention to the above warning, countdown: 2
[WARNING] ME(230369:255086392991776,MainProcess):2024-05-25-17:29:30.308.249 [mindspore/run_check/_check_version.py:396] Please pay attention to the above warning, countdown: 1
[ERROR] KERNEL(230369,e7ffaf56f120,python):2024-05-25-17:29:35.761.869 [mindspore/ccsrc/kernel/oplib/op_info_utils.cc:172] LoadOpInfoJson] Get op info json suffix path failed, soc_version: Ascend310B4
[ERROR] KERNEL(230369,e7ffaf56f120,python):2024-05-25-17:29:35.762.199 [mindspore/ccsrc/kernel/oplib/op_info_utils.cc:111] GenerateOpInfos] Load op info json failed, version: Ascend310B4
Traceback (most recent call last):
  File "/root/Downloads/mindspore_ascend_demo.py", line 8, in <module>
    print(ops.add(x, y))
  File "/usr/local/miniconda3/envs/mindspore22/lib/python3.9/site-packages/mindspore/common/_stub_tensor.py", line 49, in fun
    return method(*arg, **kwargs)
  File "/usr/local/miniconda3/envs/mindspore22/lib/python3.9/site-packages/mindspore/common/tensor.py", line 486, in __str__
    return str(self.asnumpy())
  File "/usr/local/miniconda3/envs/mindspore22/lib/python3.9/site-packages/mindspore/common/tensor.py", line 924, in asnumpy
    return Tensor_.asnumpy(self)
RuntimeError: Load op info form json config failed, version: Ascend310B4

----------------------------------------------------
- C++ Call Stack: (For framework developers)
----------------------------------------------------
mindspore/ccsrc/plugin/device/ascend/hal/device/ascend_kernel_runtime.cc:431 Init

[ERROR] PIPELINE(230369,e7ffedd76020,python):2024-05-25-17:29:35.824.442 [mindspore/ccsrc/pipeline/jit/pipeline.cc:2311] ClearResAtexit] Check exception before process exit: Load op info form json config failed, version: Ascend310B4

----------------------------------------------------
- C++ Call Stack: (For framework developers)
----------------------------------------------------
mindspore/ccsrc/plugin/device/ascend/hal/device/ascend_kernel_runtime.cc:431 Init

mindspore_ascend 2.1.1 测试失败。

Q:RuntimeError: The device address type is wrong: type name in address:CPU, type name in context:Ascend

RuntimeError: The device address type is wrong: type name in address:CPU, type name in context:Ascend

----------------------------------------------------
- C++ Call Stack: (For framework developers)
----------------------------------------------------
mindspore/ccsrc/plugin/device/ascend/hal/hardware/ge_device_res_manager.cc:72 AllocateMemory

mindspore_ascend 2.2.0 测试失败。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1694259.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【汽车之家注册/登录安全分析报告】

前言 由于网站注册入口容易被黑客攻击&#xff0c;存在如下安全问题&#xff1a; 1. 暴力破解密码&#xff0c;造成用户信息泄露 2. 短信盗刷的安全问题&#xff0c;影响业务及导致用户投诉 3. 带来经济损失&#xff0c;尤其是后付费客户&#xff0c;风险巨大&#xff0c;造…

构建php环境

目录 php简介 官网php安装包 选择下载稳定版本 &#xff08;建议使用此版本&#xff0c;文章以此版本为例&#xff09; 安装php解析环境 准备工作 安装依赖 zlib-devel 和 libxml2-devel包。 安装扩展工具库 安装 libmcrypt 安装 mhash 安装mcrypt 安装php 选项含…

Java——简易图书管理系统

本文使用 Java 实现一个简易图书管理系统 一、思路 简易图书管理系统说白了其实就是 用户 与 图书 这两个对象之间的交互 书的属性有 书名 作者 类型 价格 借阅状态 而用户可以分为 普通用户 管理员 使用数组将书统一管理起来 用户对这个数组进行操作 普通用户可以进…

BUUCTF靶场[Web] [极客大挑战 2019]Havefun1、[HCTF 2018]WarmUp1、[ACTF2020 新生赛]Include

[web][极客大挑战 2019]Havefun1 考点&#xff1a;前端、GET传参 点开网址&#xff0c;发现是这个界面 点击界面没有回显&#xff0c;老规矩查看源代码&#xff0c;看到以下代码 代码主要意思为&#xff1a; 用get传参&#xff0c;将所传的参数给cat&#xff0c;如果catdog…

c++中的命名空间与缺省参数

一、命名空间 1、概念&#xff1a;在C/C中&#xff0c;变量、函数和后面要学到的类都是大量存在的&#xff0c;这些变量、函数和类的名称将都存 在于全局作用域中&#xff0c;可能会导致很多冲突。使用命名空间的目的是对标识符的名称进行本地化&#xff0c; 以避免命名冲突或…

【介绍下Pwn,什么是Pwn?】

&#x1f308;个人主页: 程序员不想敲代码啊 &#x1f3c6;CSDN优质创作者&#xff0c;CSDN实力新星&#xff0c;CSDN博客专家 &#x1f44d;点赞⭐评论⭐收藏 &#x1f91d;希望本文对您有所裨益&#xff0c;如有不足之处&#xff0c;欢迎在评论区提出指正&#xff0c;让我们共…

汽车R155法规中,汽车获取到的VTA证书,E后面的数字表示什么意思?

标签&#xff1a; 汽车R155法规中&#xff0c;汽车获取到的VTA证书&#xff0c;E后面的数字表示什么意思&#xff1f;&#xff1b; 汽车&#xff1b;VTA认证; 有些厂商汽车拿到的VTA证书上面写着E9&#xff0c; 有些厂商汽车拿到的VTA证书上面写着E5&#xff0c;E9与E5有什么差…

华为机考入门python3--(29)牛客29-字符串加解密

分类&#xff1a;字符变换 知识点&#xff1a; 字符是字母 char.isalpha() 字符是小写字母 char.islower() 字符是数字 char.isdigit() b变C chr((ord(b) - ord(a) 1) % 26 ord(A)) 题目来自【牛客】 # 加密 def encrypt_string(s):result ""for ch…

OWASP top10--SQL注入(一)

SQL注入式攻击技术&#xff0c;一般针对基于Web平台的应用程序.造成SQL注入攻击漏洞的原因&#xff0c;是由于程序员在编写Web程序时&#xff0c;没有对浏览器端提交的参数进行严格的过滤和判断。用户可以修改构造参数&#xff0c;提交SQL查询语句&#xff0c;并传递至服务器端…

【408精华知识】主存相关解题套路大揭秘!

讲完了Cache&#xff0c;再来讲讲主存是怎么考察的&#xff0c;我始终认为&#xff0c;一图胜千言&#xff0c;所以对于很多部件&#xff0c;我都是通过画图进行形象的记忆&#xff0c;那么接下来我们对主存也画个图&#xff0c;然后再来详细解读其考察套路~ 文章目录 零、主存…

Linux驱动学习之模块化,参数传递,符号导出

1.模块化 1.1.模块化的基本概念&#xff1a; 模块化是指将特定的功能或组件独立出来&#xff0c;以便于开发、测试和维护。在Linux设备驱动中&#xff0c;模块化允许将驱动程序作为内核模块动态加载到系统中&#xff0c;从而提高了系统的灵活性和可扩展性。 1.2.Linux内核模…

Kata Containers零基础学习从零到一

文章目录 docker和Kata Containers的区别Docker容器共享宿主机内核每个容器实例运行在轻量级虚拟机&#xff08;MicroVM&#xff09;总结 通俗例子Kata Containers架构实际Kata Containers架构图解容器技术栈总结 agent和shim家长&#xff08;shim进程&#xff09;的角色保姆&a…

OpenHarmony 实战开发——一文总结ACE代码框架

一、前言 ACE_Engine框架是OpenAtom OpenHarmony&#xff08;简称“OpenHarmony”&#xff09;的UI开发框架&#xff0c;为开发者提供在进行应用UI开发时所必需的各种组件&#xff0c;以及定义这些组件的属性、样式、事件及方法&#xff0c;通过这些组件可以方便进行OpenHarmo…

java基础-JVM日志、参数、内存结构、垃圾回收器

一、基础基础 1.1 数据类型 Java的数据类型分为原始数据类型和引用数据类型。 原始数据类型又分为数字型和布尔型。 数字型又有byte、short、int、long、char、float、double。注意&#xff0c;在这里char被定义为整数型&#xff0c;并且在规范中明确定义&#xff1a;byte、…

primeflex样式库笔记 Display相关的案例

回顾 宽度设置的基本总结 w-full&#xff1a;表示widtdh&#xff1a;100%&#xff1b;占满父容器的宽度。 w-screen&#xff1a;表示占满整个屏幕的宽度。 w-1到w-12&#xff0c;是按百分比划分宽度&#xff0c;数字越大&#xff0c;占据的比例就越大。 w-1rem到w-30rem&…

推特热帖:大语言模型自荐能够替代的20种人类工作!快来看你是否需要转行!

最近推特上有一个例子引起了广泛的讨论&#xff0c;事情的起因是这样的&#xff1a;网友让 GPT-4o 预测一下自己未来将会替代人类哪些工作&#xff1f; 这听起来很有趣&#xff01;GPT-4o会给出什么样的预测呢&#xff1f; 3.5研究测试&#xff1a;hujiaoai.cn 4研究测试&…

动物合并消除休闲游戏源码 Animal Merge 益智游戏

一款动物合并消除休闲游戏源码&#xff0c;Animal Merge是一款引人入胜的益智游戏&#xff0c;玩家的任务是合并方块&#xff0c;创造出可爱的动物&#xff0c;这些动物的体型会逐渐变大。游戏玩法包括将方块放到网格上&#xff0c;并战略性地将它们合并以形成更大的动物形状。…

数据库--数据库基础(一)

目录 第一章 绪论 一.数据库的基本概念 1. 数据库的4个基本概念 2、数据库系统的特点 二.数据库和文件 三.数据模型 1.概念模型 2.逻辑模型(物理模型) 2.1关系模型 四.数据库系统的三级模式结构&#xff1a; 五数据库的二级映像功能与数据独立性 第二章 关系数据库…

ffpmeg windows WSl 编译so

1.NDK 环境变量配置 2.git clone ffpmeg 3.创建脚本&#xff08;需先下载gcc编译器&#xff09; 64位脚本如下 #!/bin/bashexport NDK/home/test/ndk20 #这里配置先你的 NDK 路径 TOOLCHAIN$NDK/toolchains/llvm/prebuilt/linux-x86_64function build_android {./configure \ …

javas-core VS java-object-diff

对照工具选择 javas-core 和 java-object-diff ,对比demo https://github.com/kofgame/objectdiff-vs-javers&#xff0c;都为同源对比&#xff0c;都支持嵌套对象。 使用JMH测试方法进行性能测试&#xff0c;使用题库的QuestionResponseVO对象来进行对照对比&#xff0c;进行…