Verifying the Execution of the Add Operator
Execution on Ascend EP Host
Verify the execution of a single-operator in the standard form as follows:
- Log in to the development environment as the HwHiAiUser user (running user) and go to the acllib/sample/acl_execute_op/acl_execute_add directory.
- Generate the single-operator offline model file of the Add operator.
- Set the environment variables.The following is an example of setting environment variables. For details about the environment variables, see "Conversion Example" in ATC Tool Instructions.
export install_path=/home/HwHiAiUser/Ascend/ascend-toolkit/latest export PATH=${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH export PYTHONPATH=${install_path}/atc/python/site-packages:${install_path}/atc/python/site-packages/auto_tune.egg/auto_tune:${install_path}/atc/python/site-packages/schedule_search.egg:$PYTHONPATH export LD_LIBRARY_PATH=${install_path}/atc/lib64:$LD_LIBRARY_PATH export ASCEND_OPP_PATH=${install_path}/opp
install_path: installation path of the ATC and OPP components.
- Go to the acl_execute_add/run/out directory of the sample project and run the following command in the out directory to generate a single-operator model file:
atc --singleop=test_data/config/add_op.json --soc_version={soc_version} --output=op_models
Specifically,
- singleop: indicates the operator description file (.json).
- soc_version: version of the Ascend AI Processor. Replace it with the actual version.
You can view the supported Ascend AI Processor version in the atc/data/platform_config in the ATC installation directory. The name of the .ini file is value of soc_version.
- --output=op_models: indicates that the generated model file is stored in the op_models folder in the current directory.
After the model conversion is successful, the following files are generated:- The single-operator model file 0_Add_3_2_8_16_3_2_8_16_3_2_8_16.om is generated in the op_models directory of the current directory. The file is named in the format of No.+opType+input description (dateType_format_shape)+output description.
For details about the mapping between data types, formats, and shapes, see aclDataType and aclFormat in "AscendCL API Reference" in Application Software Development Guide.
Note: During model conversion, operators in the custom operator library are preferentially searched to match the operators in the model file.
- Set the environment variables.
- Generate test data.
Go to the run/out/test_data/data directory of the sample project and run the following command:
python3.7.5 generate_data.py
Two data files input_0.bin and input_1.bin with shape (8, 16) and data type of int32 are generated in the current directory for verifying the Add operator.
- Build the sample project to generate an executable file for single-operator verification.
- Configure the paths of the header files and library files on which build depends.
In the src/CMakeLists.txt build script, set the path of the header files to /usr/local/Ascend/acllib/include/ and set the path of the library files to /usr/local/Ascend/acllib/lib64/stub/.
- If the environment variables ${DDK_PATH} and ${NPU_HOST_LIB} are not set, the paths predefined in the CMakeLists.txt build script are used.
- If the environment variables ${DDK_PATH} and ${NPU_HOST_LIB} are set, the CMakeLists.txt build script looks up for the header files and library files in the specified paths, respectively.
The following is an example of setting environment variables. Replace /home/HwHiAiUser/Ascend/ascend-toolkit/latest with the actual installation path of the standard-form ACLlib.
export DDK_PATH=/home/HwHiAiUser/Ascend/ascend-toolkit/latest export NPU_HOST_LIB=/home/HwHiAiUser/Ascend/ascend-toolkit/latest/acllib/lib64/stub
- Go to the acl_execute_add directory of the sample project and run the following command in this directory to create a directory for storing the generated executable file, for example, build/intermediates/host.
mkdir -p build/intermediates/host
- Go to the build/intermediates/host directory and run the cmake command.
cd build/intermediates/host
cmake ../../../src -DCMAKE_CXX_COMPILER=g++ -DCMAKE_SKIP_RPATH=TRUE
- Replace ../../../src with the actual directory of CMakeLists.txt.
- DCMAKE_CXX_COMPILER: indicates the compiler used to build the app.
- DCMAKE_SKIP_RPATH: If set to TRUE, this parameter indicates that rpath (path specified by NPU_HOST_LIB, that is, xxx/acllib/lib64/stub) is not added to the executable file generated after build.
The executable automatically looks up for dynamic libraries in the path (xxx/acllib/lib64) included in LD_LIBRARY_PATH.
The .so library files in the /home/HwHiAiUser/Ascend/ascend-toolkit/latest/acllib/lib64/stub directory are required to build the code logic based on the AscendCL APIs, without depending on any .so library files of other components (such as Driver).
After successful build, when you run an app on the host, the app can be linked to the .so library files in the /home/HwHiAiUser/Ascend/ascend-toolkit/latest/acllib/lib64 directory on the host by configuring corresponding environmental variables. The app is automatically linked to the dependent .so library files of other components during runtime.
- Run the following command to generate an executable file:
make
The executable file execute_add_op is generated in the run/out directory of the project.
- Configure the paths of the header files and library files on which build depends.
- Execute the single-operator verification file on the host side of the hardware device.
- As the HwHiAiUser user (running user), copy the out folder in the acl_execute_add/run/ directory of the sample project in the development environment to any directory in the operating environment (host), for example, /home/HwHiAiUser/HIAI_PROJECTS/run_add/.
- Set the environment variables.Run the export command to declare environment variables on the current terminal. The environment variables become invalid when the shell terminal is closed.
export LD_LIBRARY_PATH=/home/HwHiAiUser/Ascend/ascend-toolkit/latest/acllib/lib64
/home/HwHiAiUser/Ascend/ascend-toolkit/latest is the installation path of the standard-form ACLlib installation package. Replace it with the actual path.
- Execute the execute_add_op file in the operating environment to verify the single-operator model file.
Run the following command in /home/HwHiAiUser/HIAI_PROJECTS/run_add/out:
chmod +x execute_add_op
./execute_add_op
The following information is displayed. (Note: The data file is randomly generated by the data generation script, so the displayed data may be different.)[INFO] Input[0]: -4 -4 -1 7 0 9 -4 5 -9 -9 -3 7 -6 1 8 3 -6 -9 8 -3 -9 0 0 4 -3 7 -6 -9 6 6 1 -8 -7 7 -3 5 8 -3 6 -4 6 9 8 -10 7 3 3 9 -4 6 5 6 -5 3 -1 1 1 -8 -4 9 -6 -9 6 -8 5 8 5 2 -9 5 -8 -2 -1 -10 -5 5 7 -10 -8 -10 0 3 -7 8 3 3 -10 5 -7 6 -3 2 7 -10 -8 0 -2 -5 8 -4 1 8 4 -5 -7 1 -9 8 2 3 -3 5 8 -6 -8 -5 8 -10 5 -4 -5 -1 0 -10 8 6 -6 -3 [INFO] Set input[1] from test_data/data/input_1.bin success. [INFO] Input[1]: -8 -1 -3 9 -2 8 -9 7 -7 7 -5 4 9 6 -2 9 -6 1 -3 9 -5 5 4 -4 -8 -7 -1 9 6 0 9 -10 -6 6 -1 -2 -3 5 1 3 -4 0 6 4 -4 -10 -2 7 9 2 2 6 -7 -8 9 6 -2 -5 -8 5 9 -5 1 7 -9 -3 -9 -4 6 0 5 -4 -4 1 -1 2 1 7 8 -10 1 3 -5 -8 -10 -3 -7 7 8 -3 -9 5 -7 -6 -6 -4 -3 3 4 -5 5 4 -9 0 -8 2 -3 -6 5 4 -6 -8 0 8 9 -2 4 1 8 -6 -8 1 -1 -9 -2 0 -10 7 ...... ...... [INFO] Output[0]: -12 -5 -4 16 -2 17 -13 12 -16 -2 -8 11 3 7 6 12 -12 -8 5 6 -14 5 4 0 -11 0 -7 0 12 6 10 -18 -13 13 -4 3 5 2 7 -1 2 9 14 -6 3 -7 1 16 5 8 7 12 -12 -5 8 7 -1 -13 -12 14 3 -14 7 -1 -4 5 -4 -2 -3 5 -3 -6 -5 -9 -6 7 8 -3 0 -20 1 6 -12 0 -7 0 -17 12 1 3 -12 7 0 -16 -14 -4 -5 -2 12 -9 6 12 -5 -5 -15 3 -12 2 7 7 -9 -3 8 2 1 -7 12 -9 13 -10 -13 0 -1 -19 6 6 -16 4 [INFO] Write output[0] success. output file = result_files/output_0.bin [INFO] Run op success
The output result is the sum of input data 1 and input data 2. The verification result of the Add operator is correct.
result_files/output_0.bin: output data binary file
Execution on Ascend RC
Verify the execution of a single-operator as follows:
- Log in to the development environment as the HwHiAiUser user (running user) and go to the acllib/sample/acl_execute_op/acl_execute_add directory.
- Generate the single-operator offline model file of the Add operator.
- Set the environment variables.The following is an example of setting environment variables. For details about the environment variables, see "Conversion Example" in ATC Tool Instructions.
export install_path=/home/HwHiAiUser/Ascend/ascend-toolkit/latest export PATH=${install_path}/atc/ccec_compiler/bin:${install_path}/atc/bin:$PATH export PYTHONPATH=${install_path}/atc/python/site-packages:${install_path}/atc/python/site-packages/auto_tune.egg/auto_tune:${install_path}/atc/python/site-packages/schedule_search.egg:$PYTHONPATH export LD_LIBRARY_PATH=${install_path}/atc/lib64:$LD_LIBRARY_PATH export ASCEND_OPP_PATH=${install_path}/opp
install_path: installation path of the ATC and OPP components.
- Go to the acl_execute_add/run/out directory of the sample project and run the following command in the out directory to generate a single-operator model file:
atc --singleop=test_data/config/add_op.json --soc_version={soc_version} --output=op_models
Specifically,
- singleop: indicates the operator description file (.json).
- soc_version: version of the Ascend AI Processor. Replace it with the actual version.
You can view the supported Ascend AI Processor version in the atc/data/platform_config in the ATC installation directory. The name of the .ini file is value of soc_version.
- --output=op_models: indicates that the generated model file is stored in the op_models folder in the current directory.
After the model conversion is successful, the following files are generated:- The single-operator model file 0_Add_3_2_8_16_3_2_8_16_3_2_8_16.om is generated in the op_models directory of the current directory. The file is named in the format of No.+opType+input description (dateType_format_shape)+output description.
For details about the mapping between data types, formats, and shapes, see aclDataType and aclFormat in "AscendCL API Reference" in Application Software Development Guide.
Note: During model conversion, operators in the custom operator library are preferentially searched to match the operators in the model file.
- Set the environment variables.
- Generate test data.
Go to the run/out/test_data/data directory of the sample project and run the following command:
python3.7.5 generate_data.py
Two data files input_0.bin and input_1.bin with shape (8, 16) and data type of int32 are generated in the current directory for verifying the Add operator.
- Build the sample project to generate an executable file for single-operator verification.
- Configure the paths of the header files and library files on which build depends.
In the CMakeLists.txt build script, set the path of the header files to /usr/local/Ascend/acllib/include/ and set the path of the library files to /usr/local/Ascend/acllib/lib64/stub/.
- If the environment variables ${DDK_PATH} and ${NPU_HOST_LIB} are not set, the paths predefined in the CMakeLists.txt build script are used.
- If the environment variables ${DDK_PATH} and ${NPU_HOST_LIB} are set, the CMakeLists.txt build script looks up for the header files and library files in the specified paths, respectively.
The following is an example of setting environment variables. Replace /home/HwHiAiUser/Ascend/ascend-toolkit/latest with the actual installation path of the Ascend RC ACLlib.
export DDK_PATH=/home/HwHiAiUser/Ascend/ascend-toolkit/latest export NPU_HOST_LIB=/home/HwHiAiUser/Ascend/ascend-toolkit/latest/acllib/lib64/stub
- Go to the acl_execute_add directory of the sample project and run the following command in this directory to create a directory for storing the generated executable file, for example, build/intermediates/host.
mkdir -p build/intermediates/host
- Go to the build/intermediates/host directory and run the cmake command.
cd build/intermediates/host
cmake ../../../src -DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++ -DCMAKE_SKIP_RPATH=TRUE
- Replace ../../../src with the actual directory of CMakeLists.txt.
- DCMAKE_CXX_COMPILER: indicates the compiler used to build the app.
- DCMAKE_SKIP_RPATH: If set to TRUE, this parameter indicates that rpath (path specified by NPU_HOST_LIB, that is, xxx/acllib/lib64/stub) is not added to the executable file generated after build.
The executable automatically looks up for dynamic libraries in the path (xxx/acllib/lib64) included in LD_LIBRARY_PATH.
The .so library files in the /home/HwHiAiUser/Ascend/ascend-toolkit/latest/acllib/lib64/stub directory are required to build the code logic based on the AscendCL APIs, without depending on any .so library files of other components (such as Driver).
After successful build, when you run an app on the Atlas 200 DK, the app can be linked to the .so library files in the /home/HwHiAiUser/Ascend/ascend-toolkit/latest/acllib/lib64 directory on the Atlas 200 DK. The app is automatically linked to the dependent .so library files of other components during runtime.
- Run the following command to generate an executable file:
make
The executable file execute_add_op is generated in the run/out directory of the project.
- Configure the paths of the header files and library files on which build depends.
- Execute the single-operator verification file on the operating environment.
- As the HwHiAiUser user (running user), copy the out folder in the acl_execute_add/run/ directory of the sample project in the development environment to any directory on the board environment, for example, /home/HwHiAiUser/HIAI_PROJECTS/run_add/.
- Execute the execute_add_op file in the board environment to verify the single-operator model file.
Run the following command in /home/HwHiAiUser/HIAI_PROJECTS/run_add/out:
chmod +x execute_add_op
./execute_add_op
The following information is displayed. (Note: The data file is randomly generated by the data generation script, so the displayed data may be different.)[INFO] Input[0]: -4 -4 -1 7 0 9 -4 5 -9 -9 -3 7 -6 1 8 3 -6 -9 8 -3 -9 0 0 4 -3 7 -6 -9 6 6 1 -8 -7 7 -3 5 8 -3 6 -4 6 9 8 -10 7 3 3 9 -4 6 5 6 -5 3 -1 1 1 -8 -4 9 -6 -9 6 -8 5 8 5 2 -9 5 -8 -2 -1 -10 -5 5 7 -10 -8 -10 0 3 -7 8 3 3 -10 5 -7 6 -3 2 7 -10 -8 0 -2 -5 8 -4 1 8 4 -5 -7 1 -9 8 2 3 -3 5 8 -6 -8 -5 8 -10 5 -4 -5 -1 0 -10 8 6 -6 -3 [INFO] Set input[1] from test_data/data/input_1.bin success. [INFO] Input[1]: -8 -1 -3 9 -2 8 -9 7 -7 7 -5 4 9 6 -2 9 -6 1 -3 9 -5 5 4 -4 -8 -7 -1 9 6 0 9 -10 -6 6 -1 -2 -3 5 1 3 -4 0 6 4 -4 -10 -2 7 9 2 2 6 -7 -8 9 6 -2 -5 -8 5 9 -5 1 7 -9 -3 -9 -4 6 0 5 -4 -4 1 -1 2 1 7 8 -10 1 3 -5 -8 -10 -3 -7 7 8 -3 -9 5 -7 -6 -6 -4 -3 3 4 -5 5 4 -9 0 -8 2 -3 -6 5 4 -6 -8 0 8 9 -2 4 1 8 -6 -8 1 -1 -9 -2 0 -10 7 ...... ...... [INFO] Output[0]: -12 -5 -4 16 -2 17 -13 12 -16 -2 -8 11 3 7 6 12 -12 -8 5 6 -14 5 4 0 -11 0 -7 0 12 6 10 -18 -13 13 -4 3 5 2 7 -1 2 9 14 -6 3 -7 1 16 5 8 7 12 -12 -5 8 7 -1 -13 -12 14 3 -14 7 -1 -4 5 -4 -2 -3 5 -3 -6 -5 -9 -6 7 8 -3 0 -20 1 6 -12 0 -7 0 -17 12 1 3 -12 7 0 -16 -14 -4 -5 -2 12 -9 6 12 -5 -5 -15 3 -12 2 7 7 -9 -3 8 2 1 -7 12 -9 13 -10 -13 0 -1 -19 6 6 -16 4 [INFO] Write output[0] success. output file = result_files/output_0.bin [INFO] Run op success
The output result is the sum of input data 1 and input data 2. The verification result of the Add operator is correct.
result_files/output_0.bin is the binary file of the output data.