快速上手
本节介绍AscendNPU IR使用的环境配置与简单用例,方便用户快速验证环境信息,熟悉AscendNPU IR的使用。
AscendNPU IR安装和环境配置
AscendNPU IR编译示例
本示例简单演示如何将AscendNPU IR编译至可以在昇腾AI处理器上执行的二进制文件。
- 新建样例文件demo.mlir,写入以下内容。
func.func @test_basic_kernel0(%valueA: memref<16xf16, #hivm.address_space<gm>>, %valueB: memref<16xf16, #hivm.address_space<gm>>, %valueC: memref<16xf16, #hivm.address_space<gm>>) attributes {hacc.entry} { %ubA = memref.alloc() : memref<16xf16, #hivm.address_space<ub>> hivm.hir.load ins(%valueA : memref<16xf16, #hivm.address_space<gm>>) outs(%ubA : memref<16xf16, #hivm.address_space<ub>>) %ubB = memref.alloc() : memref<16xf16, #hivm.address_space<ub>> hivm.hir.load ins(%valueB : memref<16xf16, #hivm.address_space<gm>>) outs(%ubB : memref<16xf16, #hivm.address_space<ub>>) %ubC = memref.alloc() : memref<16xf16, #hivm.address_space<ub>> hivm.hir.vadd ins(%ubA, %ubB: memref<16xf16, #hivm.address_space<ub>>, memref<16xf16, #hivm.address_space<ub>>) outs(%ubC: memref<16xf16, #hivm.address_space<ub>>) hivm.hir.store ins(%ubC : memref<16xf16, #hivm.address_space<ub>>) outs(%valueC : memref<16xf16, #hivm.address_space<gm>>) return }
- 在样例文件所在路径下,执行编译命令对IR执行编译。
1
bishengir-compile demo.mlir -o test
编译成功后,会生成可执行文件test.o。