[CPU][UX][Perf] Enable tcmalloc by default (#37607)

Signed-off-by: Fadi Arafeh <fadi.arafeh@arm.com>
This commit is contained in:
Fadi Arafeh
2026-03-25 20:39:57 +08:00
committed by GitHub
parent 7ac48fd357
commit 34d317dcec
2 changed files with 94 additions and 3 deletions
+29 -3
View File
@@ -284,8 +284,9 @@ class CpuPlatform(Platform):
# Avoid inductor generates num_thread() and breaks the thread binding
os.environ["TORCHINDUCTOR_CPP_DYNAMIC_THREADS"] = "1"
# Intel OpenMP setting
ld_preload_str = os.getenv("LD_PRELOAD", "")
# Intel OpenMP setting
if "libiomp5.so" in ld_preload_str:
# The time(milliseconds) that a thread should wait after
# completing the execution of a parallel region, before sleeping.
@@ -297,10 +298,35 @@ class CpuPlatform(Platform):
os.environ["KMP_PLAIN_BARRIER_PATTERN"] = "dist,dist"
os.environ["KMP_REDUCTION_BARRIER_PATTERN"] = "dist,dist"
cpu_architecture = Platform.get_cpu_architecture()
# LD_PRELOAD libtcmalloc, bundled under vllm/libs to reduce
# memory allocation overhead
if (
platform.system() == "Linux"
and Platform.get_cpu_architecture()
in (CpuArchEnum.ARM, CpuArchEnum.POWERPC)
and cpu_architecture in (CpuArchEnum.ARM, CpuArchEnum.X86)
and "libtcmalloc" not in ld_preload_str
):
vllm_pkg = os.path.dirname(os.path.dirname(__file__))
tcmalloc_so = None
for pattern in ("libtcmalloc_minimal*.so*", "libtcmalloc.so*"):
tcmalloc_so_candidates = glob.glob(
os.path.join(vllm_pkg, "libs", pattern)
)
if tcmalloc_so_candidates:
tcmalloc_so = tcmalloc_so_candidates[0]
break
if tcmalloc_so is not None:
if ld_preload_str:
ld_preload_str = f"{tcmalloc_so}:{ld_preload_str}"
else:
ld_preload_str = tcmalloc_so
os.environ["LD_PRELOAD"] = ld_preload_str
if (
platform.system() == "Linux"
and cpu_architecture in (CpuArchEnum.ARM, CpuArchEnum.POWERPC)
and not ("libomp" in ld_preload_str or "libgomp" in ld_preload_str)
):
# We need to LD_PRELOAD PyTorch's libgomp, otherwise only