-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdot.c
More file actions
117 lines (94 loc) · 2.8 KB
/
Copy pathdot.c
File metadata and controls
117 lines (94 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//------------------------------------------------------
//
// Copyright 2023 Mark Seminatore. All rights reserved.
//------------------------------------------------------
#include "cblas.h"
#include "cblas_simd.h"
//------------------------------------------------------
// Level-1 single-precision vector dot product
//------------------------------------------------------
float cblas_sdot(CBLAS_INDEX n, float *x, CBLAS_INDEX incx, float *y, CBLAS_INDEX incy)
{
float sum = 0.0f;
CBLAS_VALIDATE_VEC2(n, x, incx, y, incy, sum);
CBLAS_STATS_START();
#if defined(MT_ENABLED)
int mt_used = (n > CBLAS_MT_DOT && cblas_get_num_threads() > 1) ? 1 : 0;
#else
int mt_used = 0;
#endif
kernel_function kernel = blas_kernels.sdot_k;
// special case kernel for no increments
if (incx == 1 && incy == 1)
{
kernel = blas_kernels.sdot_k_noinc;
}
if (mt_used)
{
float thread_partial_sums[MAX_THREADS];
cblas_level1_exec_result(sizeof(float), kernel, n, x, incx, y, incy, thread_partial_sums, "SDOT");
// accumulate results
CBLAS_INDEX threads = cblas_get_num_threads();
for (CBLAS_INDEX i = 0; i < threads; i++)
{
sum += thread_partial_sums[i];
}
}
else
{
cblas_args_t args;
args.n = n;
args.x = x;
args.incx = incx;
args.y = y;
args.incy = incy;
args.c = ∑
kernel(&args);
}
CBLAS_STATS_END("sdot", n, mt_used);
return sum;
}
//------------------------------------------------------
// Level-1 double-precision vector dot product
//------------------------------------------------------
double cblas_ddot(CBLAS_INDEX n, double *x, CBLAS_INDEX incx, double *y, CBLAS_INDEX incy)
{
double sum = 0.0;
CBLAS_VALIDATE_VEC2(n, x, incx, y, incy, sum);
CBLAS_STATS_START();
#if defined(MT_ENABLED)
int mt_used = (n > CBLAS_MT_DOT && cblas_get_num_threads() > 1) ? 1 : 0;
#else
int mt_used = 0;
#endif
kernel_function kernel = blas_kernels.ddot_k;
// special case kernel for no increments
if (incx == 1 && incy == 1)
{
kernel = blas_kernels.ddot_k_noinc;
}
if (mt_used)
{
double thread_partial_sums[MAX_THREADS];
cblas_level1_exec_result(sizeof(double), kernel, n, x, incx, y, incy, thread_partial_sums, "DDOT");
// accumulate results
CBLAS_INDEX threads = cblas_get_num_threads();
for (CBLAS_INDEX i = 0; i < threads; i++)
{
sum += thread_partial_sums[i];
}
}
else
{
cblas_args_t args;
args.n = n;
args.x = x;
args.incx = incx;
args.y = y;
args.incy = incy;
args.c = ∑
kernel(&args);
}
CBLAS_STATS_END("ddot", n, mt_used);
return sum;
}