|
3 | 3 |
|
4 | 4 | import json |
5 | 5 | import os |
6 | | -import platform |
7 | 6 | import subprocess |
| 7 | +import sys |
8 | 8 | from dataclasses import dataclass |
9 | 9 | from functools import cache |
10 | 10 |
|
@@ -78,7 +78,7 @@ def parse_id_list(raw_str: str) -> list[int]: |
78 | 78 |
|
79 | 79 |
|
80 | 80 | def get_memory_node_info(node_id: int = 0) -> MemoryNodeInfo: |
81 | | - if platform.system() == "Darwin": |
| 81 | + if sys.platform == "darwin": |
82 | 82 | # MacOS has no memory node |
83 | 83 | return MemoryNodeInfo( |
84 | 84 | total_memory=psutil.virtual_memory().total, |
@@ -122,17 +122,14 @@ def get_memory_node_info(node_id: int = 0) -> MemoryNodeInfo: |
122 | 122 |
|
123 | 123 | def get_allowed_cpu_list() -> list[LogicalCPUInfo]: |
124 | 124 | cpu_list = _get_cpu_list() |
125 | | - if platform.system() == "Darwin": |
126 | | - return cpu_list |
127 | | - |
128 | | - global_allowed_cpu_id_list = os.sched_getaffinity(0) # type: ignore[attr-defined] |
129 | | - logical_cpu_list = [x for x in cpu_list if x.id in global_allowed_cpu_id_list] |
130 | | - |
131 | | - return logical_cpu_list |
| 125 | + if sys.platform == "linux": |
| 126 | + allowed = os.sched_getaffinity(0) |
| 127 | + return [x for x in cpu_list if x.id in allowed] |
| 128 | + return cpu_list |
132 | 129 |
|
133 | 130 |
|
134 | 131 | def get_visible_memory_node() -> list[int]: |
135 | | - if platform.system() == "Darwin": |
| 132 | + if sys.platform == "darwin": |
136 | 133 | return [0] |
137 | 134 |
|
138 | 135 | allowed_memory_node_list = get_memory_affinity() |
@@ -163,7 +160,7 @@ def _synthesize_cpu_list() -> list[LogicalCPUInfo]: |
163 | 160 |
|
164 | 161 |
|
165 | 162 | def _get_cpu_list() -> list[LogicalCPUInfo]: |
166 | | - if platform.system() == "Darwin": |
| 163 | + if sys.platform == "darwin": |
167 | 164 | # For MacOS, no user-level CPU affinity and SMT, return all CPUs |
168 | 165 | return _synthesize_cpu_list() |
169 | 166 |
|
|
0 commit comments