运行样例
参考毕昇编译器安装和环境配置完成安装与环境变量配置。
编译
Cube和Vector代码需要写在同一个kernel函数中,编译器针对此aicore代码进行两次device代码编译,第一次进行Cube代码编译,第二次进行Vector代码编译,并最终将Cube和Vector代码链接在一起打包成可执行device代码。Runtime提供特别版本的<<<>>>调用支持,使得能够通过FFTS加载Cube/Vector mixkernel任务。
编译时,须指定CANN包安装路径下对应的include目录,编译混合代码,需要指定aicore类型为:dav-c220。使用如下命令编译生成.o可执行文件
执行如下命令编译生成.o可执行文件:
bisheng -O2 --cce-aicore-arch=dav-c220 -I ${install_path}/latest/runtime/include -I ${install_path}/latest/include -I ${install_path}/latest/include/experiment/runtime/ -I ${install_path}/latest/include/experiment/msprof/ -L $ ${install_path}/latest/lib64/ -lascendcl -lruntime main.cce mixkernel.cce -o test
执行用例
- 增加可执行文件的权限。
chmod +x test
- 配置动态链接库的LD_LIBRARY_PATH,需配置为runtime so的路径,如果用户自行编译了动态链接库,同时需要配置该动态库的路径。
$export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$runtime_so_path:$libabcdso_path
- 运行可执行文件。
./test
- 查看结果,Expect为Host侧代码中算子逻辑在CPU上的运行结果,Result为Device侧中调用Kernel函数在昇腾AI处理器上的运行结果。
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
i0 Expect: 342.676788 Result: 342.676788 i1 Expect: 342.676788 Result: 342.676788 i2 Expect: 342.676788 Result: 342.676788 i3 Expect: 342.676788 Result: 342.676788 ... i32 Expect: 0.000000 Result: 0.000000 i33 Expect: 0.000000 Result: 0.000000 i34 Expect: 0.000000 Result: 0.000000 i35 Expect: 0.000000 Result: 0.000000 i36 Expect: 0.000000 Result: 0.000000 i37 Expect: 0.000000 Result: 0.000000 i38 Expect: 0.000000 Result: 0.000000 ... i985 Expect: 0.000000 Result: 0.000000 i986 Expect: 0.000000 Result: 0.000000 i987 Expect: 0.000000 Result: 0.000000 i988 Expect: 0.000000 Result: 0.000000 i989 Expect: 0.000000 Result: 0.000000 i990 Expect: 0.000000 Result: 0.000000 i991 Expect: 0.000000 Result: 0.000000 i992 Expect: 335.964020 Result: 335.964020 i993 Expect: 335.964020 Result: 335.964020 i994 Expect: 335.964020 Result: 335.964020 i995 Expect: 335.964020 Result: 335.964020 i996 Expect: 335.964020 Result: 335.964020 i997 Expect: 335.964020 Result: 335.964020 ...
父主题: MIX算子示例