VCTR
Loading...
Searching...
No Matches
ContainerAndExpressionConcepts.h
1/*
2 ==============================================================================
3 DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
5 Copyright 2022- by sonible GmbH.
6
7 This file is part of VCTR - Versatile Container Templates Reconceptualized.
8
9 VCTR is free software: you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License version 3
11 only, as published by the Free Software Foundation.
12
13 VCTR is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Lesser General Public License version 3 for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 version 3 along with VCTR. If not, see <https://www.gnu.org/licenses/>.
20 ==============================================================================
21*/
22
23namespace vctr::detail
24{
25
26// clang-format off
27template <class T>
28struct AnyVctr : std::false_type {};
29
30template <class T, template <class> class A>
31struct AnyVctr<Vector<T, A>> : std::true_type {};
32
33template <class T, size_t e, size_t s>
34struct AnyVctr<Array<T, e, s>> : std::true_type {};
35
36template <class T, size_t n, class S>
37struct AnyVctr<Span<T, n, S>> : std::true_type {};
38
39template <class E, class S, size_t e, class I>
40struct AnyVctr<VctrBase<E, S, e, I>> : std::true_type {};
41
42template <class T>
43struct IsSpan : std::false_type {};
44
45template <class T, size_t n, class S>
46struct IsSpan<Span<T, n, S>> : std::true_type {};
47
48template <class T>
49struct IsStdArray : std::false_type {};
50
51template <class T, size_t e>
52struct IsStdArray<std::array<T, e>> : std::true_type {};
53
54template <class T>
55struct IsStdSpan : std::false_type {};
56
57template <class T, size_t e>
58struct IsStdSpan<std::span<T, e>> : std::true_type {};
59
60template <class T>
61struct IsExpressionChainBuilder : std::false_type {};
62
63template <template <size_t, class...> class ExpressionType, class RuntimeArgs, class... AdditionalParameters>
64struct IsExpressionChainBuilder<ExpressionChainBuilderWithRuntimeArgs<ExpressionType, RuntimeArgs, AdditionalParameters...>> : std::true_type {};
65// clang-format on
66
67} // namespace vctr::detail
68
69namespace vctr::has
70{
71
73template <class T>
74concept getNeon = requires (const T& t, size_t i) { t.getNeon (i); };
75
77template <class T>
78concept getAVX = requires (const T& t, size_t i) { t.getAVX (i); };
79
81template <class T>
82concept getSSE = requires (const T& t, size_t i) { t.getSSE (i); };
83
85template <class T>
86concept indexOperator = requires (T& t) { t[size_t()]; };
87
89template <class T>
90concept constIndexOperator = requires (const T& t) { t[size_t()]; };
91
93template <class T, class DstType>
94concept evalNextVectorOpInExpressionChain = requires (const T& t, DstType* d) { t.evalNextVectorOpInExpressionChain (d); } && std::same_as<DstType, typename std::remove_cvref_t<T>::value_type>;
95
97template <class T, class ValueType>
98concept reduceElementWise = requires (const T&t, ValueType& v) { t.reduceElementWise (v, size_t()); };
99
101template <class T, class DstType>
102concept reduceVectorOp = requires (const T& t) { { t.reduceVectorOp() } -> std::same_as<DstType>; };
103
105template <class T, class SrcDstType>
106concept reduceNeonRegisterWise = requires (const T& t, NeonRegister<SrcDstType>& sd, size_t s) { t.reduceNeonRegisterWise (sd, s); };
107
109template <class T, class SrcDstType>
110concept reduceAVXRegisterWise = requires (const T& t, AVXRegister<SrcDstType>& sd, size_t s) { t.reduceAVXRegisterWise (sd, s); };
111
113template <class T, class SrcDstType>
114concept reduceSSERegisterWise = requires (const T& t, SSERegister<SrcDstType>& sd, size_t s) { t.reduceSSERegisterWise (sd, s); };
115
117template <class T>
118concept data = requires (const T& t) { t.data(); };
119
121template <class T, class ElementType>
122concept dataWithElementType = requires (const T& t) { { t.data() } -> std::convertible_to<const ElementType*>; };
123
125template <class T>
126concept size = requires (const T& t, size_t i) { i = t.size(); };
127
129template <class T>
131
133template <class T, class ElementType>
135
137template <class T>
138concept begin = requires (T& t) { *t.begin(); } || requires (const T& t) { *t.begin(); };
139
141template <class T>
142concept end = requires (T& t) { *t.end(); } || requires (const T& t) { *t.begin(); };
143
145template <class T>
146concept resize = requires (T& t, size_t n) { t.resize (n); };
147
149template <class T>
150concept getStorageInfo = requires (const T& t) { t.getStorageInfo(); };
151
153template <class T>
154concept isNotAliased = requires (const T& t, bool r, const void* o) { r = t.isNotAliased (o); };
155
157template <class T, size_t i, class RuntimeArgs>
158concept iterateOverRuntimeArgChain = requires (T& t, const RuntimeArgs& r) { t.template iterateOverRuntimeArgChain<i, RuntimeArgs> (r); };
159
161template <class T, class... Args>
162concept applyRuntimeArgs = requires (T& t, const Args&... args) { t.applyRuntimeArgs (args...); };
163
164} // namespace vctr::has
165
166namespace vctr::detail
167{
174enum PlatformVectorOpPreference
175{
176 dontPreferIfIppAndAccelerateAreAvailable,
177 preferIfIppAndAccelerateAreAvailable
178};
179
180template <PlatformVectorOpPreference pref>
181concept isPreferredVectorOp = (Config::hasIPP && Config::platformApple && (pref == preferIfIppAndAccelerateAreAvailable)) ||
182 ((! (Config::hasIPP && Config::platformApple)) && (pref == dontPreferIfIppAndAccelerateAreAvailable));
183} // namespace vctr::detail
184
185namespace vctr::is
186{
187
188// clang-format off
189
191template <class T>
192concept anyVctr = detail::AnyVctr<std::remove_cvref_t<T>>::value;
193
195template <class T, class V>
196concept anyVctrWithValueType = anyVctr<T> && std::same_as<typename std::remove_cvref_t<T>::value_type, V>;
197
199template <class T>
201
203template <class T, class V>
204concept expressionWithValueType = expression<T> && std::same_as<typename std::remove_cvref_t<T>::value_type, V>;
205
207template <class T>
208concept expressionChainBuilder = detail::IsExpressionChainBuilder<std::remove_cvref_t<T>>::value;
209
211template <class T>
213
215template <class T>
216concept stdArray = detail::IsStdArray<T>::value;
217
219template <class T>
220concept stdSpan = detail::IsStdSpan<T>::value;
221
223template <class T>
224concept view = detail::IsSpan<T>::value || detail::IsStdSpan<T>::value;
225
226//==============================================================================
228template <class T, class DstType>
230
231//==============================================================================
233template <class DstType, class... Sources>
234concept suitableForAccelerateSSEOp = Config::platformApple && Config::archX64 && std::same_as<float, DstType> && (has::getSSE<Sources> && ...);
235
237template <class DstType, class... Sources>
238concept suitableForAccelerateNeonOp = Config::platformApple && Config::archARM && std::same_as<float, DstType> && (has::getNeon<Sources> && ...);
239
241template <class Src, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
243
245template <class Src, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
247
249template <class Src, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
251
253template <class Src, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
255
257template <class Src, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
259
261template <class Src, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
262concept suitableForAccelerateRealFloatVectorReductionOp = detail::isPreferredVectorOp<pref> && Config::platformApple && has::data<Src> && realFloatNumber<DstType>;
263//==============================================================================
265template <class Src, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
267
269template <class Src, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
270concept suitableForIppRealSingedInt32VectorOp = detail::isPreferredVectorOp<pref> && Config::hasIPP && has::evalNextVectorOpInExpressionChain<Src, DstType> && std::same_as<int32_t, DstType>;
271
273template <class Src, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
275
277template <class Src, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
279
281template <class Src, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
283
285template <class Src, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
286concept suitableForIppRealFloatVectorReductionOp = detail::isPreferredVectorOp<pref> && Config::hasIPP && has::data<Src> && realFloatNumber<DstType>;
287
289template <class Src, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
291
292//==============================================================================
294template <class SrcA, class SrcB, class DstType>
295concept suitableForBinaryVectorOp = ((expressionWithEvalVectorOp < SrcA, DstType > && anyVctr < SrcB >) ||
296 (anyVctr<SrcA> && expressionWithEvalVectorOp < SrcB, DstType >) ||
298 std::same_as<typename std::remove_cvref_t<SrcA>::value_type, typename std::remove_cvref_t<SrcB>::value_type>;
299
300//==============================================================================
302template <class SrcA, class SrcB, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
304
306template <class SrcA, class SrcB, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
308
310template <class SrcA, class SrcB, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
312
313//==============================================================================
315template <class SrcA, class SrcB, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
317
319template <class SrcA, class SrcB, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
321
323template <class SrcA, class SrcB, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
325
326//==============================================================================
328template <class T>
330
332template <class T>
334
338template <class T, class ElementType>
339concept suitableInitializerForElementType = std::constructible_from<ElementType, std::remove_cvref_t<T>> && ! expression<T>;
340
344template <class T>
345concept suitableInitializerFunction = std::invocable<T, size_t> && ! std::same_as<void, std::invoke_result_t<T, size_t>>;
346
350template <class T, class ElementType>
351concept suitableInitializerFunctionForElementType = suitableInitializerFunction<T> && std::constructible_from<ElementType, std::invoke_result_t<T, size_t>>;
352
354template <class T, class ElementType>
355concept inputIteratorToConstructValuesOfType = std::input_iterator<T> && std::constructible_from<ElementType, std::iter_value_t<T>>;
356
358template <class T, class ElementType>
359concept contiguousIteratorWithValueTypeSameAs = std::contiguous_iterator<T> && std::same_as<ElementType, std::iter_value_t<T>>;
360
365template <class T>
366concept storageInfo = requires (const T& info, size_t a, bool b) { a = T::memberAlignment; b = info.dataIsSIMDAligned; b = info.hasSIMDExtendedStorage; };
367
368template <class T>
369concept reductionExpression = requires (const T& t, typename T::value_type v, size_t i) { v = T::reductionResultInitValue; t.reduceElementWise (v, i); };
370
371// clang-format on
372
373} // namespace vctr::is
374
375namespace vctr::are
376{
377
379template <class... T>
381
382} // namespace vctr::are
Constrains a pack of types to be no expression templates.
Definition: ContainerAndExpressionConcepts.h:380
Constrains a type to have a function applyRuntimeArgs (const Args&...)
Definition: ContainerAndExpressionConcepts.h:162
Constrains a type to have a member function begin() or begin() const.
Definition: ContainerAndExpressionConcepts.h:138
Constrains a type to have a const operator[] overload taking a size_t argument.
Definition: ContainerAndExpressionConcepts.h:90
Constrains a type to have a member function data() const returning a pointer convertible to const Ele...
Definition: ContainerAndExpressionConcepts.h:122
Constrains a type to have a member function data() const.
Definition: ContainerAndExpressionConcepts.h:118
Constrains a type to have a member function end() or end() const.
Definition: ContainerAndExpressionConcepts.h:142
Constrains a type to have a member function evalNextVectorOpInExpressionChain (value_type*) const.
Definition: ContainerAndExpressionConcepts.h:94
Constrains a type to have a member function getAVX (size_t) const.
Definition: ContainerAndExpressionConcepts.h:78
Constrains a type to have a member function getNeon (size_t) const.
Definition: ContainerAndExpressionConcepts.h:74
Constrains a type to have a member function getSSE (size_t) const.
Definition: ContainerAndExpressionConcepts.h:82
Constrains a type to have a function getStorageInfo() const.
Definition: ContainerAndExpressionConcepts.h:150
Constrains a type to have a non const operator[] overload taking a size_t argument.
Definition: ContainerAndExpressionConcepts.h:86
Constrains a type to have a function isNotAliased (const void*) const.
Definition: ContainerAndExpressionConcepts.h:154
Constrains a type to have a function iterateOverRuntimeArgChain<size_t> (RuntimeArgs)
Definition: ContainerAndExpressionConcepts.h:158
Constrains a type to have a member function reduceAVXRegisterWise (AVXRegister<SrcDstType>&,...
Definition: ContainerAndExpressionConcepts.h:110
Constrains a type to have a member function reduceElementWise() const that takes a ValueType& and siz...
Definition: ContainerAndExpressionConcepts.h:98
Constrains a type to have a member function reduceNeonRegisterWise (NeonRegister<SrcDstType>&,...
Definition: ContainerAndExpressionConcepts.h:106
Constrains a type to have a member function reduceSSERegisterWise (SSERegister<SrcDstType>&,...
Definition: ContainerAndExpressionConcepts.h:114
Constrains a type to have a member function reduceVectorOp() const that returns a DstType value.
Definition: ContainerAndExpressionConcepts.h:102
Constrains a type to have a function resize (size_t).
Definition: ContainerAndExpressionConcepts.h:146
Constrains a type to both, a member function size() const and data() const returning a pointer conver...
Definition: ContainerAndExpressionConcepts.h:134
Constrains a type to both, a member function size() const and data() const.
Definition: ContainerAndExpressionConcepts.h:130
Constrains a type to have a member function size() const.
Definition: ContainerAndExpressionConcepts.h:126
Constrains a type to either be an expression template or any derived instance of VctrBase.
Definition: ContainerAndExpressionConcepts.h:212
Constrains a type to be any derived instance of VctrBase with a certain value_type.
Definition: ContainerAndExpressionConcepts.h:196
Constrains a type to be any derived instance of VctrBase.
Definition: ContainerAndExpressionConcepts.h:192
Constrains a type to represent a complex valued floating point number (e.g.
Definition: NumericTypeConcepts.h:83
Constrains the type to be a contiguous iterator with a value type same as ElementType.
Definition: ContainerAndExpressionConcepts.h:359
Constrains a type to be an expression chain builder.
Definition: ContainerAndExpressionConcepts.h:208
Constrains a type to be an expression template that defines evalNextVectorOpInExpressionChain for Dst...
Definition: ContainerAndExpressionConcepts.h:229
Constrains a type to be an expression template with a certain value_type.
Definition: ContainerAndExpressionConcepts.h:204
Constrains a type to be an expression template.
Definition: ContainerAndExpressionConcepts.h:200
Constrains the type to be an input iterator with a value type suitable to construct an ElementType.
Definition: ContainerAndExpressionConcepts.h:355
Constrains a type to represent a real valued integer number.
Definition: NumericTypeConcepts.h:49
Constrains a type to supply begin and end functions and to not satisfy triviallyCopyableWithDataAndSi...
Definition: ContainerAndExpressionConcepts.h:333
Constrains a type to represent a real valued floating point number.
Definition: NumericTypeConcepts.h:79
Definition: ContainerAndExpressionConcepts.h:369
Constrains a type to be any instance of std::array.
Definition: ContainerAndExpressionConcepts.h:216
Constrains a type to be any instance of std::span.
Definition: ContainerAndExpressionConcepts.h:220
Constrains the type to be a suitable storage info type.
Definition: ContainerAndExpressionConcepts.h:366
A combined concept to check if Apple Accelerate is a suitable option for a complex valued floating po...
Definition: ContainerAndExpressionConcepts.h:307
A combined concept to check if Apple Accelerate is a suitable option for a complex valued floating po...
Definition: ContainerAndExpressionConcepts.h:246
A combined concept to check if Apple Accelerate is a suitable option for a floating point vector oper...
Definition: ContainerAndExpressionConcepts.h:254
A combined concept to check if Apple Accelerate vpf functions are suitable to work on Neon registers.
Definition: ContainerAndExpressionConcepts.h:238
A combined concept to check if Apple Accelerate is a suitable option for a real valued floating point...
Definition: ContainerAndExpressionConcepts.h:303
A combined concept to check if Apple Accelerate is a suitable option for a real valued floating point...
Definition: ContainerAndExpressionConcepts.h:242
A combined concept to check if Apple Accelerate is a suitable option for a floating point vector redu...
Definition: ContainerAndExpressionConcepts.h:262
A combined concept to check if Apple Accelerate is a suitable option for a vector operation that tran...
Definition: ContainerAndExpressionConcepts.h:258
A combined concept to check if Apple Accelerate is a suitable option for a real or complex valued flo...
Definition: ContainerAndExpressionConcepts.h:311
A combined concept to check if Apple Accelerate is a suitable option for a real or complex valued flo...
Definition: ContainerAndExpressionConcepts.h:250
A combined concept to check if Apple Accelerate vpf functions are suitable to work on SSE registers.
Definition: ContainerAndExpressionConcepts.h:234
Constrains two source types to be suitable for a an aliasing-free binary vector operation using platf...
Definition: ContainerAndExpressionConcepts.h:295
A combined concept to check if Intel IPP is a suitable option for a complex valued floating point bin...
Definition: ContainerAndExpressionConcepts.h:320
A combined concept to check if Intel IPP is a suitable option for a complex valued floating point vec...
Definition: ContainerAndExpressionConcepts.h:274
A combined concept to check if Intel IPP is a suitable option for a floating point vector operation t...
Definition: ContainerAndExpressionConcepts.h:282
A combined concept to check if Intel IPP is a suitable option for a real valued floating point binary...
Definition: ContainerAndExpressionConcepts.h:316
A combined concept to check if Intel IPP is a suitable option for a real valued floating point vector...
Definition: ContainerAndExpressionConcepts.h:266
A combined concept to check if Intel IPP is a suitable option for a floating point vector reduction o...
Definition: ContainerAndExpressionConcepts.h:286
A combined concept to check if Intel IPP is a suitable option for a real or complex valued floating p...
Definition: ContainerAndExpressionConcepts.h:324
A combined concept to check if Intel IPP is a suitable option for a real or complex valued floating p...
Definition: ContainerAndExpressionConcepts.h:278
A combined concept to check if Intel IPP is a suitable option for a real or complex floating point ve...
Definition: ContainerAndExpressionConcepts.h:290
A combined concept to check if Intel IPP is a suitable option for a real valued singed int32 vector o...
Definition: ContainerAndExpressionConcepts.h:270
Constrains the type to be suitable for initializing a single element Vctr with a given ElementType,...
Definition: ContainerAndExpressionConcepts.h:339
Constrains the type to be a function suitable for initializing the nth element of a Vctr with a given...
Definition: ContainerAndExpressionConcepts.h:351
Constrains the type to be a function suitable for initializing the nth element of a Vctr,...
Definition: ContainerAndExpressionConcepts.h:345
Constrains a type to supply a data and size function, an index operator and define a trivially copyab...
Definition: ContainerAndExpressionConcepts.h:329
Constrains a type to be trivially copyable.
Definition: GenericConcepts.h:84
Constrains a type to be a view rather than an owning container.
Definition: ContainerAndExpressionConcepts.h:224
typename detail::ValueType< std::remove_cvref_t< T > >::Type ValueType
If T is an expression template, it equals its return type, if it's a type that defines value_type as ...
Definition: Traits.h:201