This section covers the modernized column virtualization and grid layout APIs that enable high-performance 1D atmospheric column processing in CATChem.
Under the C++20 and Kokkos architecture, the Column Interface system has been fully redesigned to achieve zero-overhead, copy-free execution on modern hardware:
-
catchem::GridManager: Manages grid layout dimensions (
$N_{\text{cols}}$ ,$N_{\text{levels}}$ ). - Kokkos Subviews: Slices 1D columns from 3D multi-dimensional arrays instantly with zero allocation or data copying.
- Kokkos Parallel For: Executes column calculations in parallel across heterogeneous computing nodes (CPUs and GPUs).
Rather than copying full 3D fields to local 1D data structures, CATChem slices 1D column vectors using standard Kokkos subviews. Slices point directly to the underlying contiguous multidimensional memory:
#include <Kokkos_Core.hpp>
void MyProcess::run(std::shared_ptr<StateManager> state) {
auto n_cols = state->n_cols;
// Parallelize column executions
Kokkos::parallel_for("ProcessColumns", Kokkos::RangePolicy<Kokkos::HostSpace>(0, n_cols),
[=](const int icol) {
// Slice the 3D temperature view for column 'icol' with zero-copy
// Coordinates: (column_index, level_index, species_or_attribute_index)
auto col_temp = Kokkos::subview(state->met.temp, icol, Kokkos::ALL(), 0);
// Access and modify elements directly in-place
for (int k = 0; k < state->n_levels; ++k) {
double t_k = col_temp(k);
col_temp(k) = calculate_new_temp(t_k);
}
});
}Benefits:
- Zero Duplication: No heap allocations or data copies are made during slicing.
- Locality Optimization: Leverages row-major or column-major Kokkos views matching underlying system architectures (e.g.
LayoutLeftfor CUDA/HIP GPUs,LayoutRightfor OpenMP CPUs).
The C++ class managing physical grid dimensions:
#pragma once
namespace catchem {
class GridManager {
public:
const int n_cols; ///< Total number of contiguous horizontal columns.
const int n_levels; ///< Total number of vertical levels.
GridManager(int nc, int nl) : n_cols(nc), n_levels(nl) {}
};
} // namespace catchemKokkos automatically maps parallel column loops to available hardware threads (e.g., OpenMP threads on multi-core CPUs, or threads/blocks on GPUs):
Kokkos::parallel_for("ColumnAerosols", Kokkos::RangePolicy<Kokkos::HostSpace>(0, state->n_cols),
[=](const int icol) {
// Run aerosol settling scheme on independent 1D column
run_aerosol_column_kernel(state, icol);
});For operations that are completely independent of vertical column contexts, use Kokkos multi-dimensional range policies to loop over all grid cells concurrently:
Kokkos::parallel_for("ScaleMetPres", Kokkos::MDRangePolicy<Kokkos::Rank<2>>({0, 0}, {state->n_cols, state->n_levels}),
KOKKOS_LAMBDA(const int icol, const int k) {
state->met.pressure(icol, k, 0) *= 1.01;
});- Prefer Kokkos Subviews: Never use manual copying or temporary
std::vectorallocations to represent columns. Subviews are instant and run on both CPU and GPU memory spaces in-place. - Align Memory Layouts: Match Kokkos View layouts with execution backends. Use
LayoutLeftfor GPU acceleration to achieve coalesced global memory access, orLayoutRightfor sequential CPU cache locality.
- Prevent Out-of-Bounds: Always use grid boundaries from
state->n_colsandstate->n_levelsto guard level-iteration loops. - Coordinate Thread Space: Avoid calling host-only or BIND(C) routines inside parallel Kokkos device lambda loops. Keep parallel lambda bodies purely mathematical and scientific.
- State Management API - Multidimensional Kokkos Views
- Process Interface API - Scheduling and Process Registry
- GasChem Process Documentation - 3D Grid flattening to 1D MICM arrays