# A Neural Network-Inspired Matrix Formulation of Chemical Kinetics for Acceleration on GPUs
## 3 GPU Performance Analysis
### Improving Speedup for Large Mechanisms  
A valid concern related to the speedup in Figure 6 is the decreasing trend for Class C mechanisms. A procedure to remove this speedup deterioration for these larger mechanisms is provided here. Put briefly, the procedure relies on taking advantage of the inherent sparsity that characterizes mechanisms with high \(N_{S}\) and \(N_{R}\) values. This concept is first motivated by a computational budget analysis of the original routines leading to the speedups shown in Figure 6. It is then shown that a simple replacement of several problematic dense matrix multiplications with sparse counterparts very usefully recovers the \"lost\" speedup for the Class C mechanisms. The computational budget, measured as the proportion of total compute time spent in the respective routines, is provided in Figure 9 for the same three mechanisms shown in Figure 7. For each mechanism and \(N_{C}\), the budget is split into four main components encountered during the source term computation:  
1. _The preprocessing routine_ consists of kernels that: (a) recover the primitive species mass fractions from conserved values; (b) normalize the species mass fractions in each cell to sum to unity; and (c) obtain molar concentrations from the mass fractions. 2. _The forward rate constant routine_ for \(\log(\mathbf{K}_{f})\) computes Equation (6) along with any other non-standard reaction types that modify the forward rate (three-body, pressure-log, and falloff). 3. _The equilibrium rate constant routine_ for \(\log(\mathbf{K}_{c})\) is outlined in Equation (9). 4. _The species net production rate routine_ for \(\mathbf{\Omega}\), given by Equation (2)--the cost of evaluating the net reaction rates \(\mathbf{Q}_{net}\) required to recover \(\mathbf{\Omega}\) (Equation (4))--is also included for this component. A revealing result is that, for all mechanisms, upon entering the saturated regime, the budget is dominated by Component 4 (evaluation of the production rates). In fact, its contribution in both pre-saturated and saturated regimes grows with larger mechanisms, and the effect of saturation on the budget itself (i.e., the amount that the contribution of Component 4 changes upon entering the saturated regime) is diminished when moving from mechanism Class A to Class B and then to Class C.  
Therefore, it can be concluded to good confidence that the main culprit for the diminishing speedup seen in large mechanisms in Figure 6 is derived from Component 4. This is the direct cause of prohibitive dense cuBLAS DGEMM operations involving the exceedingly large reaction matrices (matrices of size \(N_{C}\times N_{R}\)) found in Equations (2) and (4). Such operations involve matrix multiplications with the net, forward, and reverse stoichiometric matrices \(\boldsymbol{\
u}\), \(\boldsymbol{\
u}^{\prime}\) and \(\boldsymbol{\
u}^{\prime\prime}\). Figure 8: Cost per reaction for all mechanisms for: standard reactions (**left**); pressure-log reactions (**middle**); and falloff reactions (**right**). See Table 1 for mechanism information. As alluded to above, with the contribution of Component 4 on the budget in mind, the diminishing speedups can be alleviated by recognizing that the common denominator in the prohibitive routines--the stoichiometric matrices--are predominantly sparse for large mechanisms due to the physical constraints of elementary reactions that serve as the building blocks. This effect can be visualized through the inherent correlation between mechanism sparsity, as measured by the ratio of the number of zero to total elements in the net stoichiometric matrix \(\
u\), and the \(N_{C}\)-averaged budget contribution for component 4 (the sparsity of the net stoichiometric matrix is a conservative estimate for overall mechanism sparsity, since the forward and reverse stoichiometric matrices individually are generally more sparse). This correlation is shown in Figure 10 (left).