已关闭
[Bug-Report|缺陷反馈]: build.sh run_example 判断 libascendcl.so 存在性的 [ ] 缺少空格,导致样例错误走 -lacl_rt 链接分支 #5128
xuejinghui创建于  8 天前关闭于  7 天前
xuejinghui
8 天前 创建

Describe the current behavior / 问题描述 (Mandatory / 必填)

build.shbuild_single_example() 判断 libascendcl.so 是否存在的语句在 ] 前缺少空格:

if [ -f ${EAGER_LIBRARY_PATH}/libascendcl.so ] || [ -f ${EAGER_LIBRARY_OPP_PATH}/libascendcl.so]; then

[ 是命令而非语法符号,] 必须是独立参数。缺少空格时第二个 [ 的参数变成 ...libascendcl.so],执行时报 [: missing ] 并返回非 0,导致整个 if 条件被判定为假,错误地走 -lacl_rt 的旧版链接分支。

后果:在 $ASCEND_HOME_PATH/lib64 下不存在 libascendcl.so 的环境(例如部分商发/裁剪包布局,libascendcl.so 仅存在于 opp 侧),会错误使用 -lacl_rt 链接;若该环境同时没有兼容库 libacl_rt.so,则链接失败、样例二进制未生成,--run_example 以退出码 1 失败。

平时不发作的原因:|| 短路特性——第一个条件为真时(常见 dev 包 lib64 下有 libascendcl.so),有语法错误的第二个 [ 不会被执行,问题被掩盖。

该问题由 PR !391「子包工程编译适配」(commit 7fd59502c)引入,master 与 9.1.0 商发分支均存在。

Environment / 环境信息 (Mandatory / 必填)

  • 硬件:Ascend950(与芯片型号无关,为脚本问题)
  • 软件:触发条件为 $ASCEND_HOME_PATH/lib64 下无 libascendcl.so 的 CANN 布局;若同时无 libacl_rt.so 则链接失败
  • 分支:master / 9.1.0 均存在

Steps to reproduce the issue / 重现步骤 (Mandatory / 必填)

  1. 构造触发环境(模拟商发裁剪布局):
    mv $ASCEND_HOME_PATH/lib64/libascendcl.so /tmp/bak/
    mv $ASCEND_HOME_PATH/lib64/libacl_rt.so /tmp/bak/
    
  2. 运行样例:
    bash build.sh --run_example index eager --soc=ascend950
    
  3. 观察到 [: missing ]cannot find -lacl_rt,样例运行失败,退出码 1

Describe the expected behavior / 预期结果 (Mandatory / 必填)

正确判断 libascendcl.so 存在性:存在时使用 -lascendcl 链接,样例编译并运行成功。

build.sh: line 1567: [: missing `]'
/usr/bin/ld: cannot find -lacl_rt: No such file or directory
collect2: error: ld returned 1 exit status
build.sh: line 1581: /home/xxx/ops-nn/build/test_aclnn_index: No such file or directory
Run eager example failed, op_name: index, success examples: , failed_example: index.

修复后验证(Ascend950 真机,默认模式):

Start to run example,op_name:index example_name:index mode:eager.
result[0] is: 3.000000
Run test_aclnn_index success.

Special notes for this issue/备注 (Optional / 选填)

修复方法:libascendcl.so] 改为 libascendcl.so ]] 前补一个空格),一行改动。

likedislike
Xxuejinghui
8 天前 修改了issue 的描述
Xxuejinghui
8 天前 修改了issue 的描述
xuejinghui
8 天前 评论:

/assign

likedislike
CANN-robotCANN-robot成员
8 天前 将 xuejinghui 设为负责人
CANN-robotCANN-robot成员
7 天前 关闭了 issue
CANN-robotCANN-robot成员
7 天前 添加了label:resolved