Unverified Commit e75c1059 authored by Yifan Xiong's avatar Yifan Xiong Committed by GitHub
Browse files

Enhance parameter parsing to allow spaces in value (#397)

Enhance parameter parsing to support string like `"--arg1 value --arg2 'a long string with spaces'"`.
parent dda692da
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
"""Module of the base class.""" """Module of the base class."""
import shlex
import signal import signal
import traceback import traceback
import argparse import argparse
...@@ -39,7 +40,7 @@ def __init__(self, name, parameters=''): ...@@ -39,7 +40,7 @@ def __init__(self, name, parameters=''):
parameters (str): benchmark parameters. parameters (str): benchmark parameters.
""" """
self._name = name self._name = name
self._argv = list(filter(None, parameters.split(' '))) if parameters is not None else list() self._argv = list(filter(None, shlex.split(parameters))) if parameters is not None else list()
self._benchmark_type = None self._benchmark_type = None
self._parser = argparse.ArgumentParser( self._parser = argparse.ArgumentParser(
add_help=False, add_help=False,
......
...@@ -50,7 +50,7 @@ def test_cublas_functions(): ...@@ -50,7 +50,7 @@ def test_cublas_functions():
context = BenchmarkRegistry.create_benchmark_context( context = BenchmarkRegistry.create_benchmark_context(
'cublas-function', 'cublas-function',
platform=Platform.CUDA, platform=Platform.CUDA,
parameters='--num_warmup 10 --num_steps 10 --num_in_step 100 --config_json_str ' + custom_config_str parameters=f"--num_warmup 10 --num_steps 10 --num_in_step 100 --config_json_str '{custom_config_str}'"
) )
assert (BenchmarkRegistry.is_benchmark_context_valid(context)) assert (BenchmarkRegistry.is_benchmark_context_valid(context))
......
...@@ -54,7 +54,7 @@ def test_cudnn_functions(): ...@@ -54,7 +54,7 @@ def test_cudnn_functions():
context = BenchmarkRegistry.create_benchmark_context( context = BenchmarkRegistry.create_benchmark_context(
'cudnn-function', 'cudnn-function',
platform=Platform.CUDA, platform=Platform.CUDA,
parameters='--num_warmup 10 --num_steps 10 --num_in_step 100 --config_json_str ' + custom_config_str parameters=f"--num_warmup 10 --num_steps 10 --num_in_step 100 --config_json_str '{custom_config_str}'"
) )
assert (BenchmarkRegistry.is_benchmark_context_valid(context)) assert (BenchmarkRegistry.is_benchmark_context_valid(context))
......
...@@ -178,14 +178,14 @@ def test_ib_traffic_performance(self, mock_gpu): ...@@ -178,14 +178,14 @@ def test_ib_traffic_performance(self, mock_gpu):
assert (ret is True) assert (ret is True)
# Generate config # Generate config
parameters = '--ib_dev mlx5_0 --iters 2000 --msg_size 33554432 --hostfile hostfile' parameters = '--ib_dev "$(echo mlx5_0)" --iters 2000 --msg_size 33554432 --hostfile hostfile'
benchmark = benchmark_class(benchmark_name, parameters=parameters) benchmark = benchmark_class(benchmark_name, parameters=parameters)
os.environ['OMPI_COMM_WORLD_SIZE'] = '4' os.environ['OMPI_COMM_WORLD_SIZE'] = '4'
ret = benchmark._preprocess() ret = benchmark._preprocess()
Path('config.txt').unlink() Path('config.txt').unlink()
assert (ret) assert (ret)
expect_command = "ib_validation --cmd_prefix '" + benchmark._args.bin_dir + \ expect_command = "ib_validation --cmd_prefix '" + benchmark._args.bin_dir + \
"/ib_write_bw -F -n 2000 -d mlx5_0 -s 33554432 --report_gbits' " + \ "/ib_write_bw -F -n 2000 -d $(echo mlx5_0) -s 33554432 --report_gbits' " + \
f'--timeout 120 --hostfile hostfile --input_config {os.getcwd()}/config.txt' f'--timeout 120 --hostfile hostfile --input_config {os.getcwd()}/config.txt'
command = benchmark._bin_name + benchmark._commands[0].split(benchmark._bin_name)[1] command = benchmark._bin_name + benchmark._commands[0].split(benchmark._bin_name)[1]
assert (command == expect_command) assert (command == expect_command)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment