[Intel MKL] Parallelize UnsortedSegmentSum on CPU deivce #49152
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
UnsortedSegmentSum
is a single thread op on CPU, here use the Eigen device to parallelize it. It's updated from an old PR #26427 .I resubmit this PR because the original one got an internal crash and was reverted. Because I can't get the failure case, I just went through the old code and found a potential rounding issue here: https://github.com/Intel-tensorflow/tensorflow/blob/52a6cfddef9b51b608b4a554b77a10e1522d56ec/tensorflow/core/kernels/segment_reduction_ops.cc#L419-L425
This PR uses a simple and reasonable way to balance workload like what TF usually did:
Other parts are the same as the original one.
Performance improvement:
This patch tries to parallel UnsortSegmentReduction with num_segments, so the performance has no change if num_segments is 1, otherwise it has ~3X improvement in the benchmark.