检测PyTorch接口调用的算子

前提条件

操作步骤

  1. 执行以下命令,生成自定义算子工程,并进行host侧和kernel侧的算子实现。

    bash install.sh -v Ascendxxxyy    # xxxyy为用户实际使用的具体芯片类型

  2. 参考算子编译部署,完成算子的编译部署。

    编辑样例工程目${git_clone_path}/samples/operator/ascendc/0_introduction/1_add_frameworklaunch/CustomOp/op_kernel下的CMakeLists.txt文件,增加编译选项-sanitizer。

    add_ops_compile_options(ALL OPTIONS -sanitizer )

  3. 进入PyTorch接入工程,使用PyTorch调用方式调用AddCustom算子工程,并按照指导完成编译。

    1
    2
    3
    4
    PytorchInvocation
    ├── op_plugin_patch         
    ├── run_op_plugin.sh      //  5.执行样例时,需要使用
    └── test_ops_custom.py    //  步骤6启动工具时,需要使用
    

  4. 执行样例,样例执行过程中会自动生成测试数据,然后运行PyTorch样例,最后检验运行结果。

     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
    bash run_op_plugin.sh
    -- CMAKE_CCE_COMPILER: ${INSTALL_DIR}/toolkit/tools/ccec_compiler/bin/ccec
    -- CMAKE_CURRENT_LIST_DIR: ${INSTALL_DIR}/AddKernelInvocation/cmake/Modules
    -- ASCEND_PRODUCT_TYPE:
      Ascendxxxyy
    -- ASCEND_CORE_TYPE:
      VectorCore
    -- ASCEND_INSTALL_PATH:
      /usr/local/Ascend/ascend-toolkit/latest
    -- The CXX compiler identification is GNU 10.3.1
    -- 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: ${INSTALL_DIR}/AddKernelInvocation/build
    Scanning dependencies of target add_npu
    [ 33%] Building CCE object cmake/npu/CMakeFiles/add_npu.dir/__/__/add_custom.cpp.o
    [ 66%] Building CCE object cmake/npu/CMakeFiles/add_npu.dir/__/__/main.cpp.o
    [100%] Linking CCE executable ../../../add_npu
    [100%] Built target add_npu
    ${INSTALL_DIR}/AddKernelInvocation
    INFO: compile op on ONBOARD succeed!
    INFO: execute op on ONBOARD succeed!
    test pass
    

  5. 启动msSanitizer工具拉起Python程序,进行异常检测,异常检测功能的开启原则请参见异常检测功能启用原则
  6. 参考内存异常报告解析竞争异常报告解析未初始化异常报告解析分析异常行为。