This is an archive of the discontinued LLVM Phabricator instance.

[Support][Parallel] Change check for nested TaskGroups.
ClosedPublic

Authored by avl on Apr 22 2023, 2:19 AM.

Details

Summary

This patch changes check for nested TaskGroups so that it allows
parallel execution for TaskGroups. Following pattern would not work
parallelly with current check:

std::function<void()> Fn = [&]() {
  parallel::TaskGroup tg;

  tg.spawn([&]() { });
};

ThreadPool Pool;

Pool.async(Fn);
Pool.async(Fn);

Pool.wait();

One of the TaskGroup would work sequentially as current check
verifies overall number of TaskGroup. Two not nested
TaskGroups can work parallelly but current check prevents this.

Also this patch avoids parallel mode for TaskGroup
in parallel::strategy.ThreadsRequested == 1 case.

This patch is a followup of discussion from D142318

Diff Detail

Event Timeline

avl created this revision.Apr 22 2023, 2:19 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 22 2023, 2:19 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
avl requested review of this revision.Apr 22 2023, 2:19 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 22 2023, 2:19 AM
avl edited the summary of this revision. (Show Details)Apr 22 2023, 2:20 AM
avl updated this revision to Diff 519034.May 3 2023, 5:19 AM

rebased. added setting noparallel mode for TaskGroups in case parallel::strategy.ThreadsRequested == 1.

avl edited the summary of this revision. (Show Details)May 3 2023, 5:20 AM
andrewng accepted this revision.May 3 2023, 7:59 AM

In your description, perhaps change avoid -> prevents in TaskGroups can work parallelly but current check avoid this.

Apart from the nits, LGTM.

llvm/include/llvm/Support/Parallel.h
103

Make const.

llvm/unittests/Support/ParallelTest.cpp
149

Perhaps ++Count? And the same for below...

This revision is now accepted and ready to land.May 3 2023, 7:59 AM
avl edited the summary of this revision. (Show Details)May 4 2023, 1:52 AM
This revision was automatically updated to reflect the committed changes.