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>
34struct AnyVctr<OwnedVector<T>> : std::true_type {};
35
36template <class T, size_t e, size_t s>
37struct AnyVctr<Array<T, e, s>> : std::true_type {};
38
39template <class T, size_t e>
40struct AnyVctr<OwnedArray<T, e>> : std::true_type {};
41
42template <class T, size_t n, class S>
43struct AnyVctr<Span<T, n, S>> : std::true_type {};
44
45template <class E, class S, size_t e, class I>
46struct AnyVctr<VctrBase<E, S, e, I>> : std::true_type {};
47
48template <class T>
49struct IsSpan : std::false_type {};
50
51template <class T, size_t n, class S>
52struct IsSpan<Span<T, n, S>> : std::true_type {};
53
54template <class T>
55struct IsStdArray : std::false_type {};
56
57template <class T, size_t e>
58struct IsStdArray<std::array<T, e>> : std::true_type {};
59
60template <class T>
61struct IsStdSpan : std::false_type {};
62
63template <class T, size_t e>
64struct IsStdSpan<std::span<T, e>> : std::true_type {};
65
66template <class T>
67struct IsExpressionChainBuilder : std::false_type {};
68
69template <template <size_t, class...> class ExpressionType, class RuntimeArgs, class... AdditionalParameters>
70struct IsExpressionChainBuilder<ExpressionChainBuilderWithRuntimeArgs<ExpressionType, RuntimeArgs, AdditionalParameters...>> : std::true_type {};
71// clang-format on
72
73} // namespace vctr::detail
74
75namespace vctr::has
76{
77
79template <class T>
80concept prepareNeonEvaluation = requires (const T& t) { t.prepareNeonEvaluation(); };
81
83template <class T>
84concept getNeon = requires (const T& t, size_t i) { t.getNeon (i); };
85
87template <class T>
88concept prepareAVXEvaluation = requires (const T& t) { t.prepareAVXEvaluation(); };
89
91template <class T>
92concept getAVX = requires (const T& t, size_t i) { t.getAVX (i); };
93
95template <class T>
96concept prepareSSEEvaluation = requires (const T& t) { t.prepareSSEEvaluation(); };
97
99template <class T>
100concept getSSE = requires (const T& t, size_t i) { t.getSSE (i); };
101
103template <class T>
104concept indexOperator = requires (T& t) { t[size_t()]; };
105
107template <class T>
108concept constIndexOperator = requires (const T& t) { t[size_t()]; };
109
111template <class T, class DstType>
112concept evalNextVectorOpInExpressionChain = requires (const T& t, DstType* d) { t.evalNextVectorOpInExpressionChain (d); } && std::same_as<DstType, typename std::remove_cvref_t<T>::value_type>;
113
115template <class T, class ValueType>
116concept reduceElementWise = requires (const T&t, ValueType& v) { t.reduceElementWise (v, size_t()); };
117
119template <class T, class DstType>
120concept reduceVectorOp = requires (const T& t) { { t.reduceVectorOp() } -> std::same_as<DstType>; };
121
123template <class T, class SrcDstType>
124concept reduceNeonRegisterWise = requires (const T& t, NeonRegister<SrcDstType>& sd, size_t s) { t.reduceNeonRegisterWise (sd, s); };
125
127template <class T, class SrcDstType>
128concept reduceAVXRegisterWise = requires (const T& t, AVXRegister<SrcDstType>& sd, size_t s) { t.reduceAVXRegisterWise (sd, s); };
129
131template <class T, class SrcDstType>
132concept reduceSSERegisterWise = requires (const T& t, SSERegister<SrcDstType>& sd, size_t s) { t.reduceSSERegisterWise (sd, s); };
133
135template <class T>
136concept data = requires (const T& t) { t.data(); };
137
139template <class T, class ElementType>
140concept dataWithElementType = requires (const T& t) { { t.data() } -> std::convertible_to<const ElementType*>; };
141
143template <class T>
144concept size = requires (const T& t, size_t i) { i = t.size(); };
145
147template <class T>
149
151template <class T, class ElementType>
153
155template <class T>
156concept begin = requires (T& t) { *t.begin(); } || requires (const T& t) { *t.begin(); };
157
159template <class T>
160concept end = requires (T& t) { *t.end(); } || requires (const T& t) { *t.begin(); };
161
163template <class T>
164concept resize = requires (T& t, size_t n) { t.resize (n); };
165
167template <class T>
168concept getStorageInfo = requires (const T& t) { t.getStorageInfo(); };
169
171template <class T>
172concept isNotAliased = requires (const T& t, bool r, const void* o) { r = t.isNotAliased (o); };
173
175template <class T, size_t i, class RuntimeArgs>
176concept iterateOverRuntimeArgChain = requires (T& t, const RuntimeArgs& r) { t.template iterateOverRuntimeArgChain<i, RuntimeArgs> (r); };
177
179template <class T, class... Args>
180concept applyRuntimeArgs = requires (T& t, const Args&... args) { t.applyRuntimeArgs (args...); };
181
182} // namespace vctr::has
183
184namespace vctr::detail
185{
194enum PlatformVectorOpPreference
195{
196 dontPreferIfIppAndAccelerateAreAvailable,
197 preferIfIppAndAccelerateAreAvailable
198};
199
230template <PlatformVectorOpPreference pref>
231concept isPreferredVectorOp = (! (Config::hasIPP && Config::platformApple)) || (pref == preferIfIppAndAccelerateAreAvailable);
232} // namespace vctr::detail
233
234namespace vctr::is
235{
236
237// clang-format off
238
240template <class T>
241concept anyVctr = detail::AnyVctr<std::remove_cvref_t<T>>::value;
242
244template <class T, class V>
245concept anyVctrWithValueType = anyVctr<T> && std::same_as<typename std::remove_cvref_t<T>::value_type, V>;
246
248template <class T>
250
252template <class T, class V>
253concept expressionWithValueType = expression<T> && std::same_as<typename std::remove_cvref_t<T>::value_type, V>;
254
256template <class T>
257concept expressionChainBuilder = detail::IsExpressionChainBuilder<std::remove_cvref_t<T>>::value;
258
260template <class T>
262
264template <class T>
265concept stdArray = detail::IsStdArray<T>::value;
266
268template <class T>
269concept stdSpan = detail::IsStdSpan<T>::value;
270
272template <class T>
273concept view = detail::IsSpan<T>::value || detail::IsStdSpan<T>::value;
274
275//==============================================================================
277template <class T, class DstType>
279
280//==============================================================================
282template <class DstType, class... Sources>
283concept suitableForAccelerateSSEOp = Config::platformApple && Config::archX64 && std::same_as<float, DstType> && (has::getSSE<Sources> && ...);
284
286template <class DstType, class... Sources>
287concept suitableForAccelerateNeonOp = Config::platformApple && Config::archARM && std::same_as<float, DstType> && (has::getNeon<Sources> && ...);
288
290template <class Src, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
292
294template <class Src, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
296
298template <class Src, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
300
302template <class Src, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
304
306template <class Src, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
308
310template <class Src, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
311concept suitableForAccelerateRealFloatVectorReductionOp = detail::isPreferredVectorOp<pref> && Config::platformApple && has::data<Src> && realFloatNumber<DstType>;
312//==============================================================================
314template <class Src, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
316
318template <class Src, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
319concept suitableForIppRealSingedInt32VectorOp = detail::isPreferredVectorOp<pref> && Config::hasIPP && has::evalNextVectorOpInExpressionChain<Src, DstType> && std::same_as<int32_t, DstType>;
320
322template <class Src, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
324
326template <class Src, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
328
330template <class Src, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
332
334template <class Src, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
335concept suitableForIppRealFloatVectorReductionOp = detail::isPreferredVectorOp<pref> && Config::hasIPP && has::data<Src> && realFloatNumber<DstType>;
336
338template <class Src, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
340
341//==============================================================================
343template <class SrcA, class SrcB, class DstType>
344concept suitableForBinaryVectorOp = ((expressionWithEvalVectorOp < SrcA, DstType > && anyVctr < SrcB >) ||
345 (anyVctr<SrcA> && expressionWithEvalVectorOp < SrcB, DstType >) ||
347 std::same_as<typename std::remove_cvref_t<SrcA>::value_type, typename std::remove_cvref_t<SrcB>::value_type>;
348
349//==============================================================================
351template <class SrcA, class SrcB, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
353
355template <class SrcA, class SrcB, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
357
359template <class SrcA, class SrcB, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
361
362//==============================================================================
364template <class SrcA, class SrcB, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
366
368template <class SrcA, class SrcB, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
370
372template <class SrcA, class SrcB, class DstType, detail::PlatformVectorOpPreference pref = detail::preferIfIppAndAccelerateAreAvailable>
374
376template <class ValueType>
377concept suitableForVfpOrSvmlSSERegisterFunction = Config::archX64 && ((Config::platformApple && std::same_as<float, ValueType>) || (Config::hasSVML && realFloatNumber<ValueType>));
378
379//==============================================================================
381template <class T>
383
385template <class T>
387
391template <class T, class ElementType>
392concept suitableInitializerForElementType = std::constructible_from<ElementType, std::remove_cvref_t<T>> && ! expression<T>;
393
397template <class T>
398concept suitableInitializerFunction = std::invocable<T, size_t> && ! std::same_as<void, std::invoke_result_t<T, size_t>>;
399
403template <class T, class ElementType>
404concept suitableInitializerFunctionForElementType = suitableInitializerFunction<T> && std::constructible_from<ElementType, std::invoke_result_t<T, size_t>>;
405
407template <class T, class ElementType>
408concept inputIteratorToConstructValuesOfType = std::input_iterator<T> && std::constructible_from<ElementType, std::iter_value_t<T>>;
409
411template <class T, class ElementType>
412concept contiguousIteratorWithValueTypeSameAs = std::contiguous_iterator<T> && std::same_as<ElementType, std::iter_value_t<T>>;
413
418template <class T>
419concept storageInfo = requires (const T& info, size_t a, bool b) { a = T::memberAlignment; b = info.dataIsSIMDAligned; b = info.hasSIMDExtendedStorage; };
420
421template <class T>
422concept reductionExpression = requires (const T& t, typename T::value_type v, size_t i) { v = T::reductionResultInitValue; t.reduceElementWise (v, i); };
423
424// clang-format on
425
426} // namespace vctr::is
427
428namespace vctr::are
429{
430
432template <class... T>
434
435} // namespace vctr::are
Constrains a pack of types to be no expression templates.
Definition: ContainerAndExpressionConcepts.h:433
Constrains a type to have a function applyRuntimeArgs (const Args&...)
Definition: ContainerAndExpressionConcepts.h:180
Constrains a type to have a member function begin() or begin() const.
Definition: ContainerAndExpressionConcepts.h:156
Constrains a type to have a const operator[] overload taking a size_t argument.
Definition: ContainerAndExpressionConcepts.h:108
Constrains a type to have a member function data() const returning a pointer convertible to const Ele...
Definition: ContainerAndExpressionConcepts.h:140
Constrains a type to have a member function data() const.
Definition: ContainerAndExpressionConcepts.h:136
Constrains a type to have a member function end() or end() const.
Definition: ContainerAndExpressionConcepts.h:160
Constrains a type to have a member function evalNextVectorOpInExpressionChain (value_type*) const.
Definition: ContainerAndExpressionConcepts.h:112
Constrains a type to have a member function getAVX (size_t) const.
Definition: ContainerAndExpressionConcepts.h:92
Constrains a type to have a member function getNeon (size_t) const.
Definition: ContainerAndExpressionConcepts.h:84
Constrains a type to have a member function getSSE (size_t) const.
Definition: ContainerAndExpressionConcepts.h:100
Constrains a type to have a function getStorageInfo() const.
Definition: ContainerAndExpressionConcepts.h:168
Constrains a type to have a non const operator[] overload taking a size_t argument.
Definition: ContainerAndExpressionConcepts.h:104
Constrains a type to have a function isNotAliased (const void*) const.
Definition: ContainerAndExpressionConcepts.h:172
Constrains a type to have a function iterateOverRuntimeArgChain<size_t> (RuntimeArgs)
Definition: ContainerAndExpressionConcepts.h:176
Constrains a type to have a member function prepareAVXEvaluation() const.
Definition: ContainerAndExpressionConcepts.h:88
Constrains a type to have a member function prepareNeonEvaluation() const.
Definition: ContainerAndExpressionConcepts.h:80
Constrains a type to have a member function prepareSSEEvaluation() const.
Definition: ContainerAndExpressionConcepts.h:96
Constrains a type to have a member function reduceAVXRegisterWise (AVXRegister<SrcDstType>&,...
Definition: ContainerAndExpressionConcepts.h:128
Constrains a type to have a member function reduceElementWise() const that takes a ValueType& and siz...
Definition: ContainerAndExpressionConcepts.h:116
Constrains a type to have a member function reduceNeonRegisterWise (NeonRegister<SrcDstType>&,...
Definition: ContainerAndExpressionConcepts.h:124
Constrains a type to have a member function reduceSSERegisterWise (SSERegister<SrcDstType>&,...
Definition: ContainerAndExpressionConcepts.h:132
Constrains a type to have a member function reduceVectorOp() const that returns a DstType value.
Definition: ContainerAndExpressionConcepts.h:120
Constrains a type to have a function resize (size_t).
Definition: ContainerAndExpressionConcepts.h:164
Constrains a type to both, a member function size() const and data() const returning a pointer conver...
Definition: ContainerAndExpressionConcepts.h:152
Constrains a type to both, a member function size() const and data() const.
Definition: ContainerAndExpressionConcepts.h:148
Constrains a type to have a member function size() const.
Definition: ContainerAndExpressionConcepts.h:144
Constrains a type to either be an expression template or any derived instance of VctrBase.
Definition: ContainerAndExpressionConcepts.h:261
Constrains a type to be any derived instance of VctrBase with a certain value_type.
Definition: ContainerAndExpressionConcepts.h:245
Constrains a type to be any derived instance of VctrBase.
Definition: ContainerAndExpressionConcepts.h:241
Constrains a type to represent a complex valued floating point number (e.g.
Definition: NumericTypeConcepts.h:87
Constrains the type to be a contiguous iterator with a value type same as ElementType.
Definition: ContainerAndExpressionConcepts.h:412
Constrains a type to be an expression chain builder.
Definition: ContainerAndExpressionConcepts.h:257
Constrains a type to be an expression template that defines evalNextVectorOpInExpressionChain for Dst...
Definition: ContainerAndExpressionConcepts.h:278
Constrains a type to be an expression template with a certain value_type.
Definition: ContainerAndExpressionConcepts.h:253
Constrains a type to be an expression template.
Definition: ContainerAndExpressionConcepts.h:249
Constrains the type to be an input iterator with a value type suitable to construct an ElementType.
Definition: ContainerAndExpressionConcepts.h:408
Constrains a type to represent a real valued integer number.
Definition: NumericTypeConcepts.h:53
Constrains a type to supply begin and end functions and to not satisfy triviallyCopyableWithDataAndSi...
Definition: ContainerAndExpressionConcepts.h:386
Constrains a type to represent a real valued floating point number.
Definition: NumericTypeConcepts.h:83
Definition: ContainerAndExpressionConcepts.h:422
Constrains a type to be any instance of std::array.
Definition: ContainerAndExpressionConcepts.h:265
Constrains a type to be any instance of std::span.
Definition: ContainerAndExpressionConcepts.h:269
Constrains the type to be a suitable storage info type.
Definition: ContainerAndExpressionConcepts.h:419
A combined concept to check if Apple Accelerate is a suitable option for a complex valued floating po...
Definition: ContainerAndExpressionConcepts.h:356
A combined concept to check if Apple Accelerate is a suitable option for a complex valued floating po...
Definition: ContainerAndExpressionConcepts.h:295
A combined concept to check if Apple Accelerate is a suitable option for a floating point vector oper...
Definition: ContainerAndExpressionConcepts.h:303
A combined concept to check if Apple Accelerate vpf functions are suitable to work on Neon registers.
Definition: ContainerAndExpressionConcepts.h:287
A combined concept to check if Apple Accelerate is a suitable option for a real valued floating point...
Definition: ContainerAndExpressionConcepts.h:352
A combined concept to check if Apple Accelerate is a suitable option for a real valued floating point...
Definition: ContainerAndExpressionConcepts.h:291
A combined concept to check if Apple Accelerate is a suitable option for a floating point vector redu...
Definition: ContainerAndExpressionConcepts.h:311
A combined concept to check if Apple Accelerate is a suitable option for a vector operation that tran...
Definition: ContainerAndExpressionConcepts.h:307
A combined concept to check if Apple Accelerate is a suitable option for a real or complex valued flo...
Definition: ContainerAndExpressionConcepts.h:360
A combined concept to check if Apple Accelerate is a suitable option for a real or complex valued flo...
Definition: ContainerAndExpressionConcepts.h:299
A combined concept to check if Apple Accelerate vpf functions are suitable to work on SSE registers.
Definition: ContainerAndExpressionConcepts.h:283
Constrains two source types to be suitable for a an aliasing-free binary vector operation using platf...
Definition: ContainerAndExpressionConcepts.h:344
A combined concept to check if Intel IPP is a suitable option for a complex valued floating point bin...
Definition: ContainerAndExpressionConcepts.h:369
A combined concept to check if Intel IPP is a suitable option for a complex valued floating point vec...
Definition: ContainerAndExpressionConcepts.h:323
A combined concept to check if Intel IPP is a suitable option for a floating point vector operation t...
Definition: ContainerAndExpressionConcepts.h:331
A combined concept to check if Intel IPP is a suitable option for a real valued floating point binary...
Definition: ContainerAndExpressionConcepts.h:365
A combined concept to check if Intel IPP is a suitable option for a real valued floating point vector...
Definition: ContainerAndExpressionConcepts.h:315
A combined concept to check if Intel IPP is a suitable option for a floating point vector reduction o...
Definition: ContainerAndExpressionConcepts.h:335
A combined concept to check if Intel IPP is a suitable option for a real or complex valued floating p...
Definition: ContainerAndExpressionConcepts.h:373
A combined concept to check if Intel IPP is a suitable option for a real or complex valued floating p...
Definition: ContainerAndExpressionConcepts.h:327
A combined concept to check if Intel IPP is a suitable option for a real or complex floating point ve...
Definition: ContainerAndExpressionConcepts.h:339
A combined concept to check if Intel IPP is a suitable option for a real valued singed int32 vector o...
Definition: ContainerAndExpressionConcepts.h:319
A combined concept if one of the similar named Apple Accelerate VFP or Intel SVML backed member funct...
Definition: ContainerAndExpressionConcepts.h:377
Constrains the type to be suitable for initializing a single element Vctr with a given ElementType,...
Definition: ContainerAndExpressionConcepts.h:392
Constrains the type to be a function suitable for initializing the nth element of a Vctr with a given...
Definition: ContainerAndExpressionConcepts.h:404
Constrains the type to be a function suitable for initializing the nth element of a Vctr,...
Definition: ContainerAndExpressionConcepts.h:398
Constrains a type to supply a data and size function, an index operator and define a trivially copyab...
Definition: ContainerAndExpressionConcepts.h:382
Constrains a type to be trivially copyable.
Definition: GenericConcepts.h:78
Constrains a type to be a view rather than an owning container.
Definition: ContainerAndExpressionConcepts.h:273
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