Is C++23 std::mdspan a Zero-overhead Abstraction? - Oleksandr Bacherikov - CppCon 2023

preview_player
Показать описание
---

Is C++23 std::mdspan a Zero-overhead Abstraction? - Oleksandr Bacherikov - CppCon 2023

C++23 introduces std::mdspan into the standard library as a view over multi-dimensional arrays. This talk will try to establish some of the best practices for using mdspan, and highlight subtleties to be aware of. Taking some basic matrix and image operations, we'll compare the generated assembly to low-level implementations similar to BLAS, and check if mdspan can be used in a way to avoid any overhead. We'll discuss how the results are affected by mdspan design decisions and ABI limitations.
---

Oleksandr Bacherikov

Oleksandr Bacherikov is a Software Engineer at Snap Inc working on Computer Vision and Machine Learning magic for mobile devices. He has more than 15 years of experience in Competitive Programming and is interested in implementing algorithms in the most effective, concise, and generic way at the same time.
__

---

#cppcon #cppprogramming #cpp
Рекомендации по теме
Комментарии
Автор

18:51 [slide 37] I wonder if adding [[assume()]] attributes to tell the compiler that the extents of all 3 mdspans are the same would improve the generated assembly. Great talk Oleksandr

Roibarkan
Автор

A matrix addition is not in the BLAS because it is rare your computation is only doing matrix additions. A (large) matrix addition is completly memory bound so instead of trashing your cache it would be better if the addition could be implemented as part of more general operations.
GEMM is such an operation, which when done correctly is compute bound, it lets you do alpha*A*B + beta*C. alpha and beta are scalar and A, B and C are matrices.
Because it is compute bound you dont pay the price of the addition (also O(n^2) << O(n^3)).
In the end, it is just good API design, effectively preventing the user from shooting his foot (by using a standalone matrix add).

LeDabe
Автор

If the question is whether or not <abstraction> is zero overhead, the answer is no. Next question.

combatcorgiofficial