未验证 提交 7f0b34dd 编写于 作者: D duanyanhui 提交者: GitHub

[TIPC] Add script for npu and xpu, test=develop (#688)

* add script for npu

* add script for xpu
上级 797d5be1
......@@ -43,6 +43,10 @@ def setup(args, cfg):
if paddle.is_compiled_with_cuda():
paddle.set_device('gpu')
elif paddle.is_compiled_with_npu():
paddle.set_device('npu')
elif paddle.is_compiled_with_xpu():
paddle.set_device('xpu')
else:
paddle.set_device('cpu')
......
#!/bin/bash
source test_tipc/common_func.sh
function readlinkf() {
perl -MCwd -e 'print Cwd::abs_path shift' "$1";
}
function func_parser_config() {
strs=$1
IFS=" "
array=(${strs})
tmp=${array[2]}
echo ${tmp}
}
BASEDIR=$(dirname "$0")
REPO_ROOT_PATH=$(readlinkf ${BASEDIR}/../)
FILENAME=$1
# change gpu to npu in tipc txt configs
sed -i "s/state=GPU/state=NPU/g" $FILENAME
sed -i "s/--device:gpu/--device:npu/g" $FILENAME
sed -i "s/--benchmark:True/--benchmark:False/g" $FILENAME
dataline=`cat $FILENAME`
# change gpu to npu in execution script
sed -i 's/\"gpu\"/\"npu\"/g' test_tipc/test_train_inference_python.sh
sed -i 's/--gpus/--npus/g' test_tipc/test_train_inference_python.sh
# parser params
IFS=$'\n'
lines=(${dataline})
# pass parameters to test_train_inference_python.sh
cmd="bash test_tipc/test_train_inference_python.sh ${FILENAME} $2"
echo $cmd
eval $cmd
#!/bin/bash
source test_tipc/common_func.sh
function readlinkf() {
perl -MCwd -e 'print Cwd::abs_path shift' "$1";
}
function func_parser_config() {
strs=$1
IFS=" "
array=(${strs})
tmp=${array[2]}
echo ${tmp}
}
BASEDIR=$(dirname "$0")
REPO_ROOT_PATH=$(readlinkf ${BASEDIR}/../)
FILENAME=$1
# change gpu to npu in tipc txt configs
sed -i "s/state=GPU/state=XPU/g" $FILENAME
sed -i "s/--device:gpu/--device:xpu/g" $FILENAME
sed -i "s/--benchmark:True/--benchmark:False/g" $FILENAME
dataline=`cat $FILENAME`
# change gpu to npu in execution script
sed -i 's/\"gpu\"/\"xpu\"/g' test_tipc/test_train_inference_python.sh
sed -i 's/--gpus/--xpus/g' test_tipc/test_train_inference_python.sh
# parser params
IFS=$'\n'
lines=(${dataline})
# pass parameters to test_train_inference_python.sh
cmd="bash test_tipc/test_train_inference_python.sh ${FILENAME} $2"
echo $cmd
eval $cmd
......@@ -107,6 +107,12 @@ def main():
if args.device == "gpu":
kp_detector_config.enable_use_gpu(100, 0)
generator_config.enable_use_gpu(100, 0)
elif args.device == "xpu":
kp_detector_config.enable_xpu()
generator_config.enable_xpu()
elif args.device == "npu":
kp_detector_config.enable_npu()
generator_config.enable_npu()
else:
kp_detector_config.set_mkldnn_cache_capacity(10)
kp_detector_config.enable_mkldnn()
......
......@@ -41,7 +41,7 @@ def parse_args():
"--device",
default="gpu",
type=str,
choices=["cpu", "gpu", "xpu"],
choices=["cpu", "gpu", "xpu", "npu"],
help="The device to select to train the model, is must be cpu/gpu/xpu.")
parser.add_argument('-c',
'--config-file',
......@@ -115,8 +115,10 @@ def create_predictor(model_path,
config.enable_use_gpu(100, 0)
elif device == "cpu":
config.disable_gpu()
elif device == "npu":
config.enable_npu()
elif device == "xpu":
config.enable_xpu(100)
config.enable_xpu()
else:
config.disable_gpu()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册