This is an archive of the discontinued LLVM Phabricator instance.

Add parallelTransformReduce and parallelForEachError
ClosedPublic

Authored by rnk on Nov 2 2020, 12:37 PM.

Details

Summary

parallelTransformReduce is modelled on the C++17 pstl API of
std::transform_reduce, except our wrappers do not use execution policy
parameters.

parallelForEachError allows loops that contain potentially failing
operations to propagate errors out of the loop. This was one of the
major challenges I encountered while parallelizing PDB type merging in
LLD. Parallelizing a loop with parallelForEachError is not behavior
preserving: the loop will no longer stop on the first error, it will
continue working and report all errors it encounters in a list.

I plan to use this to propagate errors out of LLD's
coff::TpiSource::remapTpiWithGHashes, which currently stores errors an
error in the TpiSource object.

Diff Detail

Event Timeline

rnk created this revision.Nov 2 2020, 12:37 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 2 2020, 12:37 PM
Herald added a subscriber: dexonsmith. · View Herald Transcript
rnk requested review of this revision.Nov 2 2020, 12:37 PM
rriddle accepted this revision.Nov 2 2020, 12:54 PM

Nice, this looks like a good addition. There's already at least one place in MLIR that I could see this used as well.

llvm/include/llvm/Support/Parallel.h
169

Can you check for the case where NumInputs == 0 and return Init? Any reason that we should require that there is always at least one task?

193

We could strip the first reduce given that we know that there will be at least one task, but I suppose the reduce function won't be costly in most cases.

This revision is now accepted and ready to land.Nov 2 2020, 12:54 PM
rnk updated this revision to Diff 302433.Nov 2 2020, 4:43 PM
  • more tests, handle corner cases
rnk added a comment.Nov 2 2020, 4:45 PM

More unit testing showed that I wasn't more than 1024 inputs well, so I fixed that. Take another look if you want to double check that. Thanks!

llvm/include/llvm/Support/Parallel.h
169

Let's just make it work. I think I hit this edge case somewhere in LLD for parallelForEach.

172

Hm, I guess this assert is wrong for empty inputs. Amusingly, LLVM hid the bug from me because integer divide by zero is UB. :)

193

Eh, let's do it.

This revision was landed with ongoing or failed builds.Nov 2 2020, 4:50 PM
This revision was automatically updated to reflect the committed changes.