4#include <batmat/config.hpp>
18template <
class T,
class Abi>
22 using mask =
typename simd::mask_type;
29 using one_t = std::integral_constant<index_t, 1>;
30 template <
class S = T, StorageOrder O = StorageOrder::ColMajor>
32 template <
class S = T, StorageOrder O = StorageOrder::ColMajor>
34 template <
class S = T, StorageOrder O = StorageOrder::ColMajor>
36 template <
class S = T, StorageOrder O = StorageOrder::ColMajor>
38 template <
class S = T, StorageOrder O = StorageOrder::ColMajor>
43 template <
int MaskL = 0>
45 if constexpr (MaskL == 0) {
47 }
else if constexpr (MaskL > 0) {
48#if BATMAT_WITH_GSI_HPC_SIMD
49 typename simd::mask_type m{[&](
size_t i) {
return i >= MaskL; }};
51 typename simd::mask_type m{};
52 for (
int i = 0; i < static_cast<int>(m.size()); ++i)
57#if BATMAT_WITH_GSI_HPC_SIMD
58 typename simd::mask_type m{[&](
size_t i) {
return i < m.size() + MaskL; }};
60 typename simd::mask_type m{};
61 for (
int i = 0; i < static_cast<int>(m.size()); ++i)
62 m[i] = i <
static_cast<int>(m.size()) + MaskL;
69template <
class T,
class Abi, StorageOrder Order = StorageOrder::ColMajor>
71template <
class T,
class Abi, StorageOrder Order = StorageOrder::ColMajor>
74template <
class Abi, StorageOrder Order = StorageOrder::ColMajor>
76template <
class Abi, StorageOrder Order = StorageOrder::ColMajor>
79template <
class T,
class Abi, StorageOrder Order>
92 [[gnu::always_inline]]
value_type *
get(index_t r, index_t c)
const noexcept {
93 ptrdiff_t i0 = Order == StorageOrder::RowMajor ? c : r;
94 ptrdiff_t i1 = Order == StorageOrder::RowMajor ? r : c;
100 [[gnu::always_inline]]
simd load(index_t r, index_t c)
const noexcept {
103 template <
int MaskL = 0>
104 [[gnu::always_inline]]
void store(
simd x, index_t r, index_t c)
const noexcept
105 requires(!std::is_const_v<T>)
107 types::template aligned_store<MaskL>(x,
get(r, c));
109 template <
class Self>
110 [[gnu::always_inline]] Self
block(
this const Self &self, index_t r, index_t c)
noexcept {
111 return {self.get(r, c), self.outer_stride};
113 template <
class Self>
114 [[gnu::always_inline]] Self
middle_rows(
this const Self &self, index_t r)
noexcept {
115 return {self.get(r, 0), self.outer_stride};
117 template <
class Self>
118 [[gnu::always_inline]] Self
middle_cols(
this const Self &self, index_t c)
noexcept {
119 return {self.get(0, c), self.outer_stride};
125 requires std::is_const_v<T>
130 requires std::is_const_v<T>
135template <
class T,
class Abi>
141 template <StorageOrder Order>
143 template <StorageOrder Order>
152 [[gnu::always_inline]]
simd load(index_t r)
const noexcept {
155 template <
int MaskL = 0>
156 [[gnu::always_inline]]
void store(
simd x, index_t r)
const noexcept
157 requires(!std::is_const_v<T>)
159 types::template aligned_store<MaskL>(x, &
operator()(r));
161 template <
class Self>
162 [[gnu::always_inline]] Self
segment(
this const Self &self, index_t r)
noexcept {
167 template <StorageOrder Order>
169 requires std::is_const_v<T>
173 template <StorageOrder Order>
178 requires std::is_const_v<T>
183template <index_t Size,
class T,
class Abi, StorageOrder Order>
193 ptrdiff_t i0 = Order == StorageOrder::RowMajor ? c : r;
194 index_t i1 = Order == StorageOrder::RowMajor ? r : c;
198 [[gnu::always_inline]]
simd load(index_t r, index_t c)
const noexcept {
201 template <
int MaskL = 0>
202 [[gnu::always_inline]]
void store(
simd x, index_t r, index_t c)
const noexcept
203 requires(!std::is_const_v<T>)
205 types::template aligned_store<MaskL>(x, &
operator()(r, c));
208 template <index_t... Is>
210 std::integer_sequence<index_t, Is...>) noexcept
211 :
data{(o.data + Is * o.inner_stride *
static_cast<ptrdiff_t
>(o.outer_stride))...} {}
213 :
cached_uview{o, std::make_integer_sequence<index_t, Size>()} {}
216#ifdef __INTEL_LLVM_COMPILER
218template <index_t Rows, index_t Cols,
class T,
class Abi, StorageOrder Order>
219[[gnu::always_inline]]
inline auto with_cached_access(uview<T, Abi, Order> o)
noexcept {
224template <index_t Rows, index_t Cols,
class T,
class Abi, StorageOrder Order>
225 requires(Rows > 0 && Cols > 0)
226[[gnu::always_inline]]
inline cached_uview<Order == StorageOrder::ColMajor ? Cols : Rows, T, Abi,
232template <index_t Rows, index_t Cols,
class T,
class Abi>
233 requires(Rows == 0 && Cols > 0)
234[[gnu::always_inline]]
inline cached_uview<Cols, T, Abi, StorageOrder::ColMajor>
239template <index_t Rows, index_t Cols,
class T,
class Abi>
240 requires(Rows == 0 && Cols > 0)
241[[gnu::always_inline]]
inline uview<T, Abi, StorageOrder::RowMajor>
246template <index_t Rows, index_t Cols,
class T,
class Abi>
247 requires(Rows > 0 && Cols == 0)
248[[gnu::always_inline]]
inline cached_uview<Rows, T, Abi, StorageOrder::RowMajor>
253template <index_t Rows, index_t Cols,
class T,
class Abi>
254 requires(Rows > 0 && Cols == 0)
255[[gnu::always_inline]]
inline uview<T, Abi, StorageOrder::ColMajor>
#define BATMAT_ASSUME(x)
Invokes undefined behavior if the expression x does not evaluate to true.
Class for a batch of matrices that owns its storage.
void aligned_store(V v, typename V::value_type *p)
stdx::memory_alignment< simd< Tp, Abi > > simd_align
stdx::simd_size< Tp, Abi > simd_size
V aligned_load(const typename V::value_type *p)
simd< Tp, deduced_abi< Tp, Np > > deduced_simd
void masked_aligned_store(V v, typename V::mask_type m, typename V::value_type *p)
stdx::simd< Tp, Abi > simd
simd_view_types< real_t, Abi >::template view< real_t, Order > mut_real_view
simd_view_types< std::remove_const_t< T >, Abi >::template matrix< T, Order > matrix
simd_view_types< real_t, Abi >::template view< const real_t, Order > real_view
cached_uview< Order==StorageOrder::ColMajor ? Cols :Rows, T, Abi, Order > with_cached_access(const uview< T, Abi, Order > &o) noexcept
simd_view_types< std::remove_const_t< T >, Abi >::template view< T, Order > view
value_type *const data[Size]
value_type & operator()(index_t r, index_t c) const noexcept
cached_uview(const uview< T, Abi, Order > &o, std::integer_sequence< index_t, Is... >) noexcept
simd_view_types< std::remove_const_t< T >, Abi > types
cached_uview(const uview< T, Abi, Order > &o) noexcept
simd load(index_t r, index_t c) const noexcept
static constexpr ptrdiff_t inner_stride
typename types::simd simd
void store(simd x, index_t r, index_t c) const noexcept
static void aligned_store(simd x, value_type *p) noexcept
typename simd::mask_type mask
matrix::View< S, index_t, one_t, index_t, index_t, O > multi_scalar_view
datapar::deduced_simd< index_t, simd::size()> isimd
datapar::simd_size< T, Abi > simd_stride_t
static constexpr auto simd_align
datapar::simd< T, Abi > simd
matrix::View< S, index_t, simd_stride_t, simd_stride_t, matrix::DefaultStride, O > view
matrix::Matrix< S, index_t, simd_stride_t, index_t, O, simd_align_t > matrix
matrix::View< S, index_t, simd_stride_t, index_t, index_t, O > multi_view
static simd aligned_load(const T *p) noexcept
matrix::View< S, index_t, one_t, simd_stride_t, matrix::DefaultStride, O > scalar_view
std::integral_constant< index_t, 1 > one_t
datapar::simd_align< T, Abi > simd_align_t
static constexpr auto simd_stride
simd_view_types< std::remove_const_t< T >, Abi > types
static constexpr ptrdiff_t inner_stride
void store(simd x, index_t r) const noexcept
uview_vec(const mut_view< Order > &v) noexcept
typename types::simd simd
value_type & operator()(index_t r) const noexcept
uview_vec(const view< Order > &v) noexcept
Self segment(this const Self &self, index_t r) noexcept
simd load(index_t r) const noexcept
types::template view< T, Order > view
uview_vec< std::remove_const_t< T >, Abi > mut_uview
types::template view< std::remove_const_t< T >, Order > mut_view
uview_vec(const mut_uview &o) noexcept
uview_vec(const uview_vec &o)=default
uview_vec(value_type *data) noexcept
types::template view< T, Order > view
Self block(this const Self &self, index_t r, index_t c) noexcept
types::template view< std::remove_const_t< T >, Order > mut_view
uview(const view &v) noexcept
uview(const mut_view &v) noexcept
void store(simd x, index_t r, index_t c) const noexcept
simd load(index_t r, index_t c) const noexcept
uview< std::remove_const_t< T >, Abi, Order > mut_uview
Self middle_rows(this const Self &self, index_t r) noexcept
Self middle_cols(this const Self &self, index_t c) noexcept
value_type & operator()(index_t r, index_t c) const noexcept
static constexpr ptrdiff_t inner_stride
uview(const uview &o)=default
simd_view_types< std::remove_const_t< T >, Abi > types
value_type * get(index_t r, index_t c) const noexcept
uview(value_type *data, index_t outer_stride) noexcept
typename types::simd simd
uview(const mut_uview &o) noexcept
Class for a batch of matrices that owns its storage.
Non-owning view of a batch of matrices.
Non-owning view of a batch of matrices.