This is an archive of the discontinued LLVM Phabricator instance.

Add interface for querying physical hardware concurrency
ClosedPublic

Authored by tejohnson on Oct 13 2016, 4:43 PM.

Details

Summary

This will be used by ThinLTO to set the amount of backend
parallelism, which performs better when restricted to the number
of physical cores (on X86 at least, where getHostNumPhysicalCores is
currently defined). If not available this falls back to
thread::hardware_concurrency.

Note I didn't add to the thread class since that is a typedef to
std::thread where available.

Diff Detail

Repository
rL LLVM

Event Timeline

tejohnson updated this revision to Diff 74597.Oct 13 2016, 4:43 PM
tejohnson retitled this revision from to Add interface for querying physical hardware concurrency.
tejohnson updated this object.
tejohnson added a reviewer: mehdi_amini.
tejohnson added a subscriber: llvm-commits.
mehdi_amini accepted this revision.Oct 13 2016, 4:50 PM
mehdi_amini edited edge metadata.

LGTM.

I suggested a name change, but if you disagree with the rational, you can commit your version.

include/llvm/Support/Threading.h
121 ↗(On Diff #74597)

I think we may want to name it hardware_coarse_concurrency. Because:

  • This looks like expressing better what we're looking after.
  • Hyperthreading is in some sense "physical concurrency", but sharing some resources.
  • Other platforms may have something in between.
This revision is now accepted and ready to land.Oct 13 2016, 4:50 PM
tejohnson added inline comments.Oct 13 2016, 5:07 PM
include/llvm/Support/Threading.h
121 ↗(On Diff #74597)

I thought about that name after you mentioned it on the prior review thread. But I felt that saying "physical concurrency" is a better expression for what it is actually trying to give you. I think of the hyperthreading concurrency as "logical concurrency", vs physical concurrency due to physical cores.

This revision was automatically updated to reflect the committed changes.
thakis added a subscriber: thakis.Oct 14 2016, 12:23 PM

The new test fails if I cmake with -DLLVM_ENABLE_THREADS=OFF. I guess this just needs a #if LLVM_ENABLE_THREADS?

The new test fails if I cmake with -DLLVM_ENABLE_THREADS=OFF. I guess this just needs a #if LLVM_ENABLE_THREADS?

Yes that's right. With LLVM_ENABLE_THREADS=OFF hardware_concurrency will return 1, so the test will fail. I took the day off today, if you want to submit a fix then LGTM. I will do so tonight if you don't have a chance before then.

Thanks