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

Feature Request: Cores as init parameter, respect core perf levels #191

Open
turbo opened this issue Feb 18, 2023 · 0 comments
Open

Feature Request: Cores as init parameter, respect core perf levels #191

turbo opened this issue Feb 18, 2023 · 0 comments

Comments

@turbo
Copy link

turbo commented Feb 18, 2023

On Apple Silicon, I'd like to be able to set the maximum count of worker threads to the number of performance cores, rather than all. Nim's built-in CPU count proc is unaware of perf levels on AS. I assume the same is the case for later Intel CPUs.

I'm using this workaround right now:

if hostOS == "macosx" and hostCPU == "arm64" and cpuEndian == Endianness.littleEndian:
  echo "Apple Silicon detected, tuning parallel runtime to use perflevel0 only"

  # sysctl hw.perflevel0.logicalcpu_max
  # hw.perflevel0.logicalcpu_max: 8 

  let outp = execProcess(
    "/usr/sbin/sysctl", 
    args = ["hw.perflevel0.logicalcpu_max"], 
    options = { poStdErrToStdOut }
  )

  let perfCores = outp.split(": ")[1].strip.parseInt
  echo &"Detected {perfCores} cores at perflevel0"

  putEnv("WEAVE_NUM_THREADS", $perfCores)

This works, and macOS scheduler seems to pin the threads to the right cores. It'd be nice for Weave to be aware of this natively, and to be able to allow one to specify cores to init directly without the round-trip through the environment, e.g.:

init(Weave, threads = 42, [perfLevel = all, performanceOnly])

No opinion on whether a potentially set ENV var should override this init parameter.

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

1 participant