This is a simple example that demonstrates:
- how to compile
.mlirinto binary that can be executed on the Ascend NPU usingbishengir-compile - how to write a host wrapper that can launch the program on Ascend NPU
To run the example on Ascend NPU, please install the CANN software package and the set the environment variable ASCEND_HOME_PATH to the installed path. For example:
export ASCEND_HOME_PATH=/usr/local/ascend-toolkit/latest-
Prepare the requirements listed above.
-
Add
-DBISHENGIR_BUILD_EXAMPLES=ONto the cmake build options. For example:cmake -G Ninja .. \ -DCMAKE_C_COMPILER=clang \ -DCMAKE_CXX_COMPILER=clang++ \ -DCMAKE_BUILD_TYPE=Release \ -DLLVM_ENABLE_PROJECTS="mlir" \ -DLLVM_EXTERNAL_PROJECTS="bishengir" \ -DLLVM_EXTERNAL_BISHENGIR_SOURCE_DIR="AscendNPU-IR" \ # Project root directory -DBSPUB_DAVINCI_BISHENGIR=ON # Mandatory! Enables AscendNPU IR extensions for third-party repositories [Other CMake Options as required] -DBISHENGIR_BUILD_EXAMPLES=ON # Build integration examples
-
Build the project. After building, the executable
hivm-vec-addshould appear in./bindirectory. -
Build the device binary using
bishengir-compilebishengir-compile add.mlir -enable-hivm-compile -o kernel.o
-
Execute
hivm-vec-add./hivm-vec-add
-
You should see the following results (some text are omitted):
i0 Expect: 1 Result: 1 i1 Expect: 2 Result: 2 i2 Expect: 3 Result: 3 i3 Expect: 4 Result: 4