The challenge you're describing - adapting spectral element methods with dynamic mesh refinement to GPU architectures - is indeed at the forefront of computational science. Let me break down the key strategies and tools available.
Batching Strategies for Spectral Elements
For spectral element methods on GPUs, the primary challenge is managing the tension between high-order accuracy (which creates small, compute-intensive kernels) and GPU efficiency (which prefers large, uniform workloads). Several approaches have emerged:
Kernel fusion and batching: Libraries like libParanumal and NekRS have pioneered techniques where multiple small spectral element operations are batched together. They typically group elements with the same polynomial order and apply the same operations across batches. This works particularly well for the core operations like applying mass matrices or differentiation operators.
Tensor product formulations: Since spectral element operations often decompose into tensor products, frameworks exploit this structure by reshaping operations to maximize data reuse. The key insight is that even with varying element sizes, the underlying tensor contractions can be batched if cleverly organized.
Multi-level parallelism: Modern approaches use a hierarchy where elements are distributed across thread blocks, while within each element, the quadrature points are processed by individual threads. This maps well to the GPU's architecture while maintaining the mathematical structure of spectral methods.
Task-Based Models on GPUs
Regarding your question about mapping CPU task models to GPUs - yes, there are several emerging solutions:
CUDA Graphs and Dynamic Parallelism: NVIDIA's CUDA Graphs allow you to capture and replay complex kernel sequences, which can help with irregular workloads. Dynamic parallelism enables kernels to launch other kernels, creating a form of task-based execution, though with overhead considerations.
GPU task schedulers: Systems like Legion (from Stanford) and StarPU have GPU backends that can handle task graphs with data dependencies. They're particularly useful when you have heterogeneous kernels that need coordination.
Kokkos tasking: The Kokkos framework has experimental support for task-based parallelism on GPUs, though it's more mature on CPUs. It attempts to map task DAGs to GPU execution, but efficiency depends heavily on task granularity.
Efficient Granularity on A100/H100
For modern NVIDIA GPUs like A100 and H100, efficient granularity depends on several factors:
Warp-level operations: The fundamental unit is 32 threads (a warp). For spectral elements, you want at least one warp per element, but often multiple warps for higher polynomial orders. For example, with polynomial order N=7, you have 8³=512 points in 3D, which maps nicely to 16 warps.
Occupancy considerations: A100 and H100 have 108 and 132 SMs respectively. You need thousands of thread blocks to keep them busy. For adaptive meshes, this means batching small elements is crucial - you might batch 100-1000 small elements into a single kernel launch.
Memory hierarchy: These GPUs have large L2 caches (40MB on A100, 50MB on H100). Spectral element methods can benefit by ensuring frequently accessed operators (like differentiation matrices) fit in L2. The granularity should be chosen so working sets per SM fit in the 192KB of combined L1/shared memory.
Tensor Core utilization: For high-order spectral elements, the dense matrix operations can potentially use Tensor Cores. This requires specific data layouts and granularities - typically multiples of 16 for FP16 or 8 for TF32 operations.
Practical Recommendations
For adaptive spectral element codes, I'd suggest:
- Use a two-level approach: coarse-grained distribution of element patches to SMs, fine-grained parallelism within elements
- Batch elements by polynomial order and operation type
- Consider frameworks like OCCA or Kokkos that provide performance portability
- For truly dynamic adaptivity, maintain element pools sorted by size/order to facilitate efficient batching
- Profile extensively - tools like Nsight Compute can reveal whether you're memory-bound or compute-bound for your specific polynomial orders
The field is rapidly evolving, with new techniques emerging for handling irregular computations on GPUs. The key is finding the right balance between maintaining the mathematical elegance of spectral methods and adapting to the architectural constraints of modern accelerators.