15
15
// limitations under the License.
16
16
// /////////////////////////////////////////////////////////////////////
17
17
18
+ #include < numeric> // for std::inner_product
18
19
#include " simddetect.h"
19
20
#include " dotproduct.h"
20
21
#include " dotproductavx.h"
@@ -69,6 +70,11 @@ static double DotProductGeneric(const double* u, const double* v, int n) {
69
70
return total;
70
71
}
71
72
73
+ // Compute dot product using std::inner_product.
74
+ static double DotProductStdInnerProduct (const double * u, const double * v, int n) {
75
+ return std::inner_product (u, u + n, v, 0.0 );
76
+ }
77
+
72
78
static void SetDotProduct (DotProductFunction f, const IntSimdMatrix* m = nullptr ) {
73
79
DotProduct = f;
74
80
IntSimdMatrix::intSimdMatrix = m;
@@ -185,6 +191,10 @@ void SIMDDetect::Update() {
185
191
SetDotProduct (DotProductSSE, &IntSimdMatrix::intSimdMatrixSSE);
186
192
dotproduct_method = " sse" ;
187
193
#endif
194
+ } else if (!strcmp (dotproduct.string (), " std::inner_product" )) {
195
+ // std::inner_product selected by config variable.
196
+ SetDotProduct (DotProductStdInnerProduct);
197
+ dotproduct_method = " std::inner_product" ;
188
198
} else {
189
199
// Unsupported value of config variable.
190
200
tprintf (" Warning, ignoring unsupported config variable value: dotproduct=%s\n " ,
@@ -196,7 +206,7 @@ void SIMDDetect::Update() {
196
206
#if defined(SSE4_1)
197
207
" sse"
198
208
#endif
199
- " .\n " );
209
+ " std::inner_product .\n " );
200
210
}
201
211
202
212
dotproduct.set_value (dotproduct_method);
0 commit comments