Quick Start

This section briefly describes how to configure the environment and use AscendNPU IR, for you to quickly verify environment information and get familiar with the use of AscendNPU IR.

AscendNPU IR Installation and Environment Setup

  • AscendNPU IR is released with the CANN package. Install the CANN package as instructed in CANN Software Installation. The directory of the AscendNPU IR binary file is ${INSTALL_DIR}/tools/bishengir.

    Replace ${INSTALL_DIR} with the CANN component directory. For example, if the installation is performed by the root user, the default file storage path is /usr/local/Ascend/cann.

  • Before programming, configure the environment variables related to the binary program of AscendNPU IR.
    The CANN package provides a process-level environment variable setting script to automatically set the environment variable. The following is an example of the default installation paths of the root and non-root user. Replace it with the actual installation path.
    1
    2
    3
    4
    # Configure environment variables after installing the Toolkit package as the root user.
    source /usr/local/Ascend/cann/set_env.sh 
    # Configure environment variables after installing the Toolkit package as a non-root user.
    source ${HOME}/Ascend/cann/set_env.sh 
    

AscendNPU IR Compile Example

This example demonstrates how to compile AscendNPU IR into a binary file that can be executed on the AI processor.

  1. Create a sample file demo.mlir and write the following content to the file:
    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, hacc.function_kind = #hacc.function_kind<DEVICE>}
    {
      %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
    }
  2. In the path where the sample file is located, run the compile command to compile the IR.
    1
    bishengir-compile demo.mlir -o test
    

    After the compile is successful, the executable file test.o is generated.

Follow-up Procedure

AscendNPU IR enables high-performance operators built by Triton to run efficiently on the AI processor. For details about how to develop Triton operators, see Triton Ascend.