From 832c3894272d1f7632d6e72f1628cbe3c5bbbfe5 Mon Sep 17 00:00:00 2001 From: tianshuo78520a <707759223@qq.com> Date: Thu, 22 Jul 2021 16:38:26 +0800 Subject: [PATCH] fix m1 not found leaf7_features (#34309) --- python/paddle/fluid/core.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/python/paddle/fluid/core.py b/python/paddle/fluid/core.py index 3087a5a4b01..1f26b3d0bf0 100644 --- a/python/paddle/fluid/core.py +++ b/python/paddle/fluid/core.py @@ -92,15 +92,14 @@ def avx_supported(): 'Can not get the AVX flag from machdep.cpu.features.\n' 'The original error is: %s\n' % cpt.get_exception_message(e)) if not has_avx: - try: - has_avx = os.popen( - 'sysctl machdep.cpu.leaf7_features | grep -i avx').read( - ) != '' - except Exception as e: - sys.stderr.write( - 'Can not get the AVX flag from machdep.cpu.leaf7_features.\n' - 'The original error is: %s\n' % - cpt.get_exception_message(e)) + import subprocess + pipe = subprocess.Popen( + 'sysctl machdep.cpu.leaf7_features | grep -i avx', + shell=True, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + _ = pipe.communicate() + has_avx = True if pipe.returncode == 0 else False return has_avx elif sysstr == 'windows': import ctypes -- GitLab