-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathparallelize.patch
More file actions
179 lines (175 loc) · 8.42 KB
/
Copy pathparallelize.patch
File metadata and controls
179 lines (175 loc) · 8.42 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
diff --git a/Eigen/src/Core/products/GeneralBlockPanelKernel.h b/Eigen/src/Core/products/GeneralBlockPanelKernel.h
index 0a4bec372..377790cff 100644
--- a/Eigen/src/Core/products/GeneralBlockPanelKernel.h
+++ b/Eigen/src/Core/products/GeneralBlockPanelKernel.h
@@ -1581,22 +1581,24 @@ EIGEN_DONT_INLINE void gebp_kernel<LhsScalar, RhsScalar, Index, DataMapper, mr,
for (Index i1 = 0; i1 < peeled_mc3; i1 += actual_panel_rows) {
const Index actual_panel_end = (std::min)(i1 + actual_panel_rows, peeled_mc3);
EIGEN_IF_CONSTEXPR (nr >= 8) {
- for (Index j2 = 0; j2 < packet_cols8; j2 += 8) {
+ tbb::parallel_for(Index(0), packet_cols8 / 8, [&](Index j2) {
+ j2 *= 8;
for (Index i = i1; i < actual_panel_end; i += 3 * LhsProgress) {
micro_panel(fix<3>, fix<8>, traits, i, j2);
}
- }
+ });
}
- for (Index j2 = packet_cols8; j2 < packet_cols4; j2 += 4) {
+ tbb::parallel_for(packet_cols8 / 4, packet_cols4 / 4, [&](Index j2) {
+ j2 *= 4;
for (Index i = i1; i < actual_panel_end; i += 3 * LhsProgress) {
micro_panel(fix<3>, fix<4>, traits, i, j2);
}
- }
- for (Index j2 = packet_cols4; j2 < cols; j2++) {
+ });
+ tbb::parallel_for(packet_cols4, cols, [&](Index j2) {
for (Index i = i1; i < actual_panel_end; i += 3 * LhsProgress) {
micro_panel(fix<3>, fix<1>, traits, i, j2);
}
- }
+ });
}
}
@@ -1612,22 +1614,24 @@ EIGEN_DONT_INLINE void gebp_kernel<LhsScalar, RhsScalar, Index, DataMapper, mr,
for (Index i1 = peeled_mc3; i1 < peeled_mc2; i1 += actual_panel_rows) {
Index actual_panel_end = (std::min)(i1 + actual_panel_rows, peeled_mc2);
EIGEN_IF_CONSTEXPR (nr >= 8) {
- for (Index j2 = 0; j2 < packet_cols8; j2 += 8) {
+ tbb::parallel_for(Index(0), packet_cols8 / 8, [&](Index j2) {
+ j2 *= 8;
for (Index i = i1; i < actual_panel_end; i += 2 * LhsProgress) {
micro_panel(fix<2>, fix<8>, traits, i, j2);
}
- }
+ });
}
- for (Index j2 = packet_cols8; j2 < packet_cols4; j2 += 4) {
+ tbb::parallel_for(packet_cols8 / 4, packet_cols4 / 4, [&](Index j2) {
+ j2 *= 4;
for (Index i = i1; i < actual_panel_end; i += 2 * LhsProgress) {
micro_panel(fix<2>, fix<4>, traits, i, j2);
}
- }
- for (Index j2 = packet_cols4; j2 < cols; j2++) {
+ });
+ tbb::parallel_for(packet_cols4, cols, [&](Index j2) {
for (Index i = i1; i < actual_panel_end; i += 2 * LhsProgress) {
micro_panel(fix<2>, fix<1>, traits, i, j2);
}
- }
+ });
}
}
@@ -1635,16 +1639,16 @@ EIGEN_DONT_INLINE void gebp_kernel<LhsScalar, RhsScalar, Index, DataMapper, mr,
EIGEN_IF_CONSTEXPR (mr >= 1 * Traits::LhsProgress) {
for (Index i = peeled_mc2; i < peeled_mc1; i += LhsProgress) {
EIGEN_IF_CONSTEXPR (nr >= 8) {
- for (Index j2 = 0; j2 < packet_cols8; j2 += 8) {
+ tbb::parallel_for(Index(0), packet_cols8 / 8, [&](Index j2) {
+ j2 *= 8;
micro_panel(fix<1>, fix<8>, traits, i, j2);
- }
+ });
}
- for (Index j2 = packet_cols8; j2 < packet_cols4; j2 += 4) {
+ tbb::parallel_for(packet_cols8 / 4, packet_cols4 / 4, [&](Index j2) {
+ j2 *= 4;
micro_panel(fix<1>, fix<4>, traits, i, j2);
- }
- for (Index j2 = packet_cols4; j2 < cols; j2++) {
- micro_panel(fix<1>, fix<1>, traits, i, j2);
- }
+ });
+ tbb::parallel_for(packet_cols4, cols, [&](Index j2) { micro_panel(fix<1>, fix<1>, traits, i, j2); });
}
}
diff --git a/Eigen/src/Core/products/GeneralMatrixVector.h b/Eigen/src/Core/products/GeneralMatrixVector.h
index ef8bc0fd8..c2b5ef6d9 100644
--- a/Eigen/src/Core/products/GeneralMatrixVector.h
+++ b/Eigen/src/Core/products/GeneralMatrixVector.h
@@ -225,7 +225,21 @@ general_matrix_vector_product<Index, LhsScalar, LhsMapper, ColMajor, ConjugateLh
for (Index j2 = 0; j2 < cols; j2 += block_cols) {
Index jend = numext::mini(j2 + block_cols, cols);
Index i = 0;
- for (; i < n8; i += ResPacketSize * 8) process_rows<8>(i, j2, jend, lhs, rhs, res, palpha, pcj);
+ for (; i < n8; i += ResPacketSize * 8)
+ for (auto x = 0; x < 8; ++x) {
+ const auto offset = i + ResPacketSize * x;
+ pstoreu(res + offset, pmadd(tbb::parallel_deterministic_reduce(
+ tbb::blocked_range<Index>(j2, jend), pzero(ResPacket{}),
+ [&](const tbb::blocked_range<Index>& r, ResPacket running_total) {
+ for (auto j = r.begin(); j < r.end(); ++j)
+ running_total += pcj.pmul(
+ lhs.template load<LhsPacket, LhsAlignment>(i + LhsPacketSize * x, j),
+ pset1<RhsPacket>(rhs(j, 0)));
+ return running_total;
+ },
+ std::plus<>()),
+ palpha, ploadu<ResPacket>(res + offset)));
+ }
if (i < n4) {
process_rows<4>(i, j2, jend, lhs, rhs, res, palpha, pcj);
i += ResPacketSize * 4;
diff --git a/Eigen/src/SVD/BDCSVDImpl.h b/Eigen/src/SVD/BDCSVDImpl.h
index 995b4cac8..98251ff97 100644
--- a/Eigen/src/SVD/BDCSVDImpl.h
+++ b/Eigen/src/SVD/BDCSVDImpl.h
@@ -434,6 +434,14 @@ typename bdcsvd_impl<RealScalar_>::RealScalar bdcsvd_impl<RealScalar_>::secularE
const ConstArrayRef& diag,
const ConstArrayRef& diagShifted,
RealScalar shift) {
+ return tbb::parallel_deterministic_reduce(
+ tbb::blocked_range<Index>(Index(0), col0.size()), RealScalar(1),
+ [&](const tbb::blocked_range<Index>& r, RealScalar running_total) {
+ for (auto i = r.begin(); i < r.end(); ++i)
+ running_total += productOfQuotients(col0(i), diagShifted(i) - mu, col0(i), diag(i) + shift + mu);
+ return running_total;
+ },
+ std::plus<>());
RealScalar res = Literal(1);
for (Index i = 0; i < col0.size(); ++i) {
res += productOfQuotients(col0(i), diagShifted(i) - mu, col0(i), diag(i) + shift + mu);
@@ -688,6 +696,8 @@ template <typename RealScalar_>
void bdcsvd_impl<RealScalar_>::computeSingVecs(const ArrayRef& zhat, const ArrayRef& diag, const IndicesRef& perm,
const VectorType& singVals, const ArrayRef& shifts, const ArrayRef& mus,
MatrixXr& U, MatrixXr& V) {
+ static tbb::affinity_partitioner ap;
+
Index n = zhat.size();
Index m = perm.size();
@@ -701,18 +711,21 @@ void bdcsvd_impl<RealScalar_>::computeSingVecs(const ArrayRef& zhat, const Array
const RealScalar shift = shifts(k);
const RealScalar mu = mus(k);
const RealScalar singularValue = singVals(k);
- for (Index l = 0; l < m; ++l) {
- Index i = perm(l);
- const RealScalar diagonal = diag(i);
- const RealScalar z = zhat(i);
- RealScalar diff = diagonal - shift;
- EIGEN_OPTIMIZATION_BARRIER(diff)
- diff -= mu;
- EIGEN_OPTIMIZATION_BARRIER(diff)
- const RealScalar sum = diagonal + singularValue;
- U(i, k) = sequentialQuotient(z, diff, sum);
- if (m_compV && l > 0) V(i, k) = sequentialQuotient(diagonal * z, diff, sum);
- }
+ tbb::parallel_for(
+ Index(0), m,
+ [&](const Index l) {
+ Index i = perm(l);
+ const RealScalar diagonal = diag(i);
+ const RealScalar z = zhat(i);
+ RealScalar diff = diagonal - shift;
+ EIGEN_OPTIMIZATION_BARRIER(diff)
+ diff -= mu;
+ EIGEN_OPTIMIZATION_BARRIER(diff)
+ const RealScalar sum = diagonal + singularValue;
+ U(i, k) = sequentialQuotient(z, diff, sum);
+ if (m_compV && l > 0) V(i, k) = sequentialQuotient(diagonal * z, diff, sum);
+ },
+ ap);
U(n, k) = Literal(0);
// LAPACK's xLASD3 normalizes these vectors with xNRM2. Use the scaled
// normalization unconditionally: under -ffast-math, compilers may