Skip to content

Commit 5bb4c31

Browse files
SPMD sklearnex examples run (#1217)
SPMD sklearnex examples run
1 parent e5858d6 commit 5bb4c31

File tree

5 files changed

+52
-15
lines changed

5 files changed

+52
-15
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ scikit_learn_intelex.egg-info
2929
record*
3030

3131
# example .res files
32-
examples/daal4py/_results*
32+
tests/_results*

conda-recipe/meta.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ test:
8181
- mpiexec -localonly -n 4 python -m unittest discover -v -s tests -p spmd*.py # [win]
8282
- python -m unittest discover -v -s tests -p test*.py
8383
- pytest --pyargs daal4py/sklearn/
84-
- python examples/daal4py/run_examples.py
84+
- python tests/run_examples.py
8585
- python -m daal4py examples/daal4py/sycl/sklearn_sycl.py
8686

8787
about:

examples/daal4py/run_examples.py renamed to tests/run_examples.py

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@
3131
# third item is status - B
3232
print('DAAL version:', get_daal_version())
3333

34-
exdir = os.path.dirname(os.path.realpath(__file__))
34+
runner_path = os.path.realpath(__file__)
35+
runner_dir = os.path.dirname(runner_path)
36+
examples_rootdir = jp(
37+
os.path.dirname(os.path.abspath(os.path.join(runner_path,
38+
os.pardir))),
39+
'examples')
3540

3641
IS_WIN = False
3742
IS_MAC = False
@@ -52,9 +57,13 @@
5257
assert 8 * struct.calcsize('P') in [32, 64]
5358

5459
if 8 * struct.calcsize('P') == 32:
55-
logdir = jp(exdir, '_results', 'ia32')
60+
logdir = jp(runner_dir, '_results', 'ia32')
5661
else:
57-
logdir = jp(exdir, '_results', 'intel64')
62+
logdir = jp(runner_dir, '_results', 'intel64')
63+
64+
ex_log_dirs = [
65+
(jp(examples_rootdir, 'daal4py'), jp(logdir, 'daal4py')),
66+
(jp(examples_rootdir, 'sklearnex'), jp(logdir, 'sklearnex'))]
5867

5968
availabe_devices = []
6069

@@ -73,8 +82,8 @@
7382
except RuntimeError:
7483
gpu_available = False
7584
availabe_devices.append("cpu")
76-
#validate that host and cpu devices avaialbe for logging reasons. Examples and
77-
#vaidaton logic assumes that host and cpu devices are always available
85+
# validate that host and cpu devices avaialbe for logging reasons. Examples and
86+
# vaidaton logic assumes that host and cpu devices are always available
7887
print('Sycl gpu device: {}'.format(gpu_available))
7988

8089

@@ -129,14 +138,20 @@ def check_library(rule):
129138
req_version['decision_forest_classification_default_dense_batch.py'] = (2023, 'P', 1)
130139
req_version['decision_forest_classification_traverse_batch.py'] = (2023, 'P', 1)
131140
req_version['decision_forest_regression_hist_batch.py'] = (2021, 'P', 200)
141+
req_version['basic_statistics_spmd.py'] = (2023, 'P', 1)
142+
req_version['linear_regression_spmd.py'] = (2023, 'P', 1)
132143

133144
req_device = defaultdict(lambda: [])
145+
req_device['basic_statistics_spmd.py'] = ["gpu"]
146+
req_device['linear_regression_spmd.py'] = ["gpu"]
134147
req_device['sycl/gradient_boosted_regression_batch.py'] = ["gpu"]
135148

136149
req_library = defaultdict(lambda: [])
150+
req_library['basic_statistics_spmd.py'] = ['dpctl', 'mpi4py']
137151
req_library['gbt_cls_model_create_from_lightgbm_batch.py'] = ['lightgbm']
138152
req_library['gbt_cls_model_create_from_xgboost_batch.py'] = ['xgboost']
139153
req_library['gbt_cls_model_create_from_catboost_batch.py'] = ['catboost']
154+
req_library['linear_regression_spmd.py'] = ['dpctl', 'mpi4py']
140155

141156
req_os = defaultdict(lambda: [])
142157

@@ -148,7 +163,8 @@ def get_exe_cmd(ex, nodist, nostream):
148163
if not check_version(req_version["sycl/" + os.path.basename(ex)],
149164
get_daal_version()):
150165
return None
151-
if not check_device(req_device["sycl/" + os.path.basename(ex)], availabe_devices):
166+
if not check_device(
167+
req_device["sycl/" + os.path.basename(ex)], availabe_devices):
152168
return None
153169
if not check_os(req_os["sycl/" + os.path.basename(ex)], system_os):
154170
return None
@@ -158,6 +174,14 @@ def get_exe_cmd(ex, nodist, nostream):
158174
return None
159175
if not check_library(req_library[os.path.basename(ex)]):
160176
return None
177+
if os.path.dirname(ex).endswith("sklearnex") and not nodist and \
178+
ex.endswith('spmd.py'):
179+
if not check_device(req_device[os.path.basename(ex)], availabe_devices):
180+
return None
181+
if not check_version(req_version[os.path.basename(ex)], get_daal_version()):
182+
return None
183+
if not check_library(req_library[os.path.basename(ex)]):
184+
return None
161185
if any(ex.endswith(x) for x in ['batch.py', 'stream.py']):
162186
return '"' + sys.executable + '" "' + ex + '"'
163187
if not nostream and ex.endswith('streaming.py'):
@@ -169,7 +193,7 @@ def get_exe_cmd(ex, nodist, nostream):
169193
return None
170194

171195

172-
def run_all(nodist=False, nostream=False):
196+
def run(exdir, logdir, nodist=False, nostream=False):
173197
success = 0
174198
n = 0
175199
if not os.path.exists(logdir):
@@ -184,7 +208,8 @@ def run_all(nodist=False, nostream=False):
184208
logfn = jp(logdir, script.replace('.py', '.res'))
185209
with open(logfn, 'w') as logfile:
186210
print('\n##### ' + jp(dirpath, script))
187-
execute_string = get_exe_cmd(jp(dirpath, script), nodist, nostream)
211+
execute_string = get_exe_cmd(jp(dirpath, script),
212+
nodist, nostream)
188213
if execute_string:
189214
os.chdir(dirpath)
190215
proc = subprocess.Popen(
@@ -201,20 +226,32 @@ def run_all(nodist=False, nostream=False):
201226
print(out)
202227
print(
203228
strftime("%H:%M:%S", gmtime()) + '\tFAILED'
204-
'\t' + script + '\twith errno\t' + str(proc.returncode)
229+
'\t' + script + '\twith errno'
230+
'\t' + str(proc.returncode)
205231
)
206232
else:
207233
success += 1
208-
print(strftime("%H:%M:%S", gmtime()) + '\tPASSED\t' + script)
234+
print(strftime("%H:%M:%S", gmtime()) + '\t'
235+
'PASSED\t' + script)
209236
else:
210237
success += 1
211238
print(strftime("%H:%M:%S", gmtime()) + '\tSKIPPED\t' + script)
239+
return success, n
240+
212241

213-
if success != n:
214-
print('{}/{} examples passed/skipped, {} failed'.format(success, n, n - success))
242+
def run_all(nodist=False, nostream=False):
243+
success = 0
244+
num = 0
245+
for edir, ldir in ex_log_dirs:
246+
s, n = run(edir, ldir, nodist, nostream)
247+
success += s
248+
num += n
249+
if success != num:
250+
print('{}/{} examples passed/skipped, '
251+
'{} failed'.format(success, num, num - success))
215252
print('Error(s) occured. Logs can be found in ' + logdir)
216253
return 4711
217-
print('{}/{} examples passed/skipped'.format(success, n))
254+
print('{}/{} examples passed/skipped'.format(success, num))
218255
return 0
219256

220257

0 commit comments

Comments
 (0)