Skip to content
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

CPU binding on MacOS #555

Open
isaevil opened this issue Dec 5, 2022 · 4 comments
Open

CPU binding on MacOS #555

isaevil opened this issue Dec 5, 2022 · 4 comments

Comments

@isaevil
Copy link

isaevil commented Dec 5, 2022

Hi,
AFAIK, CPU binding is not supported on MacOS due to the lack of the necessary interface from Apple.

hwloc-bind core:0-3 hwloc-bind --get
hwloc_set_cpubind 0x0000000f (flags 0x0) failed (errno 78 Function not implemented)

But still, Apple provide interface to set QOS classes (for example, see pthread section at Apple's doc.
Is it possible to have some implemented hwloc API that is based on those hints? It would allow to make hints to different core types on hybrid CPUs like Apple M1/M2.

@bgoglin
Copy link
Contributor

bgoglin commented Dec 5, 2022

Hello
We have some Linux specific API to manipulate binding, we could certainly do something in a new hwloc/darwin.h or so. Did you have an idea of what the new hwloc API would look like?

@isaevil
Copy link
Author

isaevil commented Dec 5, 2022

As far as I can understand from docs I've read, Apple's pthread QOS interface allows to (based on reading of qos.h):

  • Set QOS class to pthread attributes and create a thread.
  • Set QOS class to calling thread (pthread_set_qos_class_self_np(...)).
  • Start/End QOS class override of specified thread (pthread_override_qos_class_start_np(...)).
  • Get QOS class from attribute, from calling thread.

Honestly, I don't know how high-level (or low-level) API should be used here. It can be either a possibility to set those QOS classes directly or maybe leave it internal and make hints based on cpukind (e.g. set QOS_CLASS_USER_INTERACTIVE or QOS_CLASS_USER_INITIATED to hint using Performance cores first or set QOS_CLASS_BACKGROUND to hint using Efficient cores).

I am personally interested in using it with threads, so maybe some hwloc_darwin_{set|get}_thread_qos_class name for this type of functionality is appropriate.

@bgoglin
Copy link
Contributor

bgoglin commented Dec 5, 2022

It seems to me that such hwloc functions wouldn't do anything clever, they would only call the equivalent function from MacOS X, why would be the benefit of a hwloc function then?

For Linux, the point of functions such as hwloc_linux_set_tid_cpubind() is that they use hwloc cpusets instead of Linux cpusets for describing the binding, hence it's easier to integrate inside an existing hwloc code.

@isaevil
Copy link
Author

isaevil commented Dec 6, 2022

Maybe it can be some additional logic also based on CPU sets? Like if we specify CPU set with P cores it will use "User interactive" or "User initiated", if we specify CPU set with E cores, it will use "Background" QOS class. If it is something at an intersection, it can be "Utility" QOS class. I am not sure, whether this logic seems reasonable or not, but just for example.

I guess the only benefit is having some alternative to real CPU Binding on MacOS and being able to use it as a part of HWLOC. I think it would be easier to fit this functionality into the existing code that uses HWLOC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants