diff --git a/legate/util/system.py b/legate/util/system.py index ba48e6ac5..d164669fb 100644 --- a/legate/util/system.py +++ b/legate/util/system.py @@ -86,6 +86,13 @@ def LIB_PATH(self) -> str: def cpus(self) -> tuple[CPUInfo, ...]: """A list of CPUs on the system.""" + def expand_range(value: str) -> tuple[int, ...]: + if "-" not in value: + return tuple((int(value),)) + start, stop = value.split("-") + + return tuple(x for x in range(int(start), int(stop) + 1)) + N = multiprocessing.cpu_count() if sys.platform == "darwin": @@ -98,9 +105,11 @@ def cpus(self) -> tuple[CPUInfo, ...]: line = open( f"/sys/devices/system/cpu/cpu{i}/topology/thread_siblings_list" # noqa E501 ).read() - sibling_sets.add( - tuple(sorted(int(x) for x in line.strip().split(","))) - ) + + flattened = [] + for x in (expand_range(value) for value in line.strip().split(",")): + flattened += [y for y in x] + sibling_sets.add(tuple(sorted(flattened))) return tuple( CPUInfo(siblings) for siblings in sorted(sibling_sets) )