Skip to content

Commit 1ed3d6d

Browse files
committed
Early exit from get_numa_aware_cpu_affinity() if the system is not NUMA
Signed-off-by: Dan Hansen <[email protected]>
1 parent 6ab05cb commit 1ed3d6d

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

tensorrt_llm/llmapi/utils.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -529,20 +529,24 @@ def get_numa_aware_cpu_affinity(device_id):
529529
'''
530530
cpu_count = psutil.cpu_count()
531531

532-
# Get the number of bits per ulong
533-
c_ulong_bits = ctypes.sizeof(ctypes.c_ulong) * 8
534-
535-
# Determine how large our cpu set array from NVML needs to be
536-
cpu_set_size = math.ceil(cpu_count / c_ulong_bits)
537-
538-
# If we hit an exception, default to unconstrained CPU affinity
532+
# If this is not a NUMA system, or we hit an exception, default to
533+
# unconstrained CPU affinity
539534
cpu_affinity = list(range(cpu_count))
540535

536+
if not os.path.isdir("/sys/devices/system/node/node1"):
537+
return cpu_affinity
538+
541539
try:
542540
# initialize NVML
543541
import pynvml
544542
pynvml.nvmlInit()
545543

544+
# Get the number of bits per ulong
545+
c_ulong_bits = ctypes.sizeof(ctypes.c_ulong) * 8
546+
547+
# Determine how large our cpu set array from NVML needs to be
548+
cpu_set_size = math.ceil(cpu_count / c_ulong_bits)
549+
546550
# Get the optimal CPU affinity for this device according to the NUMA
547551
# topology
548552
handle = pynvml.nvmlDeviceGetHandleByIndex(device_id)

0 commit comments

Comments
 (0)