Skip to content

Commit 6891388

Browse files
Add available devices and dtypes selection to runner.py (#101)
* devices-dtypes * pep8 * Replase None with none * update dtypes help
1 parent 8302a72 commit 6891388

File tree

3 files changed

+41
-8
lines changed

3 files changed

+41
-8
lines changed

bench.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ def parse_args(parser, size=None, loop_types=(),
173173
action='store_true',
174174
help='Use no intel optimized version. '
175175
'Now avalible for scikit-learn benchmarks')
176-
parser.add_argument('--device', default='None', type=str,
177-
choices=('host', 'cpu', 'gpu', 'None'),
176+
parser.add_argument('--device', default='none', type=str,
177+
choices=('host', 'cpu', 'gpu', 'none'),
178178
help='Execution context device')
179179

180180
for data in ['X', 'y']:
@@ -198,15 +198,15 @@ def parse_args(parser, size=None, loop_types=(),
198198
except ImportError:
199199
logging.info('Failed to import sklearnex.patch_sklearn.'
200200
'Use stock version scikit-learn', file=sys.stderr)
201-
params.device = 'None'
201+
params.device = 'none'
202202
else:
203-
if params.device != 'None':
203+
if params.device != 'none':
204204
logging.info(
205205
'Device context is not supported for stock scikit-learn.'
206206
'Please use --no-intel-optimized=False with'
207-
f'--device={params.device} parameter. Fallback to --device=None.',
207+
f'--device={params.device} parameter. Fallback to --device=none.',
208208
file=sys.stderr)
209-
params.device = 'None'
209+
params.device = 'none'
210210

211211
# disable finiteness check (default)
212212
if not params.check_finiteness:
@@ -554,7 +554,7 @@ def print_output(library, algorithm, stages, params, functions,
554554

555555

556556
def run_with_context(params, function):
557-
if params.device != 'None':
557+
if params.device != 'none':
558558
from daal4py.oneapi import sycl_context
559559
with sycl_context(params.device):
560560
function()

configs/skl_xpu_config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"data-format": "pandas",
55
"data-order": "F",
66
"dtype": "float64",
7-
"device": ["host", "cpu", "gpu", "None"]
7+
"device": ["host", "cpu", "gpu", "none"]
88
},
99
"cases": [
1010
{

runner.py

+33
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,20 @@ def get_configs(path: Path) -> List[str]:
4444
default='configs/config_example.json',
4545
help='The path to a configuration file or '
4646
'a directory that contains configuration files')
47+
parser.add_argument('--device', '--devices', default='host cpu gpu none', type=str, nargs='+',
48+
choices=('host', 'cpu', 'gpu', 'none'),
49+
help='Availible execution context devices. '
50+
'This parameter only marks devices as available, '
51+
'make sure to add the device to the config file '
52+
'to run it on a specific device')
4753
parser.add_argument('--dummy-run', default=False, action='store_true',
4854
help='Run configuration parser and datasets generation '
4955
'without benchmarks running')
56+
parser.add_argument('--dtype', '--dtypes', type=str, default="float32 float64", nargs='+',
57+
choices=("float32", "float64"),
58+
help='Available floating point data types'
59+
'This parameter only marks dtype as available, '
60+
'make sure to add the dtype parameter to the config file ')
5061
parser.add_argument('--no-intel-optimized', default=False, action='store_true',
5162
help='Use Scikit-learn without Intel optimizations')
5263
parser.add_argument('--output-file', default='results.json',
@@ -93,6 +104,28 @@ def get_configs(path: Path) -> List[str]:
93104
for params_set in config['cases']:
94105
params = common_params.copy()
95106
params.update(params_set.copy())
107+
108+
device = []
109+
if 'device' not in params:
110+
if 'sklearn' in params['lib']:
111+
logging.info('The device parameter value is not defined in config, '
112+
'none is used')
113+
device = ['none']
114+
elif not isinstance(params['device'], list):
115+
device = [params['device']]
116+
else:
117+
device = params['device']
118+
params["device"] = [dv for dv in device if dv in args.device]
119+
120+
dtype = []
121+
if 'dtype' not in params:
122+
dtype = ['float64']
123+
elif not isinstance(params['dtype'], list):
124+
dtype = [params['dtype']]
125+
else:
126+
dtype = params['dtype']
127+
params['dtype'] = [dt for dt in dtype if dt in args.dtype]
128+
96129
algorithm = params['algorithm']
97130
libs = params['lib']
98131
if not isinstance(libs, list):

0 commit comments

Comments
 (0)