onnxruntime
4eb757c7 - Clarify Kahan condition (#28790)

Commit
5 days ago
Clarify Kahan condition (#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)
Author
Parents
Loading