Is C++23 std::mdspan a Zero-overhead Abstraction?
Talkat CppCon 2023 · on Wednesday, 2023-10-04· at 15:15· Cottonwood 8/9, 6700 North Gaylord Rockies Boulevard·
summary
Asks whether std::mdspan is zero‑overhead and measures it concretely: compiles matrix and image kernels, compares generated assembly against BLAS‑style low‑level code using Clang at O2/O1 and Google Benchmark, counts assembly lines (baseline ~32, initial mdspan ~42 then ~35 after tweaks), isolates the extra instructions to ABI and layout choices, implements a stride‑only layout and splits extents to shrink the object so registers instead of stack are used, and finds parity on System V but extra stacks and memory ops remain on MSVC due to the System V ABI and Windows calling convention limits; uses std::mdspan and layout_stride variants to reach zero overhead only with careful layout and platform-aware packing.
AI-written summary · about
chapters (18)
- 0:00Introduction
- 1:08What is std::mdspan
- 3:15Matrix addition with BLAS
- 5:47Assembly for matrix add
- 7:12Benchmarking O2 vs O1
- 9:18std::mdspan for matrix ops
- 13:21Matrix addition with std::mdspan
- 16:17Overhead in std::mdspan asm
- 19:50Optimizing std::mdspan
- 23:06ABI limitations
- 25:16Identical asm with optimizations
- 27:26User-friendly wrappers
- 30:14MSVC ABI issues
- 32:29Key takeaways
- 34:23Q&A
- 36:54Q&A
- 39:27Higher-dim std::mdspan
- 46:25Conclusion
related talks
01h 03mHidden Overhead of a Function API
01h 02mStandardizing a linear algebra library
01h 01mWant fast C++? Know your hardware!
01h 22mCostless Software Abstractions for Parallel Architectures
55mC++ 20 Innovations: High-Performance Cross-Platform Architecture in C++
01h 00mKilling C++ Serialization Overhead & Complexity
01h 08mAn implementer's view of Boost.SIMD
58mHigh-performance code design patterns in C#
