On the Template Programming Approach for Shared-Memory Parallel Architectures Across GPU Vendors Using CUDA, SYCL, and HIP
摘要
We present a template programming approach for implementing computational algorithms targeting both GPU and multithreaded CPU architectures. Building upon our previously developed SCFD library which enables hardware-independent algorithm development in modern C++, our approach leverages template metaprogramming capabilities. The SCFD library’s core components include array classes, memory structures, and parallel for each algorithms. We extend the library’s portability by implementing SYCL and HIP support for memory operations, for each classes, and reduction-type operations. Also, we develop a geometric multigrid solver for structured rectangular grids that remains architecture-independent. Our benchmarks include solving the Poisson equation using the multigrid method across various architectures (Nvidia GPUs, AMD GPUs, and multiple CPUs). Additional verification tests compare our template library against native CUDA and HIP implementations for batch matrix-matrix multiplication, achieving 12% of peak GPU performance in SYCL. Comparisons with Nvidia GPUs using CUDA backends show comparable results. The geometric multigrid implementation demonstrates optimal O(N) asymptotic performance across all tested backends (CPU, Nvidia GPU, and AMD GPU). Our results demonstrate the uniformity of the templated library approach, enabling the utilization of any mass-produced hardware accelerator currently available on the market.