算子开发入门hello world程序编译时报错解决办法。
收藏回复举报
算子开发入门hello world程序编译时报错解决办法。
发表于2024-07-15 12:45:48
0 查看

背景

  1. 参考官方的算子开发快速入门教程:HelloWorld,完整源码在gitee
  2. 我的环境:香橙派 AI Pro 20T, CANN版本:8.0RC1alpha3
  3. 运行日志:
    (base) root@orangepiaipro-20t:~/Programs/CANN_study/samples/operator/HelloWorldSample# ./run.sh -v Ascend310B1
    -- The C compiler identification is GNU 11.4.0
    -- The CXX compiler identification is GNU 11.4.0
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    -- Check for working C compiler: /usr/bin/cc - skipped
    -- Detecting C compile features
    -- Detecting C compile features - done
    -- Detecting CXX compiler ABI info
    -- Detecting CXX compiler ABI info - done
    -- Check for working CXX compiler: /usr/bin/c++ - skipped
    -- Detecting CXX compile features
    -- Detecting CXX compile features - done
    -- Configuring done
    -- Generating done
    -- Build files have been written to: /root/Programs/CANN_study/samples/operator/HelloWorldSample/build
    [  3%] Creating directories for 'kernels_preprocess'
    [  7%] No download step for 'kernels_preprocess'
    [ 10%] No update step for 'kernels_preprocess'
    [ 14%] No patch step for 'kernels_preprocess'
    [ 17%] Performing configure step for 'kernels_preprocess'
    -- The C compiler identification is GNU 11.4.0
    -- The CXX compiler identification is GNU 11.4.0
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    -- Check for working C compiler: /usr/bin/cc - skipped
    -- Detecting C compile features
    -- Detecting C compile features - done
    -- Detecting CXX compiler ABI info
    -- Detecting CXX compiler ABI info - done
    -- Check for working CXX compiler: /usr/bin/c++ - skipped
    -- Detecting CXX compile features
    -- Detecting CXX compile features - done
    -- Configuring done
    -- Generating done
    -- Build files have been written to: /root/Programs/CANN_study/samples/operator/HelloWorldSample/build/kernels_preprocess-prefix/src/kernels_preprocess-build
    [ 21%] Performing build step for 'kernels_preprocess'
    [100%] Building CXX object CMakeFiles/preprocess_obj.dir/root/Programs/CANN_study/samples/operator/HelloWorldSample/hello_world.cpp.o
    bisheng: error: unknown argument: '-fcce-no-kernel-type-section'
  4. 报错信息:
    bisheng: error: unknown argument: '-fcce-no-kernel-type-section'

解决办法

  1. 看报错信息,应该是bisheng没有'-fcce-no-kernel-type-section'这个参数。我们可以通过下面的命令查看bisheng编译器的所有可用参数,并且参数信息保存到bisheng_help.log中。

    bisheng --help > bisheng_help.log
  2. 打开这个bisheng_help.log文件,搜索fcce关键字,确实没有看到'-fcce-no-kernel-type-section',但是有看到下面两个类似的参数,从参数定义来看,-fcce-kernel-type-section更为接近,估计是换成这个参数了。

    -fcce-kernel-launch-custom
                              Transform the kernel launch expression to a user-defined host function. Please be aware that this option changes the compilation behavior of cce host-side.
      -fcce-kernel-type-section
                              Generate meta sections for kernel types.
  3. 解决思路,我们需要将-fcce-no-kernel-type-section换成bisheng编译器支持的-fcce-kernel-type-section,可以通过grep命令去CANN安装路径去搜索这个参数。

    cd /usr/local/Ascend/ascend-toolkit
    grep "fcce-no-kernel-type-section" -r ./*
    
    # 搜索结果如下:
    ./8.0/aarch64-linux/tikcpp/ascendc_kernel_cmake/bisheng_intf.cmake:    "SHELL:-fcce-no-kernel-type-section"
    ./8.0/python/site-packages/ascendctools/auto_debug/npu/npu_compiler.py:            compile_cmds.extend(['-fcce-no-kernel-type-section'])
    
    ./8.0.RC1/aarch64-linux/tikcpp/ascendc_kernel_cmake/bisheng_intf.cmake:    "SHELL:-fcce-no-kernel-type-section"
    ./8.0.RC1/python/site-packages/ascendctools/auto_debug/npu/npu_compiler.py:            compile_cmds.extend(['-fcce-no-kernel-type-section'])
  4. 可以看到搜到4个文件,其实8.0就是8.0RC的软链接,不信我们可以用下面的命令测试一下:

    cd /usr/local/Ascend/ascend-t
    total 12K
    lrwxrwxrwx  1 root root    9 Jul 10 13:47 8.0 -> ./8.0.RC1
    drwxr-xr-x 17 root root 4.0K Jul 10 14:02 8.0.RC1
    drwxr-xr-x  5 root root 4.0K Jul 10 14:02 latest
  5. 所以理论上来说,只修改2个文件就行,这里我修改8.0RC对应的两个文件,将-fcce-no-kernel-type-section换成-fcce-kernel-type-section即可。

  6. 修改完后,删除build目录,重新编译一次,可以编译通过。但是print没有输出,看了一下代码,CANN 8.0RC1beta3版,里面的print确实是啥也没干。

    // printf关联了AscendC::PRINTF
    #define print PRINTF
    
    template <class... Args>
    __aicore__ inline void PRINTF(__gm__ const char* fmt, Args&&... args)
    {
    // 不走上面的分支,走else分支,所以啥也没干
    #ifdef ASCENDC_DUMP
        printfImpl(fmt, args...);
    #else
        return;
    #endif
    }
  7. 但是文档写的确实有print出来东西,怀疑是CANN8.0RC2alpha3支持printf函数输出东西,于是我又升级了一下CANN8.0RC2alpha3版本,但是还是没有数据,也没有报错,看了一下printf接口的实现,确实也是空的,所以暂时不管了。

本帖最后由 匿名用户2024/07/18 16:09:09 编辑

我要发帖子