Updated on 2022-03-13 GMT+08:00

Compiling an Operator

Compile the operator code to generate the operator binary file and operator description file as follows:

  1. Obtain the DDK version number, which is required for compiling the operator.

    Check the DDK version number in $HOME/tools/che/ddk/ddk/ddk_info.

    As shown in Figure 1, the VERSION field indicates the current DDK version.

    Figure 1 Checking the DDK version number

  2. Set the version number and compile the operator.

    1. Run the following command in the customop_te/operator directory to enter the python interaction mode:

      python

    2. In python interaction mode, run the following commands in sequence to set the DDK version number:

      from topi.cce import te_set_version

      import subprocess

      te_set_version("1.3.T18.B850")

      Figure 2 shows an example.

      Figure 2 Example of setting the DDK version number
    3. Run the following commands to compile the reduction.py file to generate the binary file and description file of the operator:

      subprocess.call("python reduction.py",shell=True)

      Figure 3 Compiling operator files
    4. Exit the python interaction mode.

      quit(0)

  3. After the operator compilation is completed, the kernel_meta folder is generated in the current operator directory. This folder contains the operator binary file *.o (with operators to run on AI Core) or *.so (with operators to run on AI CPU) and operator description file *.json.

    • The *.o or *.so file is the binary file of the operator.
    • The .json file is the operator description file, which is used to define operator properties and resources required for running.

      The .json file is parsed as follows:

      {
      "binFileName":"Reduction",            // Binary file name of the generated operator
      "binFileSuffix":".o",             // Extension of the generated operator binary file. For the operators to be running on AI CPU, the generated binary file name is suffixed by .so.
      "blockDim":1,                         // Number of AI Cores used for calculation
      "kernelName":"Reduction__kernel0",    // Name of the kernel function of the operator
      "magic":"RT_DEV_BINARY_MAGIC_ELF",    // The operation target is AI Core. If the value of magic is RT_DEV_BINARY_MAGIC_ELF_AICPU, the operation target is AI CPU.
      "sha256":"d5158df2ff2e64743eec7f527ddd9078b99c1d670f5adbd8b789224657ab0f91"  // Value obtained after the .o file is encrypted
      }