昇腾社区首页
中文
注册

运行样例

参考毕昇编译器安装和环境配置完成安装与环境变量配置。

编译

编译时,须指定CANN包安装路径下对应的include目录,对于编译Vec代码,需要指定aicore类型为:dav-c220-vec 。

执行如下命令编译生成可执行文件:

bisheng -O2 --cce-aicore-arch=dav-c220-vec -I  ${install_path}/latest/runtime/include -I  ${install_path}/latest/include -L  ${install_path}/latest/lib64/ -lascendcl -lruntime main.cce kernel_aiv.cce -o test

执行用例

  1. 增加可执行文件的权限。
    chmod +x test
  2. 配置动态链接库的LD_LIBRARY_PATH,需配置为runtime so的路径,如果用户自行编译了动态链接库,同时需要配置该动态库的路径。
    $export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$runtime_so_path:$libabcdso_path
  3. 运行可执行文件。
    ./test
  4. 查看结果,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
    28
    29
    30
    31
    i0       Expect: 3.000000                               Result: 3.000000
    i1       Expect: 3.000000                               Result: 3.000000
    i2       Expect: 3.000000                               Result: 3.000000
    i3       Expect: 3.000000                               Result: 3.000000
    i4       Expect: 3.000000                               Result: 3.000000
    i5       Expect: 3.000000                               Result: 3.000000
    i6       Expect: 3.000000                               Result: 3.000000
    i7       Expect: 3.000000                               Result: 3.000000
    i8       Expect: 3.000000                               Result: 3.000000
    i9       Expect: 3.000000                               Result: 3.000000
    i10      Expect: 3.000000                               Result: 3.000000
    i11      Expect: 3.000000                               Result: 3.000000
    i12      Expect: 3.000000                               Result: 3.000000
    i13      Expect: 3.000000                               Result: 3.000000
    i14      Expect: 3.000000                               Result: 3.000000
    i15      Expect: 3.000000                               Result: 3.000000
    i16      Expect: 3.000000                               Result: 3.000000
    ...
    i51      Expect: 3.000000                               Result: 3.000000
    i52      Expect: 3.000000                               Result: 3.000000
    i53      Expect: 3.000000                               Result: 3.000000
    i54      Expect: 3.000000                               Result: 3.000000
    i55      Expect: 3.000000                               Result: 3.000000
    i56      Expect: 3.000000                               Result: 3.000000
    i57      Expect: 3.000000                               Result: 3.000000
    i58      Expect: 3.000000                               Result: 3.000000
    i59      Expect: 3.000000                               Result: 3.000000
    i60      Expect: 3.000000                               Result: 3.000000
    i61      Expect: 3.000000                               Result: 3.000000
    i62      Expect: 3.000000                               Result: 3.000000
    i63      Expect: 3.000000                               Result: 3.000000