Using Template Magic to Automatically Generate Hybrid CPU/GPU-Code
summary
Template-based wrappers let the same C++ code compile either into a CPU loop or a CUDA kernel by using a cudaMallocManaged allocator for transparent memory and a hybrid functor/kernel wrapper that inspects arguments and launches device or host paths. Worked example: ported a multi-particle collision dynamics solver (MPCD) and verified the functor path compiles to equivalent PTX with no measurable overhead. Measured throughput: ~1.2 billion particles/s on 192 CPU cores, one machine with four GTX1080 cards exceeds that and multi‑GPU runs show about 3.5× speedup; sample code is on the CppCon/GitHub resources.
AI-written summary · about
chapters (20)
- 0:00Introduction to hybrid code
- 2:57Why use GPUs for computation
- 8:05GPU architecture overview
- 11:43Types of GPU memory
- 17:08Threading model in CUDA
- 19:20CUDA C++ language basics
- 23:52Memory allocation in CUDA
- 28:18Problems with repetitive GPU code
- 29:46Goal of hybrid platform-agnostic code
- 31:57Managed memory allocator design
- 34:29Vector type for hybrid use
- 35:12Hybrid functor concept
- 37:11Deploying code to CPU or GPU
- 40:41Kernel wrapper and argument handling
- 44:45Performance impact of wrappers
- 45:53Using the hybrid.hpp library
- 47:01Example vector addition
- 48:07Histogram example and atomic operations
- 51:36Real-world performance gains
- 53:54Q&A session
related talks
01h 33mGPU programming with modern C++
48mBridging the Gap: Writing Portable C++ Programs for CPU and GPU
53mIntroduction to C++ AMP (GPGPU Computing)
01h 32mHeterogeneous Programming in C++ today
27mVendor-Neutral GPU Programming in Chapel
39mThe CUDA C++ Developer Toolbox
05mLightning Talk: GPU Programming with C++ and Triton
25mLeveraging AI Ecosystem for Portable and Sustainable GPU Kernels in HPC
