MindStudio制作MindSpore TBE算子(四)算子测试(ST测试-香橙派AI pro--失败)

在前两次分别尝试用vmware和ModelArts的910B芯片进行算子测试的时候,发现无法完成ST测试,详情查看:
MindStudio制作MindSpore TBE算子(三)算子测试(ST测试)
MindStudio制作MindSpore TBE算子(四)算子测试(ST测试-Ascend910B/ModelArts)–失败尝试
这里我重整旗鼓,在香橙派上执行测试功能。

一、环境准备

1.1 配置CANN环境

这里配置的时候使用普通用户即可,如果使用ROOT用户可能会导致执行的时候多出许多permission报错

wget https://ascend-repo.obs.cn-east-2.myhuaweicloud.com/CANN/CANN%208.0.0/Ascend-cann-toolkit_8.0.0_linux-aarch64.run
chmod +x Ascend-cann-toolkit_8.0.0_linux-aarch64.run
./Ascend-cann-toolkit_8.0.0_linux-aarch64.run --install

1.2 配置AI PRO的mindspore环境

可以参考:

AI pro搭建Mindspore环境
补充kernel算子包

wget https://ascend-repo.obs.cn-east-2.myhuaweicloud.com/CANN/CANN%208.0.0/Ascend-cann-kernels-310b_8.0.0_linux-aarch64.run
chmod +x Ascend-cann-kernels-310b_8.0.0_linux-aarch64.run
./Ascend-cann-kernels-310b_8.0.0_linux-aarch64.run --install

安装完成后,会出现success的标志,继续安装Mindspore环境

conda create -n mindspore python=3.9 -y
conda activate mindspore
pip install --upgrade pip setuptools
pip install https://ms-release.obs.cn-north-4.myhuaweicloud.com/2.5.0/MindSpore/unified/aarch64/mindspore-2.5.0-cp39-cp39-linux_aarch64.whl --trusted-host ms-release.obs.cn-north-4.myhuaweicloud.com -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install ml-dtypes cloudpickle decorator attrs sympy 

这里可能显示有一些包的依赖关系没有构建完成,如果缺少的话就继续安装。可以利用python解释器进行验证,如果没有error报错,证明依赖基本安装完成。

(mindspore) HwHiAiUser@orangepiaipro:~/MyAscend$ python
Python 3.9.21 (main, Dec 11 2024, 16:27:47) 
[GCC 11.2.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import mindspore
[INFO] RUNTIME(224331,python):2025-02-13-13:41:11.437.848 [task_fail_callback_manager.cc:52] 224331 TaskFailCallBackManager: Constructor.
[INFO] HCCL(224331,python):2025-02-13-13:41:11.513.351 [adapter_rts.cc:2646][224331][adapter_rts.cc][CallBackInitRts] g_deviceType [6] g_deviceLogicId [-1] g_devicePhyId [-1]
[EVENT] PROFILING(224331,python):2025-02-13-13:41:11.947.471 [msprof_callback_impl.cpp:336] >>> (tid:224331) Started to register profiling ctrl callback.
[EVENT] PROFILING(224331,python):2025-02-13-13:41:11.948.105 [msprof_callback_impl.cpp:343] >>> (tid:224331) Started to register profiling hash id callback.
[INFO] PROFILING(224331,python):2025-02-13-13:41:11.948.297 [prof_atls_plugin.cpp:117] (tid:224331) RegisterProfileCallback, callback type is 7
[EVENT] PROFILING(224331,python):2025-02-13-13:41:11.948.446 [msprof_callback_impl.cpp:350] >>> (tid:224331) Started to register profiling enable host freq callback.
[INFO] PROFILING(224331,python):2025-02-13-13:41:11.948.572 [prof_atls_plugin.cpp:117] (tid:224331) RegisterProfileCallback, callback type is 8
[INFO] RUNTIME(224331,python):2025-02-13-13:41:12.436.374 [runtime.cc:5471] 224331 GetVisibleDevices: ASCEND_RT_VISIBLE_DEVICES param was not set
[INFO] PROFILING(224331,python):2025-02-13-13:41:12.437.265 [prof_atls_plugin.cpp:210] (tid:224331) Module[7] register callback of ctrl handle.
/home/HwHiAiUser/.conda/envs/mindspore/lib/python3.9/site-packages/numpy/core/getlimits.py:549: UserWarning: The value of the smallest subnormal for <class 'numpy.float64'> type is zero.
  setattr(self, word, getattr(machar, word).flat[0])
/home/HwHiAiUser/.conda/envs/mindspore/lib/python3.9/site-packages/numpy/core/getlimits.py:89: UserWarning: The value of the smallest subnormal for <class 'numpy.float64'> type is zero.
  return self._float_to_str(self.smallest_subnormal)
/home/HwHiAiUser/.conda/envs/mindspore/lib/python3.9/site-packages/numpy/core/getlimits.py:549: UserWarning: The value of the smallest subnormal for <class 'numpy.float32'> type is zero.
  setattr(self, word, getattr(machar, word).flat[0])
/home/HwHiAiUser/.conda/envs/mindspore/lib/python3.9/site-packages/numpy/core/getlimits.py:89: UserWarning: The value of the smallest subnormal for <class 'numpy.float32'> type is zero.
  return self._float_to_str(self.smallest_subnormal)
>>> 

为AI pro安装本地的MindStudio

wget https://ascend-repo.obs.cn-east-2.myhuaweicloud.com/MindStudio/MindStudio%207.0.0/MindStudio_7.0.0_linux_aarch64.tar.gz
tar -xzvf MindStudio_7.0.0_linux_aarch64.tar.gz

安装完成后在Mindstudio开始配置信息,添加AI Pro信息
在这里插入图片描述
在这里插入图片描述
大概等待5分钟左右,即可完成配置。之后内容可以参考前期重复创建算子:MindStudio制作MindSpore TBE算子(一)算子制作

1.2 配置远程Python解释器

点击右上角设置,项目结构中设置sdk。
在这里插入图片描述
这里配置对应路径下的python解释器,这里虽然没有解析出python的包,但是不影响执行。
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

二、代码准备

将准备好的代码载入到impl文件,如果函数名调用有错误,需要根据实际情况修改。

from __future__ import absolute_import
from tbe import tvm
import tbe.dsl as tbe
from tbe.common.register import register_op_compute
from tbe.common.utils import shape_refine
from tbe.common.utils import shape_util
from tbe.common.utils import para_check
from functools import reduce
from mindspore.ops.op_info_register import op_info_register, TBERegOp, DataType

SHAPE_SIZE_LIMIT = 2147483648


@register_op_compute("add_custom")
def add_custom_compute(x, y):
    """
    The compute function of the Addcustom implementation.
    """
    # shape转为list
    shape_x = shape_util.shape_to_list(x.shape)
    shape_y = shape_util.shape_to_list(y.shape)

    # shape_max取shape_x与shape_y的每个维度的大值
    shape_x, shape_y, shape_max = shape_util.broadcast_shapes(shape_x, shape_y,
                                                              param_name_input1="input_x",
                                                              param_name_input2="input_y")
    shape_size = reduce(lambda x, y: x * y, shape_max[:])
    if shape_size > SHAPE_SIZE_LIMIT:
        raise RuntimeError("the shape is too large to calculate")

    # 将input_x的shape广播为shape_max
    input_x = tbe.broadcast(x, shape_max)
    input_y = tbe.broadcast(y, shape_max)

    # 执行input_x + input_y
    res = tbe.vadd(input_x, input_y)

    return res


# Define the kernel info of AddCustom.
add_custom_op_info = TBERegOp("AddCustom") \
    .fusion_type("OPAQUE") \
    .partial_flag(True) \
    .async_flag(False) \
    .binfile_name("add_custom.so") \
    .compute_cost(10) \
    .kernel_name("add_custom_impl") \
    .input(0, "x", False, "required", "all")\
    .input(1, "y", False, "required", "all")\
    .output(0, "z", False, "required", "all")\
    .dtype_format(DataType.F16_Default, DataType.F16_Default, DataType.F16_Default)\
    .get_op_info()


# Binding kernel info with the kernel implementation.
@op_info_register(add_custom_op_info)
def add_custom_impl(x, y, z, kernel_name="add_custom_impl"):
    """
    The entry function of the AddCustom implementation.
    """
    """
    The entry function of the Addcustom implementation.
    """
    # 获取算子输入tensor的shape与dtype
    shape_x = x.get("shape")
    shape_y = y.get("shape")

    # 检验算子输入类型
    check_tuple = ("float16")
    input_data_type = x.get("dtype").lower()
    para_check.check_dtype(input_data_type, check_tuple, param_name="input_x")

    # shape_max取shape_x与shape_y的每个维度的最大值
    shape_x, shape_y, shape_max = shape_util.broadcast_shapes(shape_x, shape_y,
                                                              param_name_input1="x",
                                                              param_name_input2="y")
    # 如果shape的长度等于1,就直接赋值,如果shape的长度不等于1,做切片,将最后一个维度舍弃(按照内存排布,最后一个维度为1与没有最后一个维度的数据排布相同,例如2*3=2*3*1,将最后一个为1的维度舍弃,可提升后续的调度效率)
    if shape_x[-1] == 1 and shape_y[-1] == 1 and shape_max[-1] == 1:
        shape_x = shape_x if len(shape_x) == 1 else shape_x[:-1]
        shape_y = shape_y if len(shape_y) == 1 else shape_y[:-1]
        shape_max = shape_max if len(shape_max) == 1 else shape_max[:-1]

    # 使用TVM的placeholder接口对输入tensor进行占位,返回一个tensor对象
    data_x = tvm.placeholder(shape_x, name="data_1", dtype=input_data_type)
    data_y = tvm.placeholder(shape_y, name="data_2", dtype=input_data_type)

    with tvm.target.cce():
        # 计算过程
        res = add_custom_compute(data_x, data_y)
        # 自动调度模块
        sch = tbe.auto_schedule(res)
    # 配置编译信息
    config = {"print_ir": False,
              "name": kernel_name,
              "tensor_list": [data_x, data_y, res]}

    tbe.build(sch, config)

# # 算子调用,测试算子计算正确性
if __name__ == '__main__':
    input_output_dict = {"shape": (5, 6, 7),"format": "ND","ori_shape": (5, 6, 7),"ori_format": "ND", "dtype": "float16"}
    add_custom_impl(input_output_dict, input_output_dict, input_output_dict, kernel_name="add")

三、ST测试

在这里插入图片描述
这里遇到了一些麻烦,创建的ST测试的json一直无法弹出,因此只能使用AI Pro本地的MindStudio,如果可以正常弹出的,远程继续即可。

3.1 问题确定

进入MindStudio的安装路径,启动MindStudio

cd bin
bash MindStudio.sh

在这里插入图片描述
这里百思不得其解,为什么不能够识别到正确的mindspore,明明我安装了啊,突然想到之前的配置,要在mindspore环境下安装CANN算子,因此这里将CANN算子卸载后,切到mindspore虚拟python环境下重新安装了算子,即可解决此问题。

3.2 ST算子测试

  1. 弄好环境后,这里就可以new st case
    在这里插入图片描述
  2. 配置工具链
    在这里插入图片描述
  3. 增加新配置,并补充相关软件,这里看到系统缺乏gdb
    在这里插入图片描述
  4. 安装gdb
    sudo apt install gdb -y
    
    在这里插入图片描述
  5. 之后选择对应的system解释器,执行run工具
    在这里插入图片描述
  6. 开始测试
    在这里插入图片描述
    如果有缺少什么依赖,可以继续补全
pip install pytest
  1. 报错适配器问题
    到这里,AI pro开发CANN算子的路径是堵死了,可能只能找个有权限的910服务器来进行相关研究了。
    在这里插入图片描述
    在这里插入图片描述
<think>嗯,用户想了解Excel中的VLOOKUP函数的用法和参数含义。首先,我需要回忆一下VLOOKUP的基本结构。VLOOKUP是垂直查找函数,用于在表格的首列查找指定的值,然后返回该行中指定列的数据。它的四个参数分别是查找值、表格范围、列索引号和匹配模式。 接下来,我得确认每个参数的具体作用。第一个参数是lookup_value,也就是用户要查找的值,比如产品ID或者姓名。第二个参数是table_array,即查找的范围,这里要注意的是,查找值必须位于这个范围的第一列,否则函数无法正确工作。第三个参数是col_index_num,也就是用户想要返回的数据在表格范围中的第几列,这个列数是从表格范围的第一列开始算起的,不是整个工作表的列。第四个参数是range_lookup,决定是精确匹配还是近似匹配,通常用FALSE或0来指定精确匹配,避免错误。 然后,用户可能需要一个具体的例子来理解如何使用。比如,假设有一个产品价格表,用户想根据产品ID查找对应的价格。这时候,VLOOKUP就可以在ID列查找,然后返回价格列的数据。同时,要提醒用户注意表格范围最好使用绝对引用,比如$A$2:$C$100,这样在拖动公式时范围不会变化。 可能遇到的问题也需要考虑。比如,如果查找值不在表格的第一列,或者列索引号超过了表格的列数,函数会返回错误。此外,数据格式不一致也可能导致问题,比如查找值是数字,而表格中是文本格式的数字,这时候需要统一格式。还有,当出现#N/A错误时,可能是查找值不存在,或者匹配模式设置不正确,需要检查参数是否正确。 用户可能还会问到如何避免常见的错误,比如部分数据匹配出错的情况。这时候需要检查是否有多余的空格,或者数据格式不一致,或者表格范围没有锁定导致拖动时偏移。此外,XLOOKUP作为VLOOKUP的升级版,可能在某些情况下更方便,比如可以向左查找或者返回多列数据,这也是可以提及的内容。 最后,整理步骤,从基础语法到参数说明,再到具体案例,逐步引导用户理解如何使用VLOOKUP函数。同时,提供常见错误和解决方法,帮助用户在实际应用中避免问题。如果有必要,还可以比较VLOOKUP和其他查找函数的区别,比如HLOOKUP或XLOOKUP,但根据用户的问题,主要集中在VLOOKUP本身即可。</think>### Excel VLOOKUP函数详解 #### 一、基础语法与参数说明 VLOOKUP函数的语法为: $$=VLOOKUP(lookup\_value, table\_array, col\_index\_num, [range\_lookup])$$ 包含4个参数: 1. **lookup_value**(必填):要查找的值(如单元格引用或具体值) 2. **table_array**(必填):包含数据的表格范围(必须包含查找列和返回列) 3. **col_index_num**(必填):返回值所在列的序号(从table_array第一列开始计数) 4. **range_lookup**(可选):匹配类型 - `TRUE`/`1`:近似匹配(默认值,需数据升序排列) - `FALSE`/`0`:精确匹配(常用选项) [^1][^2] #### 二、使用步骤演示(工资表查询案例) 假设需要根据员工编号查询工资: 1. 建立查询单元格(如`B12`) 2. 输入公式: ```excel =VLOOKUP(A12, $A$2:$D$100, 4, 0) ``` - `A12`:待查询的员工编号 - `$A$2:$D$100`:锁定数据区域(绝对引用) - `4`:返回第4列(工资列) - `0`:精确匹配 [^2][^3] #### 三、常见错误与解决方法 | 错误现象 | 原因 | 解决方案 | |---------|------|---------| | #N/A | 查找值不存在 | 检查数据源或改用`IFERROR`容错 | | #REF! | 列序号超出范围 | 确认col_index_num ≤ 表格列数 | | 部分匹配失败 | 数据格式不一致 | 统一数值/文本格式 | | 结果错位 | 表格未锁定 | 使用`$`符号固定区域引用 | [^3][^4] #### 四、进阶技巧 1. **多条件查询**: 使用辅助列合并多个条件字段 ```excel =VLOOKUP(A2&B2, $D$2:$F$100, 3, 0) ``` 2. **通配符匹配**: `"*"`匹配任意字符,`"?"`匹配单个字符 ```excel =VLOOKUP("张*", $A$2:$C$100, 3, 0) ``` 3. **跨表查询**: 引用其他工作表数据 ```excel =VLOOKUP(A2, Sheet2!$A$2:$D$100, 4, 0) ``` [^1][^4]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值