Skip to content

Commit

Permalink
Linter changes, update copyright year
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
oleksandr-pavlyk committed Feb 12, 2024
1 parent 18c0627 commit 204c059
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 30 deletions.
2 changes: 1 addition & 1 deletion mkl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2018-2019, Intel Corporation
# Copyright (c) 2018-2024, Intel Corporation
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
Expand Down
2 changes: 1 addition & 1 deletion mkl/_mkl_service.pxd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2018-2019, Intel Corporation
# Copyright (c) 2018-2024, Intel Corporation
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
Expand Down
2 changes: 1 addition & 1 deletion mkl/_mkl_service.pyx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2018-2019, Intel Corporation
# Copyright (c) 2018-2024, Intel Corporation
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
Expand Down
125 changes: 99 additions & 26 deletions mkl/tests/test_mkl_service.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2018-2019, Intel Corporation
# Copyright (c) 2018-2024, Intel Corporation
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -28,27 +28,14 @@
import mkl


def test_get_version():
v = mkl.get_version()
assert isinstance(v, dict)
assert 'MajorVersion' in v
assert 'MinorVersion' in v
assert 'UpdateVersion' in v


def test_get_version_string():
v = mkl.get_version_string()
assert isinstance(v, str)
assert 'Math Kernel Library' in v


def test_set_num_threads():
saved = mkl.get_max_threads()
half_nt = int( (1 + saved) / 2 )
half_nt = int( (1 + saved) / 2 )
mkl.set_num_threads(half_nt)
assert mkl.get_max_threads() == half_nt
mkl.set_num_threads(saved)


def test_domain_set_num_threads_blas():
saved_blas_nt = mkl.domain_get_max_threads(domain='blas')
saved_fft_nt = mkl.domain_get_max_threads(domain='fft')
Expand All @@ -75,22 +62,27 @@ def test_domain_set_num_threads_blas():
status = mkl.domain_set_num_threads(saved_vml_nt, domain='vml')
assert status == 'success'


def test_domain_set_num_threads_fft():
status = mkl.domain_set_num_threads(4, domain='fft')
assert status == 'success'


def test_domain_set_num_threads_vml():
status = mkl.domain_set_num_threads(4, domain='vml')
assert status == 'success'


def test_domain_set_num_threads_pardiso():
status = mkl.domain_set_num_threads(4, domain='pardiso')
assert status == 'success'


def test_domain_set_num_threads_all():
status = mkl.domain_set_num_threads(4, domain='all')
assert status == 'success'


def test_set_num_threads_local():
mkl.set_num_threads(1)
status = mkl.set_num_threads_local(2)
Expand All @@ -102,27 +94,35 @@ def test_set_num_threads_local():
status = mkl.set_num_threads_local(8)
assert status == 'global_num_threads'


def test_set_dynamic():
mkl.set_dynamic(True)


def test_get_max_threads():
mkl.get_max_threads()


def test_domain_get_max_threads_blas():
mkl.domain_get_max_threads(domain='blas')


def test_domain_get_max_threads_fft():
mkl.domain_get_max_threads(domain='fft')


def test_domain_get_max_threads_vml():
mkl.domain_get_max_threads(domain='vml')


def test_domain_get_max_threads_pardiso():
mkl.domain_get_max_threads(domain='pardiso')


def test_domain_get_max_threads_all():
mkl.domain_get_max_threads(domain='all')


def test_get_dynamic():
mkl.get_dynamic()

Expand All @@ -134,54 +134,80 @@ def test_second():
delta = s2 - s1
assert delta >= 0


def test_dsecnd():
d1 = mkl.dsecnd()
d2 = mkl.dsecnd()
delta = d2 - d1
assert delta >= 0


def test_get_cpu_clocks():
c1 = mkl.get_cpu_clocks()
c2 = mkl.get_cpu_clocks()
delta = c2 - c1
assert delta >= 0


def test_get_cpu_frequency():
assert mkl.get_cpu_frequency() >= 0


def test_get_max_cpu_frequency():
assert mkl.get_max_cpu_frequency() >= 0


def test_get_clocks_frequency():
assert mkl.get_clocks_frequency() >= 0


def test_free_buffers():
mkl.free_buffers()


def test_thread_free_buffers():
mkl.thread_free_buffers()


def test_disable_fast_mm():
mkl.disable_fast_mm()


def test_mem_stat():
mkl.mem_stat()


def test_peak_mem_usage_enable():
mkl.peak_mem_usage('enable')


def test_peak_mem_usage_disable():
mkl.peak_mem_usage('disable')


def test_peak_mem_usage_peak_mem():
mkl.peak_mem_usage('peak_mem')


def test_peak_mem_usage_peak_mem_reset():
mkl.peak_mem_usage('peak_mem_reset')


def test_set_memory_limit():
mkl.set_memory_limit(128)
mkl.set_memory_limit(2**16)


def check_cbwr(branch, cnr_const):
status = mkl.cbwr_set(branch=branch)
if status == 'success':
expected_value = 'branch_off' if branch == 'off' else branch
actual_value = mkl.cbwr_get(cnr_const=cnr_const)
assert actual_value == expected_value, \
f"Round-trip failure for CNR branch '{branch}', CNR const '{cnr_const}"
elif status not in ['err_unsupported_branch', 'err_mode_change_failure']:
# if MKL has been initialized already,
# setting CBWR will error with mode_change_failure
pytest.fail(status)


branches = [
Expand All @@ -200,29 +226,25 @@ def test_set_memory_limit():
'avx512_mic_e1',
'avx512_e1',
]


strict = [
'avx2,strict',
'avx512_mic,strict',
'avx512,strict',
'avx512_e1,strict',
]


@pytest.mark.parametrize('branch', branches)
def test_cbwr_branch(branch):
check_cbwr(branch, 'branch')


@pytest.mark.parametrize('branch', branches + strict)
def test_cbwr_all(branch):
check_cbwr(branch, 'all')

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

def test_cbwr_get_auto_branch():
mkl.cbwr_get_auto_branch()
Expand All @@ -231,45 +253,58 @@ def test_cbwr_get_auto_branch():
def test_enable_instructions_avx512_mic_e1():
mkl.enable_instructions('avx512_mic_e1')


def test_enable_instructions_avx512():
mkl.enable_instructions('avx512')


def test_enable_instructions_avx512_mic():
mkl.enable_instructions('avx512_mic')


def test_enable_instructions_avx2():
mkl.enable_instructions('avx2')


def test_enable_instructions_avx():
mkl.enable_instructions('avx')


def test_enable_instructions_sse4_2():
mkl.enable_instructions('sse4_2')


def test_set_env_mode():
mkl.set_env_mode()


def test_get_env_mode():
mkl.get_env_mode()


def test_verbose_false():
mkl.verbose(False)


def test_verbose_true():
mkl.verbose(True)


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


@pytest.mark.skip(reason="Skipping MPI-related test")
def test_set_mpi_msmpi():
mkl.set_mpi('msmpi')


@pytest.mark.skip(reason="Skipping MPI-related test")
def test_set_mpi_intelmpi():
mkl.set_mpi('intelmpi')


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


def test_vml_set_mode_ha_on_ignore():
mkl.vml_set_mode('ha', 'on', 'ignore')


def test_vml_set_mode_ha_on_errno():
mkl.vml_set_mode('ha', 'on', 'errno')


def test_vml_set_mode_la_on_stderr():
mkl.vml_set_mode('la', 'on', 'stderr')


def test_vml_set_mode_la_off_except():
mkl.vml_set_mode('la', 'off', 'except')


def test_vml_set_mode_op_off_callback():
mkl.vml_set_mode('ep', 'off', 'callback')


def test_vml_set_mode_ep_off_default():
mkl.vml_set_mode('ep', 'off', 'default')


def test_vml_get_mode():
mkl.vml_get_mode()


def test_vml_set_err_status_ok():
mkl.vml_set_err_status('ok')


def test_vml_set_err_status_accuracywarning():
mkl.vml_set_err_status('accuracywarning')


def test_vml_set_err_status_badsize():
mkl.vml_set_err_status('badsize')


def test_vml_set_err_status_badmem():
mkl.vml_set_err_status('badmem')


def test_vml_set_err_status_errdom():
mkl.vml_set_err_status('errdom')


def test_vml_set_err_status_sing():
mkl.vml_set_err_status('sing')


def test_vml_set_err_status_overflow():
mkl.vml_set_err_status('overflow')


def test_vml_set_err_status_underflow():
mkl.vml_set_err_status('underflow')


def test_vml_get_err_status():
mkl.vml_get_err_status()


def test_vml_clear_err_status():
mkl.vml_clear_err_status()


def test_get_version():
"""
Version info sets mode of MKL library, such as
instruction pathways and conditional numerical
reproducibility regime. This test is moved to
the bottom to allow proper testing of functions
controllign those.
"""
v = mkl.get_version()
assert isinstance(v, dict)
assert 'MajorVersion' in v
assert 'MinorVersion' in v
assert 'UpdateVersion' in v


def test_get_version_string():
v = mkl.get_version_string()
assert isinstance(v, str)
assert 'Math Kernel Library' in v
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
# Copyright (c) 2018-2019, Intel Corporation
# Copyright (c) 2018-2024, Intel Corporation
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
Expand Down

0 comments on commit 204c059

Please sign in to comment.