Commit 4eb757c
authored
Clarify Kahan condition (microsoft#28790)
This pull request refactors the logic for determining when to use Kahan
compensated summation in reduction aggregators for integer types in
`onnxruntime/core/providers/cpu/reduction/reduction_ops.h`. Instead of
relying on the size of the type, a new type trait, `kReduceUseKahan<T>`,
is introduced to explicitly indicate when Kahan summation should be used
(currently for `int64_t` and `uint64_t`). This improves code clarity and
maintainability by making the condition more explicit and less
error-prone.
**Refactoring of Kahan Summation Condition:**
* Introduced the `kReduceUseKahan<T>` constexpr variable to indicate
when Kahan compensated summation should be used, replacing the previous
`sizeof(T) >= sizeof(int64_t)` checks. This trait currently evaluates to
true for `int64_t` and `uint64_t` types.
* Updated all reduction aggregator classes (`ReduceAggregatorSum`,
`ReduceAggregatorSumSquare`, `ReduceAggregatorMean`,
`ReduceAggregatorL1`, `ReduceAggregatorL2`, `ReduceAggregatorLogSum`) to
use `kReduceUseKahan<T>` instead of the previous size-based condition
when deciding to apply Kahan summation in both `aggall` and `update`
methods.
[[1]](diffhunk://#diff-ca0c9224442a3c46251b0fb7326aacc1469bdee20ab409b930556f439d560015L232-R239)
[[2]](diffhunk://#diff-ca0c9224442a3c46251b0fb7326aacc1469bdee20ab409b930556f439d560015L247-R254)
[[3]](diffhunk://#diff-ca0c9224442a3c46251b0fb7326aacc1469bdee20ab409b930556f439d560015L457-R464)
[[4]](diffhunk://#diff-ca0c9224442a3c46251b0fb7326aacc1469bdee20ab409b930556f439d560015L484-R491)
[[5]](diffhunk://#diff-ca0c9224442a3c46251b0fb7326aacc1469bdee20ab409b930556f439d560015L518-R525)
[[6]](diffhunk://#diff-ca0c9224442a3c46251b0fb7326aacc1469bdee20ab409b930556f439d560015L1164-R1171)
[[7]](diffhunk://#diff-ca0c9224442a3c46251b0fb7326aacc1469bdee20ab409b930556f439d560015L1188-R1195)
[[8]](diffhunk://#diff-ca0c9224442a3c46251b0fb7326aacc1469bdee20ab409b930556f439d560015L1248-R1255)
[[9]](diffhunk://#diff-ca0c9224442a3c46251b0fb7326aacc1469bdee20ab409b930556f439d560015L1276-R1283)
[[10]](diffhunk://#diff-ca0c9224442a3c46251b0fb7326aacc1469bdee20ab409b930556f439d560015L1316-R1323)
[[11]](diffhunk://#diff-ca0c9224442a3c46251b0fb7326aacc1469bdee20ab409b930556f439d560015L1347-R1354)1 parent d43a48b commit 4eb757c
1 file changed
Lines changed: 18 additions & 11 deletions
Lines changed: 18 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
154 | 154 | | |
155 | 155 | | |
156 | 156 | | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
157 | 164 | | |
158 | 165 | | |
159 | 166 | | |
| |||
229 | 236 | | |
230 | 237 | | |
231 | 238 | | |
232 | | - | |
| 239 | + | |
233 | 240 | | |
234 | 241 | | |
235 | 242 | | |
| |||
244 | 251 | | |
245 | 252 | | |
246 | 253 | | |
247 | | - | |
| 254 | + | |
248 | 255 | | |
249 | 256 | | |
250 | 257 | | |
| |||
454 | 461 | | |
455 | 462 | | |
456 | 463 | | |
457 | | - | |
| 464 | + | |
458 | 465 | | |
459 | 466 | | |
460 | 467 | | |
| |||
481 | 488 | | |
482 | 489 | | |
483 | 490 | | |
484 | | - | |
| 491 | + | |
485 | 492 | | |
486 | 493 | | |
487 | 494 | | |
| |||
515 | 522 | | |
516 | 523 | | |
517 | 524 | | |
518 | | - | |
| 525 | + | |
519 | 526 | | |
520 | 527 | | |
521 | 528 | | |
| |||
1161 | 1168 | | |
1162 | 1169 | | |
1163 | 1170 | | |
1164 | | - | |
| 1171 | + | |
1165 | 1172 | | |
1166 | 1173 | | |
1167 | 1174 | | |
| |||
1185 | 1192 | | |
1186 | 1193 | | |
1187 | 1194 | | |
1188 | | - | |
| 1195 | + | |
1189 | 1196 | | |
1190 | 1197 | | |
1191 | 1198 | | |
| |||
1245 | 1252 | | |
1246 | 1253 | | |
1247 | 1254 | | |
1248 | | - | |
| 1255 | + | |
1249 | 1256 | | |
1250 | 1257 | | |
1251 | 1258 | | |
| |||
1273 | 1280 | | |
1274 | 1281 | | |
1275 | 1282 | | |
1276 | | - | |
| 1283 | + | |
1277 | 1284 | | |
1278 | 1285 | | |
1279 | 1286 | | |
| |||
1313 | 1320 | | |
1314 | 1321 | | |
1315 | 1322 | | |
1316 | | - | |
| 1323 | + | |
1317 | 1324 | | |
1318 | 1325 | | |
1319 | 1326 | | |
| |||
1344 | 1351 | | |
1345 | 1352 | | |
1346 | 1353 | | |
1347 | | - | |
| 1354 | + | |
1348 | 1355 | | |
1349 | 1356 | | |
1350 | 1357 | | |
| |||
0 commit comments