nv-legate / legate.core

The Foundation for All Legate Libraries
https://docs.nvidia.com/legate/24.06/
Apache License 2.0
186 stars 61 forks source link

[BUG] Resource scoping: get_machine().only() gives length = 0 #931

Closed CharlelieLrt closed 7 months ago

CharlelieLrt commented 7 months ago

Software versions

Python : 3.10.13 | packaged by conda-forge | (main, Oct 26 2023, 18:09:17) [Clang 16.0.6 ] Platform : macOS-12.6.7-arm64-arm-64bit Legion : v23.11.00.dev-37-g08f0ce8 Legate : 23.11.00.dev+37.g08f0ce8 [0 - 100a44580] 0.000068 {4}{threads}: reservation ('CPU proc 1d00000000000003') cannot be satisfied Cunumeric : 23.11.00.dev+28.gfd46f051.dirty Numpy : 1.26.2 Scipy : 1.11.4 Numba : 0.58.1 CTK package : (failed to detect) GPU driver : (nvidia-smi missing) GPU devices : (nvidia-smi missing)

Expected behavior

Running the following script:

from legate.core import get_machine

machine = get_machine()

OMPs = machine.only("OMP")
GPUs = machine.only("GPU")
CPUs = machine.only("CPU")

print(f"# OMPs = {len(OMPs)}")
print(f"# GPUs = {len(GPUs)}") 
print(f"# CPUs = {len(CPUs)}")

with legate --cpus 2 --omps 1 --ompthreads 2 should print the number of GPUs, CPUs, and OMP procs returned by the resource scoping.

Observed behavior

Instead, the length of OMPs, GPUs and CPUs is zero.

manopapad commented 7 months ago

Looks like Python's weak typing rules bit us here. The following works for me, can you confirm that it works on your machine as well?

from legate.core import get_machine
from legate.core.machine import ProcessorKind

machine = get_machine()

OMPs = machine.only(ProcessorKind.OMP)
GPUs = machine.only(ProcessorKind.GPU)
CPUs = machine.only(ProcessorKind.CPU)

print(f"# OMPs = {len(OMPs)}")
print(f"# GPUs = {len(GPUs)}")
print(f"# CPUs = {len(CPUs)}")

Was there an example somewhere that used strings? If so, we should update it.

CharlelieLrt commented 7 months ago

Indeed that works, the call to machine.only() was just silently failing. I didn't realize it could only be called with a ProcessorKind argument. Thanks!

(I didn't see any example using strings directly)

manopapad commented 7 months ago

I would normally put a TODO item to add an input check on machine.only() and similar functions, but that component is being redesigned, and the new version shouldn't have this issue. So closing for now.