Strategies for Batching in Spectral Element Codes with AMR and Time-Dependent Meshes
Spectral element methods (SEM) with adaptive mesh refinement (AMR) and time-dependent meshes face challenges for GPUs due to irregular data access patterns and heterogeneous computational kernels. Below are key strategies to enable efficient batching:
1. Batching Strategies for Spectral Elements
(a) Grouping by Element Type
- Approach: Batch elements with identical polynomial orders, sizes, and kernel requirements.
- Implementation:
- Use contiguous memory layouts for solution coefficients, quadrature points, and Jacobians of similar elements.
- Example: Group all elements with order (p=3) into a batch, and process them with a single kernel.
- Benefit: Maximizes data locality and kernel reuse.
(b) Kernel Fusion and Task Batching
- Approach: Fuse multiple operations (e.g., mass matrix assembly, flux computation) into a single kernel.
- Implementation:
- Use CUDA streams to overlap computation and data transfer.
- Example: Batch face flux computations across all elements, then batch volume integrations.
- Benefit: Reduces kernel launch overhead and improves occupancy.
(c) Hybrid Parallelism
- Approach: Combine coarse-grained (element-level) and fine-grained (quadrature-level) parallelism.
- Implementation:
- Coarse: Assign batches of elements to GPU blocks.
- Fine: Use threads within a block to process quadrature points.
- Benefit: Balances load distribution and hides latency.
(d) Dynamic Load Balancing
- Approach: Use work queues to assign elements to GPU blocks dynamically.
- Implementation:
- Atomic queues: Each GPU block fetches the next available element.
- Example: Charm++'s load balancer redistributes work across GPUs.
- Benefit: Handles AMR-induced workload imbalances.
(e) Overlap Communication/Computation
- Approach: Asynchronous halo exchange for AMR boundaries.
- Implementation:
- Use CUDA asynchronous memory copies (e.g.,
cudaMemcpyAsync) and double buffering.
- Benefit: Masks latency from mesh re-partitioning.
2. Mapping CPU Task Models to GPUs
(a) OpenMP on GPUs
- Challenges: OpenMP tasking (e.g.,
#pragma omp task) is not natively supported on GPUs.
- Solutions:
- Tools: NVIDIA’s OpenMP 5.0+ offloading or OpenACC.
(b) Charm++ on GPUs
3. Efficient Task Granularity for NVIDIA A100/H100
-
Optimal Granularity:
- Element-Level: 1–10 elements per GPU block.
- A100: 108 SMs → 108 blocks max. Aim for 4–8 elements/block.
- H100: 132 SMs → 132 blocks max. Aim for 4–8 elements/block.
- Quadrature-Level: 32–128 threads/block (1 warp per quadrature point).
- Example: For (p=4) elements (64 quadrature points), use 64 threads/block.
-
Occupancy Targets:
- A100: Max 8 active blocks/SM, 2048 threads/SM.
- H100: Max 12 active blocks/SM, 1536 threads/SM.
- Guideline: Keep occupancy > 50% by tuning block size and registers.
-
Kernel Launch Overhead:
- Cost: ~10–20 µs per kernel.
- Batch Size: Process ≥100 elements per kernel to amortize overhead.
4. Prominent Tools and Frameworks
- NVIDIA CUDA: Low-level control for custom kernels and batching.
- Charm++: Task-based parallelism with GPU support via CkGPU.
- Kokkos: Performance-portable tasking (e.g.,
Kokkos::TaskTeam).
- RAJA: GPU offloading with task scheduling.
- NVIDIA ExaGeoStat: SEM-specific library for GPU acceleration.
5. Practical Recommendations
- Batching: Prioritize element grouping and kernel fusion to reduce irregularity.
- Task Granularity:
- Coarse: 4–8 elements/GPU block.
- Fine: 32–128 threads/block (align with warp size).
- Dynamic Load Balancing: Use Charm++ or Kokkos for AMR workloads.
- Overlap: Asynchronous communication + computation via CUDA streams.
- Profiling: Use NVIDIA Nsight Compute to optimize occupancy and kernel efficiency.
By combining batched kernel execution with dynamic task models, spectral element codes can leverage GPUs like A100/H100 despite AMR-induced irregularities. The key is balancing granularity to hide latency while maximizing parallelism.