Quick Start

This section briefly describes how to configure the environment and use the AscendNPU IR, for you to quickly verify the environment and get familiar with the use of the 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 Guide. 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 Compilation Example

This example shows how to compile AscendNPU IR into a binary file that can be executed on the Ascend 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. Run the compile command in the directory where the sample file is stored to compile the IR.
    1
    bishengir-compile demo.mlir -o test
    

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

Follow-Up Procedure

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