-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rename Sys.CPU_CORES to more explict Sys.CPU_LOGICAL_CORES #27856
Conversation
Seems like we could just better document that |
Sounds like an alternative, but do you think it would solve the misinterpretation effectively? And if we need to add the actual physical cores in the future, how should it be called? |
Calling it |
Can you look at what terminology other software use? One advantage of keeping |
Thank you all for the comments. I like the shorter name Regarding the slow down, I think I've exaggerated the number, sorry. I could only find an old issue with a 10x slowdown that we took a while to figure out. After back and forth with many hypothesis falsified it was just a misinterpretation of the variable name: #16570 |
Doesn't #16570 indicate that FFTW should use different defaults on Windows? Skimming that discussion, it seems the user hasn't explicitly used |
In that code, I was setting the number of threads to I fixed the issue later by depending on Hwloc.jl which uses the terminology "Core" for physical cores and "PUs" for logical units: import Hwloc
topology = Hwloc.topology_load()
counts = Hwloc.histmap(topology)
ncores = counts[:Core]
npus = counts[:PU]
println("This machine has $ncores cores and $npus PUs (processing units)") The CpuId.jl package uses |
This doesn't really make much sense to me:
|
Yes, as I wrote, I definitely exaggerated there. But it is a slow down that
converts 1 hour in a day or so. Significant
…On Fri, Jun 29, 2018, 5:36 PM Stefan Karpinski ***@***.***> wrote:
having their simulations running 1000x slower because hyperthreading is
not supported sometimes.
This doesn't really make much sense to me:
- If hyperthreading isn't supported then "physical cores" = "logical
cores".
- A 1000x slowdown from oversubscribing the number of physical cores
seems unlikely.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#27856 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADMLbcWjhjtu_46cjG-mWVrwxxOPK64Wks5uBsf1gaJpZM4U8ZKy>
.
|
Based on the positive hands in @StefanKarpinski 's comment, I think most agree the change would improve clarity. The build is failing because I am using the macro @deprecate Sys.CPU_CORES Sys.CPU_LOGICAL_CORES |
@eval Sys @deprecate_binding CPU_CORES CPU_LOGICAL_CORES false |
base/deprecated.jl
Outdated
@@ -1732,6 +1732,9 @@ end | |||
@deprecate mapfoldl(f, op, v0, itr) mapfoldl(f, op, itr; init=v0) | |||
@deprecate mapfoldr(f, op, v0, itr) mapfoldr(f, op, itr; init=v0) | |||
|
|||
# PR #27856 | |||
@eval Sys @deprecate_binding CPU_CORES CPU_LOGICAL_CORES false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fredrikekre did as you suggested but the CI build is saying that @deprecate_binding
is not defined
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Base.@deprecate_binding
The error in Travis now is |
It seems the variable |
Workflow I use:
In this case it seems like the deprecation may need to be done in Base’s bootstrap code. |
The build is passing without the deprecation warning. Can you advise on how to re-add the deprecation in Base's bootstrap code? |
Or if you prefer to merge and add the deprecation warning on a separate PR, that works too. |
Are you still interested in this change? The PR is ready. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should not be merged without a deprecation
a48bee3
to
ca0a36b
Compare
That deprecation was trickier than expected. Although values that are set on startup always are. |
Thanks for the addition, the build is passing, should be ready to merge 👍 |
3898ec7
to
a578d4f
Compare
Resolved the conflict, letting CI run again, we can merge as soon as anything passes. |
Wrong button, sorry. |
a578d4f
to
018d726
Compare
I agree we should eventually have |
I don't know if that improves the situation. Picking defaults is always a tricky task, and the name Besides, the chance of users adopting this platform-dependent default when they should have been explicit about what they wanted are big. Perhaps another name that is not |
I would be ok with making CPU_CORES refer to physical cores, and using MAX_THREADS for fake cores. |
So the proposal is to rename the current |
No one is suggesting that it be platform-dependent, the suggestion is that it be hardware-dependent... and it seems fairly obvious that |
Could you please clarify? Suppose I have a laptop with two physical cores
that supports hyperthreading and can do four logical cores without
performance hits. If I install Linux versus Windows, will CPU_CORES always
return four and hence mean logical cores as initially discussed in this
issue?
My main concern is the name of the variable, which is inconsistent with
other software conventions (e.g. hwloc).
…On Thu, Jul 12, 2018, 6:21 AM Stefan Karpinski ***@***.***> wrote:
CPU_CORES does not suggest something that is platform-dependent.
No one is suggesting that it be platform-dependent. The suggestion is that
it be hardware-dependent... and it seems fairly obvious that CPU_CORES
would depend on your hardware.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#27856 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADMLbd2Ug5IAsCATqehQmSwBq7J127Beks5uF01IgaJpZM4U8ZKy>
.
|
Does such a thing exist?
No, as Stefan said this would be hardware-dependent, not OS-dependent. I just don't want writing |
Sorry for the naive question, isn't hyperthreading technology implemented at the software level? |
Not entirely; it also requires a hardware feature that exposes a different number of CPUs to the OS. |
So it is not only hardware-dependent right? That is what is concerning, the
name CPU_CORES is very unclear. Most software use it for physical cores, a
hardware quality.
…On Thu, Jul 12, 2018, 8:38 AM Jeff Bezanson ***@***.***> wrote:
Not entirely; it also requires a hardware feature that exposes a different
number of CPUs to the OS.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#27856 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADMLbQb4D9oMFdpxCMgZk0abdrJ-OJ8Aks5uF22OgaJpZM4U8ZKy>
.
|
No, the number of physical cores and hyper-threaded cores are both determined entirely by the hardware. The number of hyper-threads supported by your CPU does not change when you change your OS. |
The trouble is that naively people expect |
So maybe MAX_THREADS or other less confusing name would save future burns?
It is natural to interpret CPU_CORES as cpu cores, which is not what the
Julia implementation is doing.
…On Thu, Jul 12, 2018, 10:15 AM Stefan Karpinski ***@***.***> wrote:
The trouble is that naively people expect CPU_CORES to tell them how many
"cores" there are and how many threads they should use. Both of those
questions are subtler than they used to be and may not be the same. You
seem to have gotten burned by one meaning, but there's no reason that the
other meaning won't burn you just as badly.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#27856 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADMLbUfd38VMNbWqCEf_pPRvsDHOZCP8ks5uF4Q2gaJpZM4U8ZKy>
.
|
The point is that it depends on what the definition of what a "cpu core" is—and this is not clear-cut. You want to change it to mean "physical cores" based on a a single experience on one piece of hardware with one specific workload for which having as many threads as there are logical cores happened to cause suboptimal performance. On the same hardware, there are other workloads where having as many threads as there are logical cores will lead to optimal performance and only having as there are physical cores will lead to highly suboptimal performance. On yet other hardware (e.g. Xeon Phi), it is impossible to get optimal performance if the number of threads is limited to the number of physical cores: you can only get full usage of the hardware with hyper-threading. Jeff's proposal is (as I understand it) to leave |
+1 for |
I see. If both physical and logical cores are exported as well besides the
guessed value proposed, that would be fine.
I still think that the name CPU_CORES is inappropriate for the current
implementation. IMO, ideally we would have the following semantics:
CPU_CORES: optimal guess, hard to define
CPU_PHYS_CORES: physical cores
CPU_LOGIC_CORES: logical cores
This PR is adopting the above definitions, but I could shorten the name
further from CPU_LOGICAL_CORES to CPU_LOGIC_CORES
What do you think?
…On Thu, Jul 12, 2018, 11:04 AM Stefan Karpinski ***@***.***> wrote:
It is natural to interpret CPU_CORES as cpu cores, which is not what the
Julia implementation is doing.
The point is that it depends on what the definition of what a "cpu core"
is—and this is not clear-cut. You want to change it to mean "physical
cores" based on a a single experience on one piece of hardware with one
specific workload for which having as many threads as there are logical
cores happened to cause suboptimal performance. On *the same* hardware,
there are other workloads where having as many threads as there are logical
cores will lead to optimal performance and only having as there are
physical cores will lead to highly suboptimal performance. On yet other
hardware (e.g. Xeon Phi <https://en.wikipedia.org/wiki/Xeon_Phi>), it is
impossible to get optimal performance if the number of threads is limited
to the number of physical cores: you can only get full usage of the
hardware with hyper-threading.
Jeff's proposal is (as I understand it) to leave CPU_CORES as is but
document that may change in the future and is defined to give you some
value between the number of logical cores and physical cores that we
believe to be a pretty good guess at how many threads you want to use for
CPU-intensive workloads on your hardware. The current definition as logical
cores is good for some machines (Xeon Phi) but bad for other machines, so
this should be improved. In addition, we can expose the number of logical
and physical cores separately.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#27856 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADMLbfiHRYwFtuqHkU1eP3ofqDDAsSkQks5uF4-SgaJpZM4U8ZKy>
.
|
Oh I like CPU_CORES and CPU_THREADS +1
On Thu, Jul 12, 2018, 12:01 PM Júlio Hoffimann <[email protected]>
wrote:
… I see. If both physical and logical cores are exported as well besides the
guessed value proposed, that would be fine.
I still think that the name CPU_CORES is inappropriate for the current
implementation. IMO, ideally we would have the following semantics:
CPU_CORES: optimal guess, hard to define
CPU_PHYS_CORES: physical cores
CPU_LOGIC_CORES: logical cores
This PR is adopting the above definitions, but I could shorten the name
further from CPU_LOGICAL_CORES to CPU_LOGIC_CORES
What do you think?
On Thu, Jul 12, 2018, 11:04 AM Stefan Karpinski ***@***.***>
wrote:
> It is natural to interpret CPU_CORES as cpu cores, which is not what the
> Julia implementation is doing.
>
> The point is that it depends on what the definition of what a "cpu core"
> is—and this is not clear-cut. You want to change it to mean "physical
> cores" based on a a single experience on one piece of hardware with one
> specific workload for which having as many threads as there are logical
> cores happened to cause suboptimal performance. On *the same* hardware,
> there are other workloads where having as many threads as there are logical
> cores will lead to optimal performance and only having as there are
> physical cores will lead to highly suboptimal performance. On yet other
> hardware (e.g. Xeon Phi <https://en.wikipedia.org/wiki/Xeon_Phi>), it is
> impossible to get optimal performance if the number of threads is limited
> to the number of physical cores: you can only get full usage of the
> hardware with hyper-threading.
>
> Jeff's proposal is (as I understand it) to leave CPU_CORES as is but
> document that may change in the future and is defined to give you some
> value between the number of logical cores and physical cores that we
> believe to be a pretty good guess at how many threads you want to use for
> CPU-intensive workloads on your hardware. The current definition as logical
> cores is good for some machines (Xeon Phi) but bad for other machines, so
> this should be improved. In addition, we can expose the number of logical
> and physical cores separately.
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <#27856 (comment)>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/ADMLbfiHRYwFtuqHkU1eP3ofqDDAsSkQks5uF4-SgaJpZM4U8ZKy>
> .
>
|
Based on triage discussion, "CPU cores" is most commonly used to mean "physical cores" whereas "CPU threads" is often used to mean "logical cores"—i.e. number of hardware threads (Intel is not entirely consistent about this, but this is the trend). Accordingly, an alternate proposal is to rename |
Awesome, I can adjust the PR by the end of the day, feel free to make the
changes earlier as well...
…On Thu, Jul 12, 2018, 12:06 PM Stefan Karpinski ***@***.***> wrote:
Based on triage discussion, "CPU cores" is most commonly used to mean
"physical cores" whereas "CPU threads" is often used to mean "logical
cores"—i.e. number of hardware threads (Intel is not entirely consistent
about this, but this is the trend). Accordingly, an alternate proposal is
to rename CPU_CORES to CPU_THREADS now and potentially reintroduce
CPU_CORES in the future to give the number of physical cores. It should
be noted that this number may not be as useful as people believe it to be.
The number of threads that a process should use is a different matter, but
is generally some n between CPU_CORES ≤ n ≤ CPU_THREADS.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#27856 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADMLbZfZr9yi3a44LTaipz74TL9WQqzmks5uF54rgaJpZM4U8ZKy>
.
|
Got into some weird situation with GitHub remotes and it was easier to make a new PR: #28091. |
This pull request renames
Sys.CPU_CORES
to the more explicit nameSys.CPU_LOGICAL_CORES
, and the corresponding env variableJULIA_CPU_CORES
toJULIA_CPU_LOGICAL_CORES
.I've experienced cases of users on Windows using
CPU_CORES
thinking of physical cores, and then having their simulations running 1000x slower because hyperthreading is not supported sometimes.The changes also leave the door open for a future
Sys.CPU_PHYSICAL_CORES
with the actual physical cores.Please let me know if something is missing or if the changes are not appropriate.