# A Novel GPU-Based Acceleration Algorithm for a Longwave Radiative Transfer Model
## 4 GPU-Enabled Acceleration Algorithm
### 2D Acceleration Algorithm  
The RRTMG_LW uses a collection of three-dimensional (3D) cells to describe the atmosphere. Its 1D acceleration algorithm with a domain decomposition in the horizontal direction assigns the workload of one \"column,\" shown in Figure 2, to each CUDA thread. Here, the \(x\)-axis  
Figure 1: Profiling graph of the original RRTMG_LW code in the CAS-ESM.  
represents longitude, the \(y\)-axis represents latitude, and the \(z\)-axis represents the vertical direction. The RRTMG_LW in spatial structure has three dimensions, but the \(x\) and \(y\) dimensions in its CUDA code implementation are merged into one dimension to easily write the code. In the CAS-ESM, the IAP AGCM4.0 has a \(1.4^{\circ}\times 1.4^{\circ}\) horizontal resolution and 51 levels in the vertical direction, so the RRTMG_LW has \(nx\times ny\) = \(256\times 128\) horizontal grid points. Thus, the first dimension of 3D arrays in its code has \(256\times 128\) elements at most.  
To make full use of the GPU performance, the 2D acceleration algorithm with a domain decomposition in the horizontal and vertical directions for the RRTMG_LW was proposed in our previous study [23]. Figure 3 illustrates the 2D domain decomposition for the RRTMG_LW accelerated on the GPU. The 2D acceleration algorithm is illustrated in Algorithm 2. Because of data dependency, the acceleration of \(cldpmc\) and \(rtrmmc\) in the vertical direction is unsuitable, while \(intm\), \(setcoef\), and \(taumol\) are able to accelerate in the vertical direction. In the 1D acceleration, \(n\) is the number of threads in each thread block, while \(m=\lceil(\textbf{real})ncol/n\rceil\) is the number of blocks used in each kernel grid. In the 2D acceleration, \(tBlock\) defines the number of threads used in each thread block of the \(x,y\), and \(z\) dimensions by the derived type \(dim3\). Furthermore, \(grid\) defines the number of blocks in the \(x,y\), and \(z\) dimensions by \(dim3\).  
Figure 3: Schematic diagram of 2D decomposition for the RRTMG_LW in the GPU acceleration.  
Figure 2: Spatial structure of RRTMG_LW.  
```
subroutine\(rrtmg\_lw\_d2\)(parameters)
1. Copy input data to GPU device //Call\(inatm\_d1\) with 2D decomposition
2. call\(inatm\_d1\ll\)\(grid\), \(t\)Block\(\gg\)(parameters) //Call\(inatm\_d2\) with 2D decomposition
3. call\(inatm\_d2\ll\)\(grid\), \(t\)Block\(\gg\)(parameters) //Call\(inatm\_d3\) with 1D decomposition
4. call\(inatm\_d3\ll\)\(m\), \(n\gg\)(parameters) //Call\(inatm\_d4\) with 2D decomposition
5. call\(inatm\_d4\ll\)\(grid\), \(t\)Block\(\gg\)(parameters) //Call\(cldpmrc\_d\) with 1D decomposition
6. call\(cldpmrc\_d\ll\), \(m\gg\)(parameters) //Call\(setcoef\_d1\) with 2D decomposition
7. call\(setcoef\_d1\ll\)\(grid\), \(t\)Block\(\gg\)(parameters) //Call\(setcoef\_d2\) with 1D decomposition
8. call\(setcoef\_d2\ll\), \(m\gg\)(parameters) //Call\(taumol\_d\) with 2D decomposition
9. call\(taumol\_d\ll\)\(grid\), \(t\)Block\(\gg\)(parameters) //Call\(rtrtmc\_d\) with 1D decomposition
10. call\(rtrmmc\_d\), \(m\gg\)(parameters)
```  
**Algorithm 2**2D acceleration algorithm.