Skip to content

Commit 204c059

Browse files
Linter changes, update copyright year
Moved test_get_version and test_get_version_string to the end of the test file with comment for why. Expanded return statuses from cbwr_set which we do not consider test failure, with comment added.
1 parent 18c0627 commit 204c059

File tree

5 files changed

+103
-30
lines changed

5 files changed

+103
-30
lines changed

mkl/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018-2019, Intel Corporation
1+
# Copyright (c) 2018-2024, Intel Corporation
22
#
33
# Redistribution and use in source and binary forms, with or without
44
# modification, are permitted provided that the following conditions are met:

mkl/_mkl_service.pxd

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018-2019, Intel Corporation
1+
# Copyright (c) 2018-2024, Intel Corporation
22
#
33
# Redistribution and use in source and binary forms, with or without
44
# modification, are permitted provided that the following conditions are met:

mkl/_mkl_service.pyx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018-2019, Intel Corporation
1+
# Copyright (c) 2018-2024, Intel Corporation
22
#
33
# Redistribution and use in source and binary forms, with or without
44
# modification, are permitted provided that the following conditions are met:

mkl/tests/test_mkl_service.py

+99-26
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018-2019, Intel Corporation
1+
# Copyright (c) 2018-2024, Intel Corporation
22
#
33
# Redistribution and use in source and binary forms, with or without
44
# modification, are permitted provided that the following conditions are met:
@@ -28,27 +28,14 @@
2828
import mkl
2929

3030

31-
def test_get_version():
32-
v = mkl.get_version()
33-
assert isinstance(v, dict)
34-
assert 'MajorVersion' in v
35-
assert 'MinorVersion' in v
36-
assert 'UpdateVersion' in v
37-
38-
39-
def test_get_version_string():
40-
v = mkl.get_version_string()
41-
assert isinstance(v, str)
42-
assert 'Math Kernel Library' in v
43-
44-
4531
def test_set_num_threads():
4632
saved = mkl.get_max_threads()
47-
half_nt = int( (1 + saved) / 2 )
33+
half_nt = int( (1 + saved) / 2 )
4834
mkl.set_num_threads(half_nt)
4935
assert mkl.get_max_threads() == half_nt
5036
mkl.set_num_threads(saved)
5137

38+
5239
def test_domain_set_num_threads_blas():
5340
saved_blas_nt = mkl.domain_get_max_threads(domain='blas')
5441
saved_fft_nt = mkl.domain_get_max_threads(domain='fft')
@@ -75,22 +62,27 @@ def test_domain_set_num_threads_blas():
7562
status = mkl.domain_set_num_threads(saved_vml_nt, domain='vml')
7663
assert status == 'success'
7764

65+
7866
def test_domain_set_num_threads_fft():
7967
status = mkl.domain_set_num_threads(4, domain='fft')
8068
assert status == 'success'
8169

70+
8271
def test_domain_set_num_threads_vml():
8372
status = mkl.domain_set_num_threads(4, domain='vml')
8473
assert status == 'success'
8574

75+
8676
def test_domain_set_num_threads_pardiso():
8777
status = mkl.domain_set_num_threads(4, domain='pardiso')
8878
assert status == 'success'
8979

80+
9081
def test_domain_set_num_threads_all():
9182
status = mkl.domain_set_num_threads(4, domain='all')
9283
assert status == 'success'
9384

85+
9486
def test_set_num_threads_local():
9587
mkl.set_num_threads(1)
9688
status = mkl.set_num_threads_local(2)
@@ -102,27 +94,35 @@ def test_set_num_threads_local():
10294
status = mkl.set_num_threads_local(8)
10395
assert status == 'global_num_threads'
10496

97+
10598
def test_set_dynamic():
10699
mkl.set_dynamic(True)
107100

101+
108102
def test_get_max_threads():
109103
mkl.get_max_threads()
110104

105+
111106
def test_domain_get_max_threads_blas():
112107
mkl.domain_get_max_threads(domain='blas')
113108

109+
114110
def test_domain_get_max_threads_fft():
115111
mkl.domain_get_max_threads(domain='fft')
116112

113+
117114
def test_domain_get_max_threads_vml():
118115
mkl.domain_get_max_threads(domain='vml')
119116

117+
120118
def test_domain_get_max_threads_pardiso():
121119
mkl.domain_get_max_threads(domain='pardiso')
122120

121+
123122
def test_domain_get_max_threads_all():
124123
mkl.domain_get_max_threads(domain='all')
125124

125+
126126
def test_get_dynamic():
127127
mkl.get_dynamic()
128128

@@ -134,54 +134,80 @@ def test_second():
134134
delta = s2 - s1
135135
assert delta >= 0
136136

137+
137138
def test_dsecnd():
138139
d1 = mkl.dsecnd()
139140
d2 = mkl.dsecnd()
140141
delta = d2 - d1
141142
assert delta >= 0
142143

144+
143145
def test_get_cpu_clocks():
144146
c1 = mkl.get_cpu_clocks()
145147
c2 = mkl.get_cpu_clocks()
146148
delta = c2 - c1
147149
assert delta >= 0
148150

151+
149152
def test_get_cpu_frequency():
150153
assert mkl.get_cpu_frequency() >= 0
151154

155+
152156
def test_get_max_cpu_frequency():
153157
assert mkl.get_max_cpu_frequency() >= 0
154158

159+
155160
def test_get_clocks_frequency():
156161
assert mkl.get_clocks_frequency() >= 0
157162

158163

159164
def test_free_buffers():
160165
mkl.free_buffers()
161166

167+
162168
def test_thread_free_buffers():
163169
mkl.thread_free_buffers()
164170

171+
165172
def test_disable_fast_mm():
166173
mkl.disable_fast_mm()
167174

175+
168176
def test_mem_stat():
169177
mkl.mem_stat()
170178

179+
171180
def test_peak_mem_usage_enable():
172181
mkl.peak_mem_usage('enable')
173182

183+
174184
def test_peak_mem_usage_disable():
175185
mkl.peak_mem_usage('disable')
176186

187+
177188
def test_peak_mem_usage_peak_mem():
178189
mkl.peak_mem_usage('peak_mem')
179190

191+
180192
def test_peak_mem_usage_peak_mem_reset():
181193
mkl.peak_mem_usage('peak_mem_reset')
182194

195+
183196
def test_set_memory_limit():
184-
mkl.set_memory_limit(128)
197+
mkl.set_memory_limit(2**16)
198+
199+
200+
def check_cbwr(branch, cnr_const):
201+
status = mkl.cbwr_set(branch=branch)
202+
if status == 'success':
203+
expected_value = 'branch_off' if branch == 'off' else branch
204+
actual_value = mkl.cbwr_get(cnr_const=cnr_const)
205+
assert actual_value == expected_value, \
206+
f"Round-trip failure for CNR branch '{branch}', CNR const '{cnr_const}"
207+
elif status not in ['err_unsupported_branch', 'err_mode_change_failure']:
208+
# if MKL has been initialized already,
209+
# setting CBWR will error with mode_change_failure
210+
pytest.fail(status)
185211

186212

187213
branches = [
@@ -200,29 +226,25 @@ def test_set_memory_limit():
200226
'avx512_mic_e1',
201227
'avx512_e1',
202228
]
229+
230+
203231
strict = [
204232
'avx2,strict',
205233
'avx512_mic,strict',
206234
'avx512,strict',
207235
'avx512_e1,strict',
208236
]
237+
238+
209239
@pytest.mark.parametrize('branch', branches)
210240
def test_cbwr_branch(branch):
211241
check_cbwr(branch, 'branch')
212242

243+
213244
@pytest.mark.parametrize('branch', branches + strict)
214245
def test_cbwr_all(branch):
215246
check_cbwr(branch, 'all')
216247

217-
def check_cbwr(branch, cnr_const):
218-
status = mkl.cbwr_set(branch=branch)
219-
if status == 'success':
220-
expected_value = 'branch_off' if branch == 'off' else branch
221-
actual_value = mkl.cbwr_get(cnr_const=cnr_const)
222-
assert actual_value == expected_value, \
223-
f"Round-trip failure for CNR branch '{branch}', CNR const '{cnr_const}"
224-
elif status != 'err_unsupported_branch':
225-
pytest.fail(status)
226248

227249
def test_cbwr_get_auto_branch():
228250
mkl.cbwr_get_auto_branch()
@@ -231,45 +253,58 @@ def test_cbwr_get_auto_branch():
231253
def test_enable_instructions_avx512_mic_e1():
232254
mkl.enable_instructions('avx512_mic_e1')
233255

256+
234257
def test_enable_instructions_avx512():
235258
mkl.enable_instructions('avx512')
236259

260+
237261
def test_enable_instructions_avx512_mic():
238262
mkl.enable_instructions('avx512_mic')
239263

264+
240265
def test_enable_instructions_avx2():
241266
mkl.enable_instructions('avx2')
242267

268+
243269
def test_enable_instructions_avx():
244270
mkl.enable_instructions('avx')
245271

272+
246273
def test_enable_instructions_sse4_2():
247274
mkl.enable_instructions('sse4_2')
248275

276+
249277
def test_set_env_mode():
250278
mkl.set_env_mode()
251279

280+
252281
def test_get_env_mode():
253282
mkl.get_env_mode()
254283

284+
255285
def test_verbose_false():
256286
mkl.verbose(False)
257287

288+
258289
def test_verbose_true():
259290
mkl.verbose(True)
260291

292+
261293
@pytest.mark.skip(reason="Skipping MPI-related test")
262294
def test_set_mpi_custom():
263295
mkl.set_mpi('custom', 'custom_library_name')
264296

297+
265298
@pytest.mark.skip(reason="Skipping MPI-related test")
266299
def test_set_mpi_msmpi():
267300
mkl.set_mpi('msmpi')
268301

302+
269303
@pytest.mark.skip(reason="Skipping MPI-related test")
270304
def test_set_mpi_intelmpi():
271305
mkl.set_mpi('intelmpi')
272306

307+
273308
@pytest.mark.skip(reason="Skipping MPI-related test")
274309
def test_set_mpi_mpich2():
275310
mkl.set_mpi('mpich2')
@@ -279,53 +314,91 @@ def test_vml_set_get_mode_roundtrip():
279314
saved = mkl.vml_get_mode()
280315
mkl.vml_set_mode(*saved) # should not raise errors
281316

317+
282318
def test_vml_set_mode_ha_on_ignore():
283319
mkl.vml_set_mode('ha', 'on', 'ignore')
284320

321+
285322
def test_vml_set_mode_ha_on_errno():
286323
mkl.vml_set_mode('ha', 'on', 'errno')
287324

325+
288326
def test_vml_set_mode_la_on_stderr():
289327
mkl.vml_set_mode('la', 'on', 'stderr')
290328

329+
291330
def test_vml_set_mode_la_off_except():
292331
mkl.vml_set_mode('la', 'off', 'except')
293332

333+
294334
def test_vml_set_mode_op_off_callback():
295335
mkl.vml_set_mode('ep', 'off', 'callback')
296336

337+
297338
def test_vml_set_mode_ep_off_default():
298339
mkl.vml_set_mode('ep', 'off', 'default')
299340

341+
300342
def test_vml_get_mode():
301343
mkl.vml_get_mode()
302344

345+
303346
def test_vml_set_err_status_ok():
304347
mkl.vml_set_err_status('ok')
305348

349+
306350
def test_vml_set_err_status_accuracywarning():
307351
mkl.vml_set_err_status('accuracywarning')
308352

353+
309354
def test_vml_set_err_status_badsize():
310355
mkl.vml_set_err_status('badsize')
311356

357+
312358
def test_vml_set_err_status_badmem():
313359
mkl.vml_set_err_status('badmem')
314360

361+
315362
def test_vml_set_err_status_errdom():
316363
mkl.vml_set_err_status('errdom')
317364

365+
318366
def test_vml_set_err_status_sing():
319367
mkl.vml_set_err_status('sing')
320368

369+
321370
def test_vml_set_err_status_overflow():
322371
mkl.vml_set_err_status('overflow')
323372

373+
324374
def test_vml_set_err_status_underflow():
325375
mkl.vml_set_err_status('underflow')
326376

377+
327378
def test_vml_get_err_status():
328379
mkl.vml_get_err_status()
329380

381+
330382
def test_vml_clear_err_status():
331383
mkl.vml_clear_err_status()
384+
385+
386+
def test_get_version():
387+
"""
388+
Version info sets mode of MKL library, such as
389+
instruction pathways and conditional numerical
390+
reproducibility regime. This test is moved to
391+
the bottom to allow proper testing of functions
392+
controllign those.
393+
"""
394+
v = mkl.get_version()
395+
assert isinstance(v, dict)
396+
assert 'MajorVersion' in v
397+
assert 'MinorVersion' in v
398+
assert 'UpdateVersion' in v
399+
400+
401+
def test_get_version_string():
402+
v = mkl.get_version_string()
403+
assert isinstance(v, str)
404+
assert 'Math Kernel Library' in v

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python
2-
# Copyright (c) 2018-2019, Intel Corporation
2+
# Copyright (c) 2018-2024, Intel Corporation
33
#
44
# Redistribution and use in source and binary forms, with or without
55
# modification, are permitted provided that the following conditions are met:

0 commit comments

Comments
 (0)