Running a Single Operator
- Generate a single-operator compilation binary file in the DDK sample project customop_runner.
- Assign the write permission to the customop_runner sample project.
chmod -R +w $HOME/tools/che/ddk/ddk/sample/customop/customop_runner/
- Go to the build directory of the DDK sample project customop_runner.
cd $HOME/tools/che/ddk/ddk/sample/customop/customop_runner/build
- Set the environment variable of DDK_PATH.
export DDK_PATH=$HOME/tools/che/ddk/ddk
- Generate the Makefile file.
- For the Atlas 200 DK developer board, run the following command:
cmake -Dtarget=OI .
- In the ASIC environment, run the following command:
cmake .
- For the Atlas 200 DK developer board, run the following command:
- Run the make command to generate a binary file.
make
The executable file main and dynamic library libcustom_engine.so are generated in $HOME/tools/che/ddk/ddk/sample/customop/customop_runner/out/.
- Assign the write permission to the customop_runner sample project.
- Copy the out directory to the directory of the custom TE operator project.
cp -rf $HOME/tools/che/ddk/ddk/sample/customop/customop_runner/out $HOME/tools/projects/customop_te/
- Configure the input data, output data, and verification description file.
Go to the out folder in the directory of the custom TE operator project.
cd $HOME/tools/projects/customop_te/out- In the input.txt file, configure the path and name of the input data file.
For example:
dataPath=../operator/Reduction_input_2_3_4_sum_axis_1.data
If the custom operator has multiple inputs, you need to define multiple .txt files according to input.txt, for example, input1.txt, input2.txt, and more.
- Configure the output data in the output.txt file.
For example:
size=4 dataPath=./output/out0.data dtype=1
- size: expected size of the output data file, in bytes
- dataPath: path and name of the output data file
- dtype: output data type. The value 1 indicates float16, and the value 2 indicates float32.
- In the expect.txt file, configure the path and file name of the data to be generated.
For example:
dataPath=../operator/Reduction_output_2_3_4_sum_axis_1.data
- In the input.txt file, configure the path and name of the input data file.
- Copy the operator and out folders to the host of the developer board or ASIC device as the HwHiAiUser user. The operator and out folders must be placed in the same directory.
For example, copy operator and out folders to the /home/HwHiAiUser/projects directory.
- Run the operator.
Log in to the host of the developer board or ASIC device as the HwHiAiUser user and go to the out directory, for example, /home/HwHiAiUser/projects/out.
- Create the output folder in the current directory to store the generated data file. The file path and name are defined in the output.txt file.
mkdir output
- Run the following command to assign the execution permission to the main file:
chmod +x main
- Run the following command to run a single operator and compare the operators:
./main -i input.txt -o output.txt -e expect.txt -b ../operator/kernel_meta/Reduction.o -p 0.2 -d 0.2 -k Reduction__kernel0 -t 0
In the preceding command:
- -i: input data configuration file, which specifies the path and file name of the input data
If the custom operator has multiple inputs, you need to define multiple .txt files according to input.txt, for example, input1.txt, input2.txt, and more.
- -o: output data configuration file, which specifies the size, path, file name, and type of the output data
- -e: expected data configuration file, which specifies the path and file name of the expected output data for result comparison
- -b: operator binary file *.o (operator to be running on AI Core) or *.so (operator to be running on AI CPU)
- -p: allowed precision deviation. The value range is [0, 1). A smaller value indicates higher precision.
- -d: statistical discrepancy, that is, the percentage of the data whose precision deviation is above the threshold. The value range is (0, 1). A smaller value indicates higher precision.
- -k: kernel name. The first letter must be in uppercase. The kernel name of the TE operator must be the same as kernelName in the.json file. The kernel name of the C++ operator must be the same as the object name opetype registered in Framework for the operator.
- -t: The value can be 0 (TE_AI Core operator), 1 (TE_AI CPU operator), or 2 (custom C++ operator or AI CPU operator).
You can check whether the TE operator is running on AI Core or AI CPU based on the value of magic in the **.json file generated after the operator is compiled.
After the command is executed successfully, the out0.data result file and the vertifyResult.txt verification data comparison result file are generated in the output folder of the current directory.
The following is an example of the vertifyResult.txt file, indicating that the actual output data is consistent with the expected output data.
Output file ./output/out0.data compare result true
- -i: input data configuration file, which specifies the path and file name of the input data
- Create the output folder in the current directory to store the generated data file. The file path and name are defined in the output.txt file.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot