Sample Reference
Description
This is an IR graph construction sample, which generates an offline model adapted to the Ascend AI Processor.
Sample Obtaining
Find the sample code in /atc/sample/IRBuild in the ATC installation path.
Directory Structure
├── main.cpp //IR graph construction implementation file ├── Makefile //Build script ├── data │ ├──data_generate.py //Data generation script, for generating data in .bin format
Weight Data Generation
- Run the data generation script in the data directory.
python3.7.5 data_generate.py
- Generate data in .bin format in the data directory. The weight and offset data will be read from this file during IR graph construction.
IR Build
- Run the Makefile.
- Modify the path of the installation package in Makefile.
- Run the make clean and make ir_build commands to build the graph.
- Find the generated executable file ir_build in the out directory.
IR Running
- Set environment variables.
export install_path=/home/HwHiAiUser/Ascend/ascend-toolkit/latest/xxx-linux_gccx.x.x export PATH=${install_path}/atc/ccec_compiler/bin:$PATH export PYTHONPATH=${install_path}/atc/python/site-packages/te:${install_path}/atc/python/site-packages/topi:$PYTHONPATH export LD_LIBRARY_PATH=${install_path}/atc/lib64:$LD_LIBRARY_PATH export ASCEND_OPP_PATH=${install_path}/opp
The preceding paths are used as an example for the following installation scenario. You can change the paths as required.
- The ATC component is installed as a non-root user (for example, HwHiAiUser). /home/HwHiAiUser/Ascend/ascend-toolkit/latest/xxx-linux_gccx.x.x is an example of the installation path, containing the atc directory.
- The OPP component is installed as a non-root user (for example, HwHiAiUser). /home/HwHiAiUser/Ascend/ascend-toolkit/latest/xxx-linux_gccx.x.x is an example of the installation path, containing the opp directory.
- Run the executable file.
cd out
./ir_build Ascend310
- View the execution result.The following information indicates a model build success.
========== Generate Graph1 Success! ========== Build Model1 SUCCESS! Save Offline Model1 SUCCESS!
Find the offline model ir_build_sample1.om in the out directory.
The kernel_meta folder is also generated in the out directory.