batmat 0.0.17
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 L, StorageOrder O>
130
131template <class T, class S, class L, StorageOrder O>
142
143template <class T, class I, class S, StorageOrder O, class A>
154
155template <class T, class I, class S, class A, StorageOrder O>
166
167} // namespace detail
168
169/// Convert the given view or matrix type @p V (batmat::matrix::View or batmat::matrix::Matrix) to
170/// a batched view type using a deduced SIMD type. This conversion takes place in the wrapper around
171/// the optimized implementations (which require views with a proper SIMD-compatible stride).
172template <class V>
174
175template <class V>
176concept simdifiable = requires { typename simdified_view_type<std::remove_reference_t<V>>::type; };
177
178template <simdifiable V>
180
181namespace detail {
182
183template <class>
185
186template <simdifiable V>
190
191template <class>
193
194template <simdifiable V>
198
199} // namespace detail
200
201template <class V>
203template <class V>
205
206template <class...>
207inline constexpr bool simdify_compatible = false;
208
209template <simdifiable V, simdifiable... Vs>
210inline constexpr bool simdify_compatible<V, Vs...> =
211 (std::is_same_v<simdified_value_t<V>, simdified_value_t<Vs>> && ...) &&
212 (std::is_same_v<simdified_abi_t<V>, simdified_abi_t<Vs>> && ...);
213
214constexpr auto simdify(simdifiable auto &&a) -> simdified_view_t<decltype(a)> {
215 return simdified_view_t<decltype(a)>{{
216 .data = data(a),
217 .rows = rows(a),
218 .cols = cols(a),
219 .outer_stride = outer_stride(a),
220 }};
221}
222
223template <class V>
225
226template <class V>
229
230template <simdifiable_multi V>
232
233namespace detail {
234
235template <simdifiable_multi V>
236struct simdified_value<V> {
238};
239
240template <simdifiable_multi V>
241struct simdified_abi<V> {
243};
244
245} // namespace detail
246
247template <simdifiable_multi V, simdifiable_multi... Vs>
248inline constexpr bool simdify_compatible<V, Vs...> =
249 (std::is_same_v<simdified_value_t<V>, simdified_value_t<Vs>> && ...) &&
250 (std::is_same_v<simdified_abi_t<V>, simdified_abi_t<Vs>> && ...);
251
252constexpr auto simdify(simdifiable_multi auto &&a) -> simdified_multi_view_t<decltype(a)> {
253 return simdified_multi_view_t<decltype(a)>{{
254 .data = data(a),
255 .depth = depth(a),
256 .rows = rows(a),
257 .cols = cols(a),
258 .outer_stride = outer_stride(a),
259 }};
260}
261
262} // namespace batmat::linalg
Class for a batch of matrices that owns its storage.
stdx::memory_alignment< simd< Tp, Abi > > simd_align
Definition simd.hpp:139
stdx::simd_size< Tp, Abi > simd_size
Definition simd.hpp:137
deduced_abi< Tp, 1 > scalar_abi
Definition simd.hpp:143
stdx::simd_abi::deduce_t< Tp, Np > deduced_abi
Definition simd.hpp:101
stdx::simd< Tp, Abi > simd
Definition simd.hpp:99
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:151
batmat::matrix::View< T, index_t, stride, stride, layer_stride, O > type
Definition simdify.hpp:50
typename batmat::linalg::simdified_view_type< V >::abi_type type
Definition simdify.hpp:196
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:188
batmat::matrix::View< const T, index_t, stride, index_t, layer_stride, O > type
Definition simdify.hpp:163
batmat::matrix::View< T, index_t, stride, index_t, layer_stride, O > type
Definition simdify.hpp:127
typename detail::simdified_value< V >::type simdified_value_t
Definition simdify.hpp:202
typename detail::simdified_abi< V >::type simdified_abi_t
Definition simdify.hpp:204
detail::simdified_multi_view_type< std::remove_reference_t< V > > simdified_multi_view_type
Definition simdify.hpp:224
typename simdified_view_type< V >::type simdified_view_t
Definition simdify.hpp:179
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:173
constexpr bool simdify_compatible
Definition simdify.hpp:207
typename simdified_multi_view_type< V >::type simdified_multi_view_t
Definition simdify.hpp:231
constexpr auto simdify(simdifiable auto &&a) -> simdified_view_t< decltype(a)>
Definition simdify.hpp:214
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.