# A Neural Network-Inspired Matrix Formulation of Chemical Kinetics for Acceleration on GPUs
## 3 GPU Performance Analysis
### Cost of Reaction Types  
The above sections described general speedup and performance trends for the GPU in light of the matrix-oriented methodology of Section 2.1. As per the classifications presented in Section 2.3, a more detailed investigation into the GPU cost of individual reaction types in the pre-saturated and saturated regimes can better illuminate both the sources of speedup behavior and the types of mechanisms that are more suited for GPU offloading. To better isolate the GPU effects of individual routines and reaction types, the quantity of interest here is defined as the cost per reaction. The cost per reaction is measured by taking the compute time of a specific kernel (or routine composed of a set of kernels) and normalizing by the size of the subset of total reactions on which the routine acts. For example, in the case of reversible reactions, the computation of equilibrium rate constants occur on the subset of total reactions of size \(N_{R,rev}\). To get a measure on the total time _per reaction_ taken during the computation of \(\log(\mathbf{K}_{c})\), the corresponding routine time is divided by \(N_{R,rev}\). This effectively provides an averaged measure on the cost impact for individual reaction types or routines encountered in a given mechanism. Figure 7 compares the cost per reaction for \(\log(\mathbf{K}_{f})\) and \(\log(\mathbf{K}_{c})\) routines for the three Mechanisms A2, B3, and C1. The \(\log(\mathbf{K}_{f})\) routine consists of the following: Arrhenius-based matrix multiplication (Equation (9), uses a DGEMM kernel), evaluation of third body concentrations if present (DGEMM kernel), falloff rate constant evaluations if applicable (custom kernels), and pressure-log rate constant evaluations if applicable (custom kernels). Figure 6: (**Left**) GPU-derived speedup in log-scale with respect to the Cantera-based CPU baseline for all mechanisms listed in Table 1. (**Right**) Same as left but with linear-scale in the \(y\)-axis. The \(\log(\mathbf{K}_{c})\) routine consists of the evaluation of Equation (9), which utilizes a first custom kernel to fill the Gibbs matrix and a second DGEMM kernel to recover the rate constants. In the pre-saturated regime, the cost per reaction of the \(\log(\mathbf{K}_{f})\) routine consistently outweighs that of \(\log(\mathbf{K}_{c})\). However, the behavior is different in the saturated regime as mechanism complexity grows. An interesting feature is the consistent spike in cost per reaction for \(\log(\mathbf{K}_{c})\) at the saturation points (see Figure 4) of the respective mechanisms. For the smaller mechanisms, this jump leads to a convergence in the difference between \(\log(\mathbf{K}_{f})\) and \(\log(\mathbf{K}_{c})\) costs in the saturated regime. For the large Mechanism C1, this jump at the commencement of saturation near \(N_{C}=10^{2}\) brings the \(\log(\mathbf{K}_{c})\) cost per reaction to a higher value than the \(\log(\mathbf{K}_{f})\) cost (though not shown here, this effect is exacerbated for mechanism C2). The implication is that more complex mechanisms (as determined by \(N_{S}\) and \(N_{R}\)) incur a higher penalty for \(\log(\mathbf{K}_{c})\) evaluations in the saturated regime. As such, in the case of very large mechanisms, a useful driver to design mechanisms that are more \"GPU-optimal\" in the saturated regime is to minimize the presence of reversible reactions, i.e., to steer the mechanism distribution towards something akin to that of C2 (see the top row of Figure 3). Analogous costs for the three individual reaction types described in Section 2.3--standard, pressure-log, and falloff--are shown for all mechanisms in Figure 8. Recall that these reaction types modify the computation of the forward rate constant whenever applicable (i.e., they are sub-components of the \(\log(\mathbf{K}_{f})\) computation). The trends can again be characterized by behaviors in the pre-saturated and saturated regimes.