本工具针对任意场景下算子编译生成的ELF文件(Executable and Linkable Format)提供解析和解压功能,并将结果信息以可读格式呈现,方便开发者直观获得kernel文件信息。
ELF文件是一种用于二进制文件、可执行文件、目标代码、共享库和核心转储的文件格式,包括常见的*.a、*.so文件等。ELF文件构成如下:
ELF文件主要用于Linux和其他类Unix操作系统中,用于程序的执行和链接。
工具跟随CANN软件包发布(参考环境准备完成CANN安装),其路径默认为“${INSTALL_DIR}/tools/ascendc_tools/msobjdump”,其中${INSTALL_DIR}请替换为CANN软件安装后文件存储路径。例如,若安装的Ascend-cann-toolkit软件包,则安装后文件存储路径为:$HOME/Ascend/ascend-toolkit/latest。
1 2 | source /usr/local/Ascend/ascend-toolkit/set_env.sh source /usr/local/Ascend/ascend-toolkit/latest/toolkit/bin/setenv.bash |
1 2 | source ${HOME}/Ascend/ascend-toolkit/set_env.sh source ${HOME}/Ascend/ascend-toolkit/latest/toolkit/bin/setenv.bash |
1 | msobjdump -h |
解析ELF文件内部信息,如文件长度、 文件类型信息、每个文件的段信息、符号表信息等,命令样式如下:
1 | msobjdump --dump-elf ${elf_file} |
其中${elf_file}为待解析ELF文件路径,如/home/op_api/lib_api.so。
解压ELF文件并落盘到指定目录,命令样式如下:
1 | msobjdump --extract-elf ${elf_file} --out-dir ${out_path} |
其中${elf_file}为待解压ELF文件路径,如/home/op_api/lib_api.so;${out_path}为落盘文件目录,如/home/extract/。若不设置--out-dir,工具默认将解压文件落盘到当前执行路径下。
终端打印所有device.o文件列表,命令样式如下:
1 | msobjdump --list-elf ${elf_file} |
其中${elf_file}为待打印的ELF文件路径,如/home/op_api/lib_api.so。
工具全量命令参数说明请参考表1。
功能参数 (区分大小写) |
功能说明 |
是否必选 |
---|---|---|
-d,--dump-elf |
解析ELF文件中包含的每个device.o文件的文件长度、 文件类型、符号表等信息,并在终端屏显,关键字段含义参见表2。 |
三选一,必选 |
-e,--extract-elf |
解压ELF文件中包含的每个device.o/device.json文件,并按原始文件夹规则落盘到输出路径下。 若未指定--out-dir参数,默认落盘到当前执行路径下。 |
|
-l,--list-elf |
打屏显示输ELF文件中包含的device.o文件列表。 |
|
-o,--out-dir |
解压文件的落盘路径, 需要与--extract-elf参数配套使用。 说明:
msobjdump支持多用户并发调用,但需要指定不同的--out-dir,否则可能出现落盘内容被覆盖的问题。 |
否 |
关键字段 |
说明 |
是否必选 |
---|---|---|
VERSION |
版本号。 |
否 |
TYPE COUNT |
当前section段包含的kernel文件个数。 |
|
ELF FILE ${id} |
罗列的kernel文件,文件名是按照 ${sec_prefix}_${file_index}_${kernel_type}.o 拼接而成,其中${sec_prefix}为section段名(工具根据“.ascend.kernel”关键字搜索获取),${file_index}表示文件编号,${kernel_type}表示kernel类型。 |
|
KERNEL TYPE |
当前kernel文件的类型,映射关系为{0 : 'mix', 1: 'aiv', 2: 'aic'}。 |
|
KERNEL LEN |
当前kernel文件的长度。 |
|
elf heard infos |
包括ELF Header、Section Headers、Key to Flags、Program Headers、Symbol表等信息。 |
是 |
以MatMulInvocationNeo算子为例(单击Link获取样例工程),假设${cmake_install_dir}为算子Cmake编译产物根目录,产物目录结构如下,类似CMake编译配置文件编写。
1 2 3 4 5 6 7 | out ├── lib │ ├── libascendc_kernels_npu.so ├── include │ ├── ascendc_kernels_npu │ ├── aclrtlaunch_matmul_custom.h │ ├── aclrtlaunch_triple_chevrons_func.h |
工具对编译生成的库文件(如*.so、*.a等)进行解析和解压,功能实现命令样例如下:
1 | msobjdump --dump-elf ${cmake_install_dir}/out/libascendc_kernels_npu.so |
执行命令后,终端会打印所有device信息,示例如下,字段含义参见表2。
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | =========================== [VERSION]: 1 [TYPE COUNT]: 1 =========================== [ELF FILE 0]: ascendxxxb1_ascendc_kernels_npu_0_mix.o [KERNEL TYPE]: mix [KERNEL LEN]: 511560 ====== [elf heard infos] ====== ELF Header: Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 Class: ELF64 Data: 2's complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: EXEC (Executable file) Machine: <unknown>: 0x1029 Version: 0x1 Entry point address: 0x0 Start of program headers: 64 (bytes into file) Start of section headers: 510280 (bytes into file) Flags: 0x940000 Size of this header: 64 (bytes) Size of program headers: 56 (bytes) Number of program headers: 2 Size of section headers: 64 (bytes) Number of section headers: 20 Section header string table index: 18 Section Headers: [Nr] Name Type Address Off Size ES Flg Lk Inf Al [ 0] NULL 0000000000000000 000000 000000 00 0 0 0 [ 1] .text PROGBITS 0000000000000000 0000b0 010a08 00 AX 0 0 4 ..................................................................................... [19] .strtab STRTAB 0000000000000000 071278 00b6cb 00 0 0 1 Key to Flags: W (write), A (alloc), X (execute), M (merge), S (strings), I (info), L (link order), O (extra OS processing required), G (group), T (TLS), C (compressed), x (unknown), o (OS specific), E (exclude), D (mbind), p (processor specific) There are no section groups in this file. Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align LOAD 0x0000b0 0x0000000000000000 0x0000000000000000 0x010aa8 0x010aa8 R E 0x1000 GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW 0 ...... |
1 | msobjdump --extract-elf ${cmake_install_dir}/out/libascendc_kernels_npu.so |
执行命令后,默认在当前执行路径下落盘ascendxxxb1_ascendc_kernels_npu_0_mix.o文件。
1 | msobjdump --list-elf ${cmake_install_dir}/out/libascendc_kernels_npu.so |
执行命令后,终端会打印所有文件,屏显样例如下:
1 | ELF file 0: ascendxxxb1_ascendc_kernels_npu_0_mix.o |
以下面的算子工程为例,假设${cmake_install_dir}为算子Cmake编译产物根目录,产物目录结构如下,类似算子工程编译。
1 2 3 4 5 6 7 | ├── op_api │ ├── include │ ├── aclnn_acos_custom.h │ ├── aclnn_matmul_leakyrelu_custom.h │ ├── ......... │ ├── lib │ ├── libcust_opapi.so |
工具对编译生成的库文件(如*.so、*.a等)进行解析和解压,功能实现命令样例如下:
1 | msobjdump --dump-elf ${cmake_install_dir}/op_api/lib/libcust_opapi.so |
执行命令后,终端会打印每个算子device.o的section段、符号表信息,示例如下,字段含义参见表2。
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | ===== [elf heard infos] in ascendxxx_acos_custom_AcosCustom_da824ede53d7e754f85c14b9446ec2fc.o =====: ELF Header: Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 Class: ELF64 Data: 2's complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ............................................ Size of program headers: 56 (bytes) Number of program headers: 3 Size of section headers: 64 (bytes) Number of section headers: 9 Section header string table index: 7 Section Headers: [Nr] Name Type Address Off Size ES Flg Lk Inf Al [ 0] NULL 0000000000000000 000000 000000 00 0 0 0 ..................................................................................... [ 8] .strtab STRTAB 0000000000000000 00529b 000119 00 0 0 1 Key to Flags: W (write), A (alloc), X (execute), M (merge), S (strings), I (info), L (link order), O (extra OS processing required), G (group), T (TLS), C (compressed), x (unknown), o (OS specific), E (exclude), D (mbind), p (processor specific) ...................... ===== [elf heard infos] in ascendxxx_matmul_leakyrelu_custom_MatmulLeakyreluCustom_e052bee3255764ac919095f3bdf83389.o =====: ELF Header: Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 Class: ELF64 Data: 2's complement, little endian Version: 1 (current) ............................................. Section header string table index: 6 Section Headers: [Nr] Name Type Address Off Size ES Flg Lk Inf Al [ 0] NULL 0000000000000000 000000 000000 00 0 0 0 [ 1] .text PROGBITS 0000000000000000 0000e8 007ed8 00 AX 0 0 4 [ 2] .data PROGBITS 0000000000008000 0080e8 000008 00 WA 0 0 256 [ 3] .comment PROGBITS 0000000000000000 0080f0 000043 01 MS 0 0 1 [ 4] .bl_uninit NOBITS 0000000000000000 008133 000020 00 0 0 1 [ 5] .symtab SYMTAB 0000000000000000 008138 0000c0 18 7 1 8 [ 6] .shstrtab STRTAB 0000000000000000 0081f8 00003b 00 0 0 1 [ 7] .strtab STRTAB 0000000000000000 008233 0000ec 00 0 0 1 .................................. |
1 | msobjdump --extract-elf ${cmake_install_dir}/op_api/lib/libcust_opapi.so |
执行命令后,默认在当前执行路径下保存解压文件,产物目录如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | |-- config // 算子原型配置文件目录 | ├── ${soc_version} | ├── acos_custom.json | ├── matmul_leakyrelu_custom.json | ├── ....... |-- ${soc_version} // 昇腾AI处理器名 | ├── acos_custom // 基础单算子编译文件*.o和对应的*.json文件 | ├── AcosCustom_da824ede53d7e754f85c14b9446ec2fc.json // 命名规则:${op_type}_${parm_info}.json或${op_type}_${parm_info}.o,${parm_info}是基于算子输入/输出dtype、shape等信息生成的标识码 | ├── AcosCustom_da824ede53d7e754f85c14b9446ec2fc.o | ├── AcosCustom_dad9c8ca8fcbfd789010c8b1c0da8e26.json | ├── AcosCustom_dad9c8ca8fcbfd789010c8b1c0da8e26.o | ├── matmul_leakyrelu_custom | ├── MatmulLeakyreluCustom_e052bee3255764ac919095f3bdf83389.json | ├── MatmulLeakyreluCustom_e052bee3255764ac919095f3bdf83389.o | ├── axpy_custom | ├── ..... |
以acos_custom算子编译产物解压为例:
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | { "binList": [ { "implMode": "high_performance", "int64Mode": false, "simplifiedKeyMode": 0, "simplifiedKey": [...], "staticKey": "96b2b4bb2e35fa3db8c2714828d6e4f367b0731c9514401e1a2d41ebd63833c7,ee37ce8796ef139ded8f105c019b2819f38447bdeeb8ff7f58430228e6d9a361", "inputs": [ { "name": "x", "index": 0, "dtype": "float32", "format": "ND", "paramType": "required", "shape": [ -2 ], "format_match_mode": "FormatAgnostic" } ], "outputs": [ { "name": "y", "index": 0, "dtype": "float32", "format": "ND", "paramType": "required", "shape": [ -2 ], "format_match_mode": "FormatAgnostic" } ], "attrs": [ { "name": "tmp", "dtype": "int", "value": 0 }, ................ } |
1 | msobjdump --dump-elf ./AcosCustom_da824ede53d7e754f85c14b9446ec2fc.o |
执行命令后,终端屏显信息如下,参数说明参见表3、表4、表5。
1 2 3 4 5 6 7 8 9 10 11 12 13 | .ascend.meta. [0]: AcosCustom_da824ede53d7e754f85c14b9446ec2fc_1 T: 1 L: 4 V: 3 F_TYPE_KTYPE: K_TYPE_AIV .ascend.meta. [0]: AcosCustom_da824ede53d7e754f85c14b9446ec2fc_2_mix_aiv T: 1 L: 4 V: 5 F_TYPE_KTYPE: K_TYPE_MIX_AIV_MAIN T: 3 L: 4 V: [0:1] F_TYPE_MIX_TASK_RATION: [0:1] .ascend.meta. [0]: AcosCustom_da824ede53d7e754f85c14b9446ec2fc_3_mix_aiv T: 1 L: 4 V: 5 F_TYPE_KTYPE: K_TYPE_MIX_AIV_MAIN T: 3 L: 4 V: [0:1] F_TYPE_MIX_TASK_RATION: [0:1] |
解析类型 |
解析类型映射 |
说明 |
---|---|---|
1 |
F_TYPE_KTYPE |
表示kernel type。 |
2 |
F_TYPE_CROSS_CORE_SYNC |
表示硬同步syncall类型。 |
3 |
F_TYPE_MIX_TASK_RATION |
表示核函数运行时的core分配类型。 |
kernel type数值 |
对应的kernel type |
说明 |
---|---|---|
1 |
K_TYPE_AICORE |
该参数为预留参数,当前版本暂不支持。 算子执行时仅会启动AI Core,比如用户在host侧设置blockdim为5,则会启动5个AI Core。 |
2 |
K_TYPE_AIC |
算子执行时仅启动AI Core上的Cube核:比如用户在host侧设置blockdim为10,则会启动10个Cube核。 |
3 |
K_TYPE_AIV |
算子执行时仅启动AI Core上的Vecor核:比如用户在host侧设置blockdim为10,则会启动10个Vecor核。 |
4 |
K_TYPE_MIX_AIC_MAIN |
AIC、AIV混合场景下,设置核函数的类型为MIX ,算子执行时会同时启动AI Core上的Cube核和Vector核,比如用户在host侧设置blockdim为10,且设置task_ration为1:2,则会启动10个Cube核和20个Vector核。 |
5 |
K_TYPE_MIX_AIV_MAIN |
AIC、AIV混合场景下,使用了多核控制相关指令时,设置核函数的类型为MIX,算子执行时会同时启动AI Core上的Cube核和Vector核,比如用户在host侧设置blockdim为10,且设置task_ration为1:2,则会启动10个Vector核和20个Cube核。 |
6 |
K_TYPE_AIC_ROLLBACK |
算子执行时会同时启动AI Core和Vector Core, 此时AI Core会当成Cube Core使用。 |
7 |
K_TYPE_AIV_ROLLBACK |
算子执行时会同时启动AI Core和Vector Core, 此时AI Core会当成Vector Core使用。 |
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | { "binFileName": "AcosCustom_da824ede53d7e754f85c14b9446ec2fc", "binFileSuffix": ".o", "blockDim": -1, "coreType": "MIX", "intercoreSync": 1, "kernelName": "AcosCustom_da824ede53d7e754f85c14b9446ec2fc", "magic": "RT_DEV_BINARY_MAGIC_ELF", "memoryStamping": [], "opParaSize": 24, "parameters": [], "sha256": "94e32d04fcaf435411af194c8b4c85447744879aacec198448b820246f96d310", "workspace": { "num": 1, "size": [ -1 ], "type": [ 0 ] }, "kernelList": [ { "tilingKey": 1, "kernelType": "MIX_AIC", "taskRation": "0:1", "crossCoreSync": 0, "kernelName": "AcosCustom_da824ede53d7e754f85c14b9446ec2fc_1" }, .............. ], "taskRation": "tilingKey", "optionalInputMode": "gen_placeholder", "debugOptions": "printf", "debugBufSize": 78643200, "compileInfo": {}, "supportInfo": { // 算子原型信息 "implMode": "high_performance", "int64Mode": false, "simplifiedKeyMode": 0, "simplifiedKey": [...], "staticKey": "96b2b4bb2e35fa3db8c2714828d6e4f367b0731c9514401e1a2d41ebd63833c7,ee37ce8796ef139ded8f105c019b2819f38447bdeeb8ff7f58430228e6d9a361", "inputs": [ { "name": "x", "index": 0, "dtype": "float32", "format": "ND", "paramType": "required", "shape": [ -2 ], "format_match_mode": "FormatAgnostic" } ], .......... } |
1 | msobjdump --list-elf ${cmake_install_dir}/op_api/lib/libcust_opapi.so |
执行命令后,终端会打印所有文件,屏显样例如下:
1 2 3 4 5 | ELF file 0: ascendxxx_acos_custom_AcosCustom_dad9c8ca8fcbfd789010c8b1c0da8e26.json ELF file 1: ascendxxx_acos_custom_AcosCustom_dad9c8ca8fcbfd789010c8b1c0da8e26.o .................... ELF file 2: ascendxxx_acos_custom_AcosCustom_da824ede53d7e754f85c14b9446ec2fc.json ELF file 3: ascendxxx_acos_custom_AcosCustom_da824ede53d7e754f85c14b9446ec2fc.o |