From 5fb45e467247ee3d2145a7ac2e1db2181736eac6 Mon Sep 17 00:00:00 2001 From: MRXLT Date: Tue, 31 Mar 2020 04:02:59 +0000 Subject: [PATCH] fix gpu_ids --- python/paddle_serving_server_gpu/serve.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/python/paddle_serving_server_gpu/serve.py b/python/paddle_serving_server_gpu/serve.py index 2cce4d4b..fb2e756d 100644 --- a/python/paddle_serving_server_gpu/serve.py +++ b/python/paddle_serving_server_gpu/serve.py @@ -64,14 +64,21 @@ def start_gpu_card_model(index, gpuid, args): # pylint: disable=doc-string-miss def start_multi_card(args): # pylint: disable=doc-string-missing gpus = "" if args.gpu_ids == "": - if "CUDA_VISIBLE_DEVICES" in os.environ: - gpus = os.environ["CUDA_VISIBLE_DEVICES"] - else: - gpus = [] + gpus = [] else: gpus = args.gpu_ids.split(",") + if "CUDA_VISIBLE_DEVICES" in os.environ: + env_gpus = os.environ["CUDA_VISIBLE_DEVICES"].split(",") + if int(gpus[-1]) >= len(env_gpus): + print( + " Max index of gpu_ids out of range, the number of CUDA_VISIBLE_DEVICES is {}.". + format(len(env_gpus))) + exit(-1) + else: + env_gpus = [] if len(gpus) <= 0: - start_gpu_card_model(-1, 0, args) + print("gpu_ids not set, going to run cpu service.") + start_gpu_card_model(-1, -1, args) else: gpu_processes = [] for i, gpu_id in enumerate(gpus): -- GitLab