# A Neural Network-Inspired Matrix Formulation of Chemical Kinetics for Acceleration on GPUs
## 2 Methodology
### Matrix-Based Kinetics Equations
The result can be expressed as a matrix multiplication  
\[\mathbf{G}=\mathbf{H}-\mathbf{S}=\mathbf{X}_{G}\mathbf{W}_{G}+B_{G},\text{ where} \tag{10}\]  
\[\mathbf{X}_{G}= \begin{bmatrix}\log T_{1}&T_{1}&T_{1}^{2}&T_{1}^{3}&T_{1}^{4}& 1/T_{1}\\ \log T_{2}&T_{2}&T_{2}^{2}&T_{2}^{3}&T_{2}^{4}&1/T_{2}\\ \vdots&\vdots&\vdots&\vdots&\vdots\\ \log T_{N_{\mathrm{C}}}&T_{N_{\mathrm{C}}}&T_{N_{\mathrm{C}}}^{2}&T_{N_{ \mathrm{C}}}^{3}&T_{N_{\mathrm{C}}}^{4}&1/T_{N_{\mathrm{C}}}\end{bmatrix} , \quad\mathbf{W}_{G}= \begin{bmatrix}\alpha_{1,1}&\ldots&\alpha_{1,N_{\mathrm{S} }}\\ \alpha_{2,1}&\ldots&\alpha_{2,N_{\mathrm{S}}}\\ \vdots&\ddots&\vdots\\ \alpha_{6,1}&\ldots&\alpha_{6,N_{\mathrm{S}}}\end{bmatrix} ,\quad B_{G}= \begin{bmatrix}\alpha_{7,1}\\ \alpha_{7,2}\\ \vdots\\ \alpha_{7,N_{\mathrm{S}}}\end{bmatrix} ^{T}.\]  
In Equation (10), \(\mathbf{X}_{G}\in\mathbb{R}^{N_{\mathrm{C}}\times 6}\) is the input consisting of various functions of temperature and \(\mathbf{\alpha}\in\mathbb{R}^{7\times N_{\mathrm{S}}}\) is a matrix of polynomial coefficients; the first six rows of \(\mathbf{\alpha}\) is the weight matrix \(\mathbf{W}_{G}\) and the last row is the bias \(B_{G}\). Note that, although not shown in Equation (10) for conciseness, the quantities in \(\mathbf{\alpha}\) (and in turn \(\mathbf{W}_{G}\) and \(B_{G}\)) are also functions of the cell temperature \(T_{i}\) and the species index. This is because the species polynomial coefficients change based on a cutoff temperature (usually 1000 K). Regarding practical implementation, in the case that the NASA cutoff temperature is the same for all of the species (say 1000 K), it is possible to treat the evaluation of Equation (10) (the first layer in Figure 1c) with linear algebra libraries (i.e., cuBLAS operations) by populating two copies of \(\mathbf{\alpha}\) based on the cutoff threshold. However, this approach is only feasible in the case when the NASA cutoff temperature is the same for all of the species. In the more general case where the cutoff temperature varies with the species index, it is much more convenient to directly treat the evaluation of Equation (10) using a custom matrix multiplication kernel that computes the polynomial directly--with conditional logic that populates the values in \(\mathbf{\alpha}\) on-the-fly based on the cell temperature--instead of a using the cuBLAS (or other similar) routines. The convenience here outweighs the hit on GPU optimality, and, as such, this is the approach used in the GPU implementation profiled in Section 3. It should be noted that a principle advantage in considering the matrix form for the evaluation of NASA polynomials (as in Equation (10)) comes with the approximate ANN framework (see Appendix A)--the framework overcomes the conditional logic limitations imposed by the NASA coefficients by designing a neural network to essentially discover new polynomials such that the equilibrium rate constants can be recovered, but the coefficients' dependence on temperature is removed. Inserting Equation (10) into Equation (9) gives  
\[\log(\mathbf{K}_{c})=-(\mathbf{X}_{G}\mathbf{W}_{G}+B_{G})\mathbf{\
u}, \tag{11}\]where the standard concentration term \(p_{ref}/RT_{i}\) has been integrated into the bias \(B_{G}\). Equation (11) can be interpreted as a linear two-layer ANN. The parameters of the first layer (the Gibbs layer) are the temperature-dependent \(\mathbf{W}_{G}\) and \(B_{G}\) and those of the second layer are the net stoichiometric coefficients \(\mathbf{\
u}\). The intermediary neurons (i.e., hidden layer neurons) here are referred to as the Gibbs neurons. Illustrations of both the forward and the equilibrium rate constant formulations as neural network-inspired architectures are shown in Figure 1b,c, with Arrhenius and Gibbs neurons highlighted. Alongside the formulations provided above, however, some additional complications arise when considering the forward rate constant in detailed reaction mechanisms and the treatment of zero concentrations.