batmat 0.0.22
Batched linear algebra routines
Loading...
Searching...
No Matches
simdify.hpp
Go to the documentation of this file.
1#pragma once
2
5#include <batmat/simd.hpp>
6#include <guanaqo/mat-view.hpp>
7#include <type_traits>
8
9// TODO: consistent API for guanaqo::MatrixView
10namespace guanaqo {
11template <class T, class I, class S, StorageOrder O>
12constexpr auto data(const MatrixView<T, I, S, O> &v) {
13 return v.data;
14}
15template <class T, class I, class S, StorageOrder O>
16constexpr auto rows(const MatrixView<T, I, S, O> &v) {
17 return v.rows;
18}
19template <class T, class I, class S, StorageOrder O>
20constexpr auto cols(const MatrixView<T, I, S, O> &v) {
21 return v.cols;
22}
23template <class T, class I, class S, StorageOrder O>
24constexpr auto outer_stride(const MatrixView<T, I, S, O> &v) {
25 return v.outer_stride;
26}
27template <class T, class I, class S, StorageOrder O>
28constexpr auto depth(const MatrixView<T, I, S, O> &) {
29 return std::integral_constant<I, 1>{};
30}
31} // namespace guanaqo
32
33namespace batmat::linalg {
34
36
37namespace detail {
38
39template <class V>
41
42template <class T, class S, class L, StorageOrder O>
53
54template <class T, class S, class L, StorageOrder O>
65
66template <class T, class I, StorageOrder O>
77
78template <class T, class I, StorageOrder O>
89
90template <class T, class I, class S, StorageOrder O, class A>
101
102template <class T, class I, class S, class A, StorageOrder O>
113
114// For multiple batches
115
116template <class V>
118
119template <class T, class S, class D, class L, StorageOrder O>
120 requires(D{} == 0 || D{} > S{})
131
132template <class T, class S, class D, class L, StorageOrder O>
133 requires(D{} == 0 || D{} > S{})
144
145template <class T, class I, class S, class D, StorageOrder O, class A>
146 requires(D{} == 0 || D{} > S{})
157
158template <class T, class I, class S, class D, class A, StorageOrder O>
159 requires(D{} == 0 || D{} > S{})
170
171} // namespace detail
172
173/// Convert the given view or matrix type @p V (batmat::matrix::View or batmat::matrix::Matrix) to
174/// a batched view type using a deduced SIMD type. This conversion takes place in the wrapper around
175/// the optimized implementations (which require views with a proper SIMD-compatible stride).
176template <class V>
178
179template <class V>
180concept simdifiable = requires { typename simdified_view_type<std::remove_reference_t<V>>::type; };
181
182template <simdifiable V>
184
185namespace detail {
186
187template <class>
189
190template <simdifiable V>
194
195template <class>
197
198template <simdifiable V>
202
203template <class>
205
206template <simdifiable V>
210
211} // namespace detail
212
213template <class V>
215template <class V>
217template <class V>
219
220template <class...>
221inline constexpr bool simdify_compatible = false;
222
223template <simdifiable V, simdifiable... Vs>
224inline constexpr bool simdify_compatible<V, Vs...> =
225 (std::is_same_v<simdified_value_t<V>, simdified_value_t<Vs>> && ...) &&
226 (std::is_same_v<simdified_abi_t<V>, simdified_abi_t<Vs>> && ...);
227
228constexpr auto simdify(simdifiable auto &&a) -> simdified_view_t<decltype(a)> {
229 return simdified_view_t<decltype(a)>{{
230 .data = data(a),
231 .rows = rows(a),
232 .cols = cols(a),
233 .outer_stride = outer_stride(a),
234 }};
235}
236
237template <class V>
239
240template <class V>
243
244template <simdifiable_multi V>
246
247namespace detail {
248
249template <simdifiable_multi V>
250struct simdified_value<V> {
252};
253
254template <simdifiable_multi V>
255struct simdified_abi<V> {
257};
258
259template <simdifiable_multi V>
260struct simdified_simd<V> {
262};
263
264} // namespace detail
265
266template <simdifiable_multi V, simdifiable_multi... Vs>
267inline constexpr bool simdify_compatible<V, Vs...> =
268 (std::is_same_v<simdified_value_t<V>, simdified_value_t<Vs>> && ...) &&
269 (std::is_same_v<simdified_abi_t<V>, simdified_abi_t<Vs>> && ...);
270
271constexpr auto simdify(simdifiable_multi auto &&a) -> simdified_multi_view_t<decltype(a)> {
272 return simdified_multi_view_t<decltype(a)>{{
273 .data = data(a),
274 .depth = depth(a),
275 .rows = rows(a),
276 .cols = cols(a),
277 .outer_stride = outer_stride(a),
278 }};
279}
280
281} // namespace batmat::linalg
Class for a batch of matrices that owns its storage.
stdx::memory_alignment< simd< Tp, Abi > > simd_align
Definition simd.hpp:142
stdx::simd_size< Tp, Abi > simd_size
Definition simd.hpp:140
deduced_abi< Tp, 1 > scalar_abi
Definition simd.hpp:146
stdx::simd_abi::deduce_t< Tp, Np > deduced_abi
Definition simd.hpp:104
stdx::simd< Tp, Abi > simd
Definition simd.hpp:102
batmat::matrix::View< T, index_t, stride, index_t, layer_stride, O > type
Definition simdify.hpp:154
batmat::matrix::View< const T, index_t, stride, stride, layer_stride, O > type
Definition simdify.hpp:110
batmat::matrix::View< T, index_t, stride, stride, layer_stride, O > type
Definition simdify.hpp:62
batmat::matrix::View< T, index_t, stride, index_t, layer_stride, O > type
Definition simdify.hpp:128
batmat::matrix::View< const T, index_t, stride, index_t, layer_stride, O > type
Definition simdify.hpp:167
batmat::matrix::View< T, index_t, stride, stride, layer_stride, O > type
Definition simdify.hpp:50
batmat::matrix::View< T, index_t, stride, index_t, layer_stride, O > type
Definition simdify.hpp:141
typename batmat::linalg::simdified_view_type< V >::abi_type type
Definition simdify.hpp:200
batmat::matrix::View< T, index_t, stride, stride, layer_stride, O > type
Definition simdify.hpp:98
typename batmat::linalg::simdified_view_type< V >::value_type type
Definition simdify.hpp:192
typename batmat::linalg::simdified_view_type< V >::simd_type type
Definition simdify.hpp:208
typename detail::simdified_value< V >::type simdified_value_t
Definition simdify.hpp:214
typename detail::simdified_abi< V >::type simdified_abi_t
Definition simdify.hpp:216
typename detail::simdified_simd< V >::type simdified_simd_t
Definition simdify.hpp:218
detail::simdified_multi_view_type< std::remove_reference_t< V > > simdified_multi_view_type
Definition simdify.hpp:238
typename simdified_view_type< V >::type simdified_view_t
Definition simdify.hpp:183
detail::simdified_view_type< std::remove_reference_t< V > > simdified_view_type
Convert the given view or matrix type V (batmat::matrix::View or batmat::matrix::Matrix) to a batched...
Definition simdify.hpp:177
constexpr bool simdify_compatible
Definition simdify.hpp:221
typename simdified_multi_view_type< V >::type simdified_multi_view_t
Definition simdify.hpp:245
constexpr auto simdify(simdifiable auto &&a) -> simdified_view_t< decltype(a)>
Definition simdify.hpp:228
constexpr auto outer_stride(const MatrixView< T, I, S, O > &v)
Definition simdify.hpp:24
constexpr auto cols(const MatrixView< T, I, S, O > &v)
Definition simdify.hpp:20
constexpr auto data(const MatrixView< T, I, S, O > &v)
Definition simdify.hpp:12
constexpr auto rows(const MatrixView< T, I, S, O > &v)
Definition simdify.hpp:16
constexpr auto depth(const MatrixView< T, I, S, O > &)
Definition simdify.hpp:28
Owning array of matrices, stored in an efficient batched format.
Definition matrix.hpp:59
Non-owning view of an array of matrices, stored in an efficient batched format.
Definition view.hpp:59
index_type outer_stride
value_type * data
Non-owning view of a batch of matrices.