-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathparallelize.patch
More file actions
175 lines (171 loc) · 8.08 KB
/
Copy pathparallelize.patch
File metadata and controls
175 lines (171 loc) · 8.08 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
diff --git a/Eigen/src/Core/products/GeneralBlockPanelKernel.h b/Eigen/src/Core/products/GeneralBlockPanelKernel.h
index 84ca39b38..c8a6b5122 100644
--- a/Eigen/src/Core/products/GeneralBlockPanelKernel.h
+++ b/Eigen/src/Core/products/GeneralBlockPanelKernel.h
@@ -1504,22 +1504,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);
}
- }
+ });
}
}
@@ -1535,22 +1537,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);
}
- }
+ });
}
}
@@ -1558,16 +1562,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 2af8d67d6..e141d79b5 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 086cbb188..cf33f6885 100644
--- a/Eigen/src/SVD/BDCSVDImpl.h
+++ b/Eigen/src/SVD/BDCSVDImpl.h
@@ -382,6 +382,16 @@ typename bdcsvd_impl<RealScalar_>::RealScalar bdcsvd_impl<RealScalar_>::secularE
const IndicesRef& perm,
const ArrayRef& diagShifted,
RealScalar shift) {
+ return tbb::parallel_deterministic_reduce(
+ tbb::blocked_range<Index>(Index(0), perm.size()), RealScalar(1),
+ [&](const tbb::blocked_range<Index>& r, RealScalar running_total) {
+ for (auto i = r.begin(); i < r.end(); ++i) {
+ const Index j = perm(i);
+ running_total += (col0(j) / (diagShifted(j) - mu)) * (col0(j) / (diag(j) + shift + mu));
+ }
+ return running_total;
+ },
+ std::plus<>());
Index m = perm.size();
RealScalar res = Literal(1);
for (Index i = 0; i < m; ++i) {
@@ -622,6 +632,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();
@@ -632,15 +644,18 @@ void bdcsvd_impl<RealScalar_>::computeSingVecs(const ArrayRef& zhat, const Array
} else {
U.col(k).setZero();
if (m_compV) V.col(k).setZero();
- for (Index l = 0; l < m; ++l) {
- Index i = perm(l);
- RealScalar diff = diag(i) - shifts(k);
- EIGEN_OPTIMIZATION_BARRIER(diff)
- diff -= mus(k);
- EIGEN_OPTIMIZATION_BARRIER(diff)
- U(i, k) = zhat(i) / diff / ((diag(i) + singVals[k]));
- if (m_compV && l > 0) V(i, k) = diag(i) * zhat(i) / diff / ((diag(i) + singVals[k]));
- }
+ tbb::parallel_for(
+ Index(0), m,
+ [&](const Index l) {
+ Index i = perm(l);
+ RealScalar diff = diag(i) - shifts(k);
+ EIGEN_OPTIMIZATION_BARRIER(diff)
+ diff -= mus(k);
+ EIGEN_OPTIMIZATION_BARRIER(diff)
+ U(i, k) = zhat(i) / diff / ((diag(i) + singVals[k]));
+ if (m_compV && l > 0) V(i, k) = diag(i) * zhat(i) / diff / ((diag(i) + singVals[k]));
+ },
+ ap);
U(n, k) = Literal(0);
// LAPACK's xLASD3 normalizes these vectors with xNRM2. Use the scaled
// normalization unconditionally: under -ffast-math, compilers may