From 5ac9f67ad55ffccbe6c7c4e83f9397d9e64112a5 Mon Sep 17 00:00:00 2001 From: xshaitt <773999579@qq.com> Date: Fri, 18 Apr 2025 11:22:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20get=5Finfer=5Fgpuid=20?= =?UTF-8?q?=E5=87=BD=E6=95=B0=EF=BC=8C=E5=A2=9E=E5=8A=A0=E5=AF=B9=20Paddle?= =?UTF-8?q?Paddle=20=E7=89=88=E6=9C=AC=E7=9A=84=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/tools/infer/utility.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/backend/tools/infer/utility.py b/backend/tools/infer/utility.py index 33f0a48..05c400e 100644 --- a/backend/tools/infer/utility.py +++ b/backend/tools/infer/utility.py @@ -340,7 +340,14 @@ def get_infer_gpuid(): if sysstr == "Windows": return 0 - if not paddle.fluid.core.is_compiled_with_rocm(): + # 检查 PaddlePaddle 版本 + paddle_version = paddle.__version__ + major_version = int(paddle_version.split('.')[0]) + if major_version >= 2: + is_rocm = paddle.device.is_compiled_with_rocm() + else: + is_rocm = paddle.fluid.core.is_compiled_with_rocm() + if not is_rocm: cmd = "env | grep CUDA_VISIBLE_DEVICES" else: cmd = "env | grep HIP_VISIBLE_DEVICES"