Theoretical performance is the ideal objective of actual operator performance. Hardware specifications vary with hardware platforms. The theoretical performance helps you understand the potential of hardware and set performance optimization objectives.
After obtaining profile data, time-consuming process points where deviation from the theoretical value is large are considered as "bottlenecks". The following describes how to find bottlenecks and optimization directions based on profile data.
View the op_summary_*.csv file parsed by on-board profiling. Note: The asterisk (*) indicates the timestamp.
In SIMD and SIMT hybrid programming scenarios, due to the inherent characteristics of the hardware architecture, all computing tasks are scheduled and executed based on the Vector Function (VF). Therefore, in the profiling data, the overall VF execution time of both SIMT and SIMD is recorded as aiv_vec_time. In particular, the time spent on reading and writing the Global Memory during the execution of the SIMT VF is also included in aic_vec_time.
The ideal utilization of each pipeline should be 100%. Less than 100% means there may be room for improvement. The preceding figure shows the data obtained from an AI Processor. For the Cube operator MatMulV2, the Cube pipeline utilization aic_mac_ratio is about 80%, implying that the computing power is not fully utilized. aic_mte2_ratio of MTE2 is about 95%. Therefore, MTE2 is the longest pipeline.
Compare the longest pipeline with the theoretical difference. The shapes of the input left and right matrices are (2048, 12288) and (12288, 6144) respectively, in bfloat16. The shape of the bias input is 6144 in float. Therefore, the total amount of data to be transferred can be computed. According to Theoretical Parameters, the theoretical time for the data transfer is as follows: (sizeof(bfloat16) x (2048 x 12288 + 12288 x 6144) + sizeof(float) x 6144)/1.8 TB/s ≈ 111.8 µs, where 1 TB = 1012 bytes. The theoretical value is greatly different from the actual profile data aic_mte2_time. The analysis finds that the total size of the input data exceeds the L1 space size (512 KB). During the MatMul compute, the input matrix data may be repeatedly transferred. To check whether the number of repeated transfers is reasonable, pipeline optimization and tiling optimization are required. For details, see Method 3: Analyze the simulation pipeline chart.
In the preceding figure, the shape of the operator input is (8192, 8192), in float. Therefore, the total amount of data to be transferred can be computed. According to Theoretical Parameters, the theoretical time required for the data transfer is as follows: sizeof(float) x (8192 x 8192)/0.8 TB/s ≈ 335.5 µs, where 1 TB =1012 bytes and the theoretical bandwidth varies depending on the AI Processor. The theoretical value is consistent with the actual profile data aiv_mte2_time, so it can be determined that the data transfer of the operator almost reaches the MTE2 bound. In this example, the total execution duration is 350 μs, which is the same as the actual duration of MTE2, indicating that the operator has been properly tuned. In case that there is a large gap between the MTE2 duration and the total execution time, the next step is to implement pipeline optimization and tiling optimization, to hide other pipelines in the MTE2 pipeline. See Method 3: Analyze the simulation pipeline chart.
View the op_summary_*.csv file parsed by on-board profiling.
The preceding figure shows the data obtained from an AI Processor. According to the hardware platform, the AI Processor has 48 vector cores. The Mul operator is simply a vector operator. However, in some scenarios, not all vector cores are used (Block Dim < 48), causing computing power waste. In this case, the next direction is tiling optimization.
The preceding figure shows the data obtained from an AI Processor. It can be seen that the pipelines related to vector cores (such as MTE2 and MTE3 of vec0 as well as MTE2 and MTE3 of vec1) are regularly interrupted. Analyze the operator logic to check whether pipeline interruption is caused by factors such as data dependency. So the next direction is pipeline optimization as the primary method while tiling optimization and memory optimization as the secondary methods, to further improve vector pipeline utilization.
The header overhead is the latency generated before the operator performs compute, including the latency caused by core startup, core addressing TLB miss, access to the same address (additional latency caused by conflicts when multiple cores access the same memory address at the same time due to hardware restrictions), and variable resource initialization. Take
By analyzing the on-board profiling data (TaskDuration data when the kernel is empty), you can see the startup overhead of each core. Then, by using the appropriate number of cores and operator kernel types, you can continuously experiment to find the optimal configuration. For details about the optimization direction, see Header and Tailer Overhead Optimization.