Overview
Before You Start
Use Cases
For a pure static shape network or a dynamic shape network with few shape changes, if you want to quickly improve the network execution performance, you can use the operator compiler op_compiler to compile and generate a static kernel package during network deployment to improve the operator call performance.
Tuning Principles
In static kernel compilation, the shape size of the operator is specified during compilation but not running. The operator compiler obtains shape information from the input operator information file and compiles an operator binary file for each shape to improve operator efficiency and performance.
The advantages of static kernel compilation are as follows:
- The sizes of all tensors are known before compilation, improving the memory utilization.
- During compilation, strategic optimization can be implemented based on the actual shape size.
- AI processors show better performance in parallel instruction execution than logic computation. Frequent scalar operations may interrupt parallel instruction execution, resulting in performance deterioration. Scalar computation can be completed during static compilation. This can improve the performance.
- The operation data size is fixed, and the compiler will not insert extra synchronization instructions. In this way, instructions can be executed in parallel mode, improving the execution performance.
Constraints
- Static-shape operator compilation
- Product models supported by the default compilation mode:
Atlas inference products Atlas training products Atlas A2 products
- The restrictions on the tuning mode are as follows:
- Product models supported by the default compilation mode:
Basic Workflow
Figure 1 shows the basic process of improving the operator execution performance in the network model by compiling the static kernel. The tuning procedure is as follows:
- Dump operator information.
Before operator tuning, obtain operator information in the network model.
- Method 1: If Python-based APIs are used for programming, dump the operator .json file using the Ascend PyTorch Profiler API.
- Method 2: If ACL APIs are used, dump the operator .json file using the aclopStartDumpArgs and aclopStopDumpArgs APIs.
- Compile the static kernel package.Use the operator compiler to compile the dumped operator information file (*.json) and generate a kernel package.
The operator compiler (op_compiler) is a command line tool provided by CANN for compiling operators and generating operator binary files. When the shape of an operator is fixed or slightly changed, you can use this tool to compile and install the static kernel package to improve the call performance of the operator. For details about the tool, see Operator Compiler.
- Install the static kernel package.
Upload the static kernel package to the server where the target network model runs and execute the .run package to complete the installation.
- Verify the model execution result.
After the static kernel package is installed, run the target model again. Compare the running performance of the entire network and the single-operator running time before and after the static kernel package is installed.
