diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..adfe1ae --- /dev/null +++ b/.flake8 @@ -0,0 +1,46 @@ +[flake8] +extend-ignore = + # whitespace before ':' (currently conflicts with black formatting): + E203, + # line too long (in docstrings): + E501, + # ‘from module import *’ used; unable to detect undefined names: + F403, + # doc line too long (105 > 80 characters): + W505, + # missing docstring in public module: + D100, + # missing docstring in public class: + D101, + # missing docstring in public method: + D102, + # missing docstring in public function: + D103, + # missing docstring in public package: + D104, + # missing docstring in magic method: + D105, + # missing docstring in __init__: + D107, + # no blank lines allowed after function docstring: + D202, + # 1 blank line required between summary line and description: + D205, + # first line should end with a period: + D400, + # first line should be in imperative mood: + D401, + # first line should not be the function's "signature": + D402, + +per-file-ignores = + mkl/__init__.py: E402, F401, F405 + +filename = *.py, *.pyx, *.pxi, *.pxd +max_line_length = 80 +max-doc-length = 80 +show-source = True + +# Print detailed statistic if any issue detected +count = True +statistics = True diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs new file mode 100644 index 0000000..3ed6a7a --- /dev/null +++ b/.git-blame-ignore-revs @@ -0,0 +1,4 @@ +# $ git config blame.ignoreRevsFile .git-blame-ignore-revs + +# Add pre-commit hooks +9c1fb5bd9b946c2eaaf1ea882e789efcccf66b53 diff --git a/.github/workflows/build-with-clang.yml b/.github/workflows/build-with-clang.yml index 6163694..4f1c09a 100644 --- a/.github/workflows/build-with-clang.yml +++ b/.github/workflows/build-with-clang.yml @@ -73,7 +73,7 @@ jobs: export CFLAGS="${CFLAGS} -fno-fast-math" python setup.py develop - - name: Run mkl-service tests + - name: Run mkl-service tests run: | source ${{ env.ONEAPI_ROOT }}/setvars.sh pytest -s -v --pyargs mkl diff --git a/.github/workflows/conda-package.yml b/.github/workflows/conda-package.yml index bb6a499..ee60e61 100644 --- a/.github/workflows/conda-package.yml +++ b/.github/workflows/conda-package.yml @@ -87,7 +87,7 @@ jobs: uses: styfle/cancel-workflow-action@0.12.1 with: access_token: ${{ github.token }} - + - uses: actions/checkout@v4.1.7 with: fetch-depth: 0 @@ -114,7 +114,7 @@ jobs: - name: Build conda package run: conda build --no-test --python ${{ matrix.python }} -c https://software.repos.intel.com/python/conda -c conda-forge --override-channels conda-recipe - + - name: Upload artifact uses: actions/upload-artifact@v4.6.2 with: @@ -254,9 +254,9 @@ jobs: restore-keys: | ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-python-${{ matrix.python }}- ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}- - + # add intel-openmp as an explicit dependency - # to avoid it being missed when package version is specified exactly + # to avoid it being missed when package version is specified exactly - name: Install mkl-service shell: cmd run: | diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 0000000..b47cb29 --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,38 @@ +name: pre-commit + +on: + pull_request: + push: + branches: [master] + +permissions: read-all + +jobs: + pre-commit: + runs-on: ubuntu-latest + timeout-minutes: 30 + steps: + - name: Checkout repo + uses: actions/checkout@v4.2.2 + + - name: Set up python + uses: actions/setup-python@v5 + with: + python-version: '3.12' + + - name: Set up pip packages + uses: BSFishy/pip-action@v1 + with: + packages: | + codespell + pylint + + - name: Set up clang-format + run: | + sudo apt-get install -y clang-format-14 + sudo unlink /usr/bin/clang-format + sudo ln -s /usr/bin/clang-format-14 /usr/bin/clang-format + clang-format --version + + - name: Run pre-commit checks + uses: pre-commit/action@v3.0.1 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..aa05d6c --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,103 @@ +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.0.0 + hooks: + - id: check-ast + - id: check-builtin-literals + - id: check-case-conflict + - id: check-executables-have-shebangs + - id: check-merge-conflict + - id: check-toml + - id: debug-statements + - id: destroyed-symlinks + - id: end-of-file-fixer + - id: fix-byte-order-marker + - id: mixed-line-ending + - id: trailing-whitespace + +- repo: https://github.com/pre-commit/pygrep-hooks + rev: v1.10.0 + hooks: + - id: python-check-blanket-noqa + - id: python-check-blanket-type-ignore + - id: python-check-mock-methods + - id: python-no-eval + - id: python-no-log-warn + - id: python-use-type-annotations + - id: rst-backticks + - id: rst-directive-colons + - id: rst-inline-touching-normal + - id: text-unicode-replacement-char + +- repo: https://github.com/codespell-project/codespell + rev: v2.4.1 + hooks: + - id: codespell + additional_dependencies: + - tomli + +- repo: https://github.com/psf/black + rev: 25.1.0 + hooks: + - id: black + exclude: "_vendored/conv_template.py" + +- repo: https://github.com/pocc/pre-commit-hooks + rev: v1.3.5 + hooks: + - id: clang-format + args: ["-i"] + +- repo: https://github.com/MarcoGorelli/cython-lint + rev: v0.16.6 + hooks: + - id: cython-lint + - id: double-quote-cython-strings + +- repo: https://github.com/pycqa/flake8 + rev: 7.1.2 + hooks: + - id: flake8 + args: ["--config=.flake8"] + additional_dependencies: + - flake8-docstrings==1.7.0 + - flake8-bugbear==24.4.26 + +- repo: https://github.com/pycqa/isort + rev: 6.0.1 + hooks: + - id: isort + name: isort (python) + - id: isort + name: isort (cython) + types: [cython] + - id: isort + name: isort (pyi) + types: [pyi] + +- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks + rev: v2.14.0 + hooks: + - id: pretty-format-toml + args: [--autofix] + +- repo: local + hooks: + - id: pylint + name: pylint + entry: pylint + language: system + types: [python] + require_serial: true + args: + [ + "-rn", # Only display messages + "-sn", # Don't display the score + "--errors-only", + "--disable=import-error", + ] + +- repo: https://github.com/jumanjihouse/pre-commit-hooks + rev: 3.0.0 + hooks: + - id: shellcheck diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f2c9e6..756af54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,53 +1,51 @@ -`mkl-service` changelog -======================= +# changelog +All notable changes to this project will be documented in this file. -[dev] (MM/DD/YY) -================ +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -Migrated from `setup.py` to `pyproject.toml` +## [dev] (MM/DD/YY) -Added support for python 3.13 +### Added +* Added support for python 3.13 [gh-72](github.com/IntelPython/mkl-service/pull/72) -2.3.0 -===== +### Changed +* Migrated from `setup.py` to `pyproject.toml` [gh-66](github.com/IntelPython/mkl-service/pull/66) + + +## [2.3.0] Fixed CI to actually execute tests. Populated CBWR constants to match MKL headers. Added tests checking that `cbwr_set` and `cbwr_get` round-trip. -2.2.0 -===== +## [2.2.0] -Closed issues #8, #7 and #5. +Closed issues #8, #7 and #5. Extended `mkl.cbwr_set` to recognize `'avx512_e1'`, `'avx512_mic_e1'`, as as strict conditional numerical reproducibility, supported via `'avx2,strict'`, `'avx512,strict'` (see [issue/8](http://github.com/IntelPython/mkl-service/issues/8)). Extended `mkl.cbwrt_get()` to mean `mkl.cbwr('all')`. -2.1.0 -===== +## [2.1.0] Change in setup script to not use `numpy.distutils` thus removing numpy as build-time dependency. -Change in conda-recipe to allow conda build to build the recipe, but ignoring run export on mkl-service coming from mkl-devel metadata. +Change in conda-recipe to allow conda build to build the recipe, but ignoring run export on mkl-service coming from mkl-devel metadata. -2.0.2 -===== +## [2.0.2] Correction to `setup.py` to not require Cython at the installation time. -2.0.1 -===== +## [2.0.1] Re-release, with some changes necessary for public CI builds to work. -2.0.0 -===== +## [2.0.0] Work-around for VS 9.0 not having `inline` keyword, allowing the package to build on Windows for Python 2.7 -2.0.0 -===== +## [2.0.0] Rerelease of `mkl-service` package with version bumped to 2.0.0 to avoid version clash with `mkl-service` package from Anaconda. @@ -57,7 +55,6 @@ Loading the package with `import mkl` initializes Intel(R) MKL library to use LP The choice of threading layer can be controlled with environment variable `MKL_THREADING_LAYER`. However the unset variable is interpreted differently that in Intel(R) MKL itself. If `mkl-service` detects that Gnu OpenMP has been loaded in Python space, the threading layer of Intle(R) MKL will be set to Gnu OpenMP, instead of Intel(R) OpenMP. -1.0.0 -===== +## [1.0.0] Initial release of `mkl-service` package. diff --git a/examples/example.py b/examples/example.py index afaac59..ad036f3 100644 --- a/examples/example.py +++ b/examples/example.py @@ -23,39 +23,45 @@ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# pylint: disable=no-member -import mkl import re +import mkl + def enable_best_instructions_set(): - for instructions_set in ['avx512', 'avx2', 'avx', 'sse4_2']: - if mkl.enable_instructions(instructions_set) == 'success': + for instructions_set in ["avx512", "avx2", "avx", "sse4_2"]: + if mkl.enable_instructions(instructions_set) == "success": result = instructions_set break else: - result = 'error' + result = "error" return result def is_max_supported_instructions_set(instructions_set): result = False - if re.search(instructions_set.replace('4_2', '4.2'), mkl.get_version()['Processor'].decode(), re.IGNORECASE): + if re.search( + instructions_set.replace("4_2", "4.2"), + mkl.get_version()["Processor"].decode(), + re.IGNORECASE, + ): result = True return result -if __name__ == '__main__': +if __name__ == "__main__": time_begin = mkl.dsecnd() print(mkl.get_version_string()) instructions_set = enable_best_instructions_set() - print('Enable snstructions set: ' + str(instructions_set)) + print("Enable snstructions set: " + str(instructions_set)) is_max = is_max_supported_instructions_set(instructions_set) - print('Is the best supported instructions set: ' + str(is_max)) + print("Is the best supported instructions set: " + str(is_max)) time_end = mkl.dsecnd() - print('Execution time: ' + str(time_end - time_begin)) + print("Execution time: " + str(time_end - time_begin)) diff --git a/mkl/__init__.py b/mkl/__init__.py index 61af8ac..4a86a64 100644 --- a/mkl/__init__.py +++ b/mkl/__init__.py @@ -25,16 +25,19 @@ import sys -class RTLD_for_MKL(): + +class RTLD_for_MKL: def __init__(self): self.saved_rtld = None def __enter__(self): import ctypes + try: self.saved_rtld = sys.getdlopenflags() - # python loads libraries with RTLD_LOCAL, but MKL requires RTLD_GLOBAL - # pre-load MKL with RTLD_GLOBAL before loading the native extension + # python loads libraries with RTLD_LOCAL, but MKL requires + # RTLD_GLOBAL pre-load MKL with RTLD_GLOBAL before loading + # the native extension sys.setdlopenflags(self.saved_rtld | ctypes.RTLD_GLOBAL) except AttributeError: pass @@ -45,6 +48,7 @@ def __exit__(self, *args): sys.setdlopenflags(self.saved_rtld) self.saved_rtld = None + with RTLD_for_MKL(): from . import _mklinit diff --git a/mkl/_mkl_service.pyx b/mkl/_mkl_service.pyx index c6cd8a9..b8600cb 100644 --- a/mkl/_mkl_service.pyx +++ b/mkl/_mkl_service.pyx @@ -33,7 +33,7 @@ cimport mkl._mkl_service as mkl cdef extern from *: """ - /* defind MKL_BLACS_MPICH2 if undefined */ + /* define MKL_BLACS_MPICH2 if undefined */ #ifndef MKL_BLACS_MPICH2 #define MKL_BLACS_MPICH2 -1 #endif @@ -65,27 +65,29 @@ cpdef set_num_threads(num_threads): """ Specifies the number of OpenMP* threads to use. """ - cdef int c_num_threads = __python_obj_to_int(num_threads, 'set_num_threads') - __check_positive_num_threads(c_num_threads, 'set_num_threads') + cdef int c_num_threads = __python_obj_to_int(num_threads, "set_num_threads") + __check_positive_num_threads(c_num_threads, "set_num_threads") return __set_num_threads(c_num_threads) cdef int __warn_and_fallback_on_default_domain(domain): - warnings.warn("domain={} is expected to be an integer, a string ('blas', 'fft', " - "'vml', 'pardiso', 'all'). " - "Using domain='all' instead.".format(domain)) + warnings.warn( + f"domain={domain} is expected to be an integer, a string ('blas', " + "'fft', 'vml', 'pardiso', 'all'). Uing domain='all' instead." + ) return mkl.MKL_DOMAIN_ALL cdef int __domain_to_mkl_domain(domain): cdef int c_mkl_domain = mkl.MKL_DOMAIN_ALL _mapping = { - 'blas': mkl.MKL_DOMAIN_BLAS, - 'fft': mkl.MKL_DOMAIN_FFT, - 'vml': mkl.MKL_DOMAIN_VML, - 'pardiso': mkl.MKL_DOMAIN_PARDISO, - 'all': mkl.MKL_DOMAIN_ALL } + "blas": mkl.MKL_DOMAIN_BLAS, + "fft": mkl.MKL_DOMAIN_FFT, + "vml": mkl.MKL_DOMAIN_VML, + "pardiso": mkl.MKL_DOMAIN_PARDISO, + "all": mkl.MKL_DOMAIN_ALL + } if isinstance(domain, numbers.Integral): c_mkl_domain = domain @@ -100,12 +102,12 @@ cdef int __domain_to_mkl_domain(domain): return c_mkl_domain -cpdef domain_set_num_threads(num_threads, domain='all'): +cpdef domain_set_num_threads(num_threads, domain="all"): """ Specifies the number of OpenMP* threads for a particular function domain. """ - cdef c_num_threads = __python_obj_to_int(num_threads, 'domain_set_num_threads') - __check_non_negative_num_threads(c_num_threads, 'domain_set_num_threads') + cdef c_num_threads = __python_obj_to_int(num_threads, "domain_set_num_threads") + __check_non_negative_num_threads(c_num_threads, "domain_set_num_threads") cdef int c_mkl_domain = __domain_to_mkl_domain(domain) cdef int c_mkl_status = __domain_set_num_threads(c_num_threads, c_mkl_domain) @@ -115,21 +117,24 @@ cpdef domain_set_num_threads(num_threads, domain='all'): cpdef set_num_threads_local(num_threads): """ - Specifies the number of OpenMP* threads for all Intel(R) MKL functions on the current execution thread. + Specifies the number of OpenMP* threads for all Intel(R) MKL functions on the + current execution thread. """ cdef c_num_threads = 0 if isinstance(num_threads, str): - if num_threads is not 'global_num_threads': - raise ValueError("The argument of set_num_threads_local is expected " - "to be a non-negative integer or a string 'global_num_threads'") + if num_threads is not "global_num_threads": + raise ValueError( + "The argument of set_num_threads_local is expected " + "to be a non-negative integer or a string 'global_num_threads'" + ) else: - c_num_threads = __python_obj_to_int(num_threads, 'set_num_threads_local') + c_num_threads = __python_obj_to_int(num_threads, "set_num_threads_local") - __check_non_negative_num_threads(c_num_threads, 'set_num_threads_local') + __check_non_negative_num_threads(c_num_threads, "set_num_threads_local") cdef c_prev_num_threads = __set_num_threads_local(c_num_threads) if (c_prev_num_threads == 0): - ret_value = 'global_num_threads' + ret_value = "global_num_threads" else: ret_value = c_prev_num_threads @@ -152,7 +157,7 @@ cpdef get_max_threads(): return __get_max_threads() -cpdef domain_get_max_threads(domain='all'): +cpdef domain_get_max_threads(domain="all"): """ Gets the number of OpenMP* threads targeted for parallelism for a particular function domain. @@ -248,12 +253,13 @@ cpdef get_max_cpu_frequency(): cpdef get_clocks_frequency(): """ Returns the frequency value in GHz based on constant-rate Time Stamp Counter. - + """ return __get_clocks_frequency() -# Memory Management. See the Intel(R) MKL Developer Guide for more memory usage information. +# Memory Management. See the Intel(R) MKL Developer Guide for more memory usage +# information. cpdef free_buffers(): """ Frees unused memory allocated by the Intel(R) MKL Memory Allocator. @@ -263,14 +269,16 @@ cpdef free_buffers(): cpdef thread_free_buffers(): """ - Frees unused memory allocated by the Intel(R) MKL Memory Allocator in the current thread. + Frees unused memory allocated by the Intel(R) MKL Memory Allocator in the current + thread. """ __thread_free_buffers() cpdef disable_fast_mm(): """ - Turns off the Intel(R) MKL Memory Allocator for Intel(R) MKL functions to directly use the system malloc/free functions. + Turns off the Intel(R) MKL Memory Allocator for Intel(R) MKL functions to directly + use the system malloc/free functions. """ return __disable_fast_mm() @@ -291,7 +299,8 @@ cpdef peak_mem_usage(mem_const): cpdef set_memory_limit(limit): """ - On Linux, sets the limit of memory that Intel(R) MKL can allocate for a specified type of memory. + On Linux, sets the limit of memory that Intel(R) MKL can allocate for a specified + type of memory. """ return __set_memory_limit(limit) @@ -304,7 +313,7 @@ cpdef cbwr_set(branch=None): return __cbwr_set(branch) -cpdef cbwr_get(cnr_const='all'): +cpdef cbwr_get(cnr_const="all"): """ Returns the current CNR settings. """ @@ -321,14 +330,16 @@ cpdef cbwr_get_auto_branch(): # Miscellaneous cpdef enable_instructions(isa=None): """ - Enables dispatching for new Intel architectures or restricts the set of Intel instruction sets available for dispatching. + Enables dispatching for new Intel architectures or restricts the set of Intel + instruction sets available for dispatching. """ return __enable_instructions(isa) cpdef set_env_mode(): """ - Sets up the mode that ignores environment settings specific to Intel(R) MKL. See mkl_set_env_mode(1). + Sets up the mode that ignores environment settings specific to Intel(R) MKL. + See mkl_set_env_mode(1). """ return __set_env_mode() @@ -358,7 +369,8 @@ cpdef set_mpi(vendor, custom_library_name=None): # VM Service Functions cpdef vml_set_mode(accuracy, ftzdaz, errmode): """ - Sets a new mode for VM functions according to the mode parameter and stores the previous VM mode to oldmode. + Sets a new mode for VM functions according to the mode parameter and stores the + previous VM mode to oldmode. """ return __vml_set_mode(accuracy, ftzdaz, errmode) @@ -372,7 +384,8 @@ cpdef vml_get_mode(): cpdef vml_set_err_status(status): """ - Sets the new VM Error Status according to err and stores the previous VM Error Status to olderr. + Sets the new VM Error Status according to err and stores the previous VM Error + Status to olderr. """ return __vml_set_err_status(status) @@ -386,21 +399,25 @@ cpdef vml_get_err_status(): cpdef vml_clear_err_status(): """ - Sets the VM Error Status to VML_STATUS_OK and stores the previous VM Error Status to olderr. + Sets the VM Error Status to VML_STATUS_OK and stores the previous VM Error Status + to olderr. """ return __vml_clear_err_status() cdef str __mkl_status_to_string(int mkl_status) noexcept: if mkl_status == 1: - return 'success' + return "success" else: - return 'error' + return "error" cdef int __python_obj_to_int(obj, func_name) except *: if not isinstance(obj, numbers.Integral): - raise ValueError("The argument of " + func_name + " is expected to be a positive integer") + raise ValueError( + "The argument of " + func_name + " is expected to be a positive " + "integer" + ) cdef int c_int = obj return c_int @@ -421,9 +438,12 @@ cdef inline int __mkl_str_to_int(variable, possible_variables_dict) except *: if variable is None: raise ValueError("Variable can not be None") if possible_variables_dict is None: - raise RuntimeError("Dictionary mapping possible variable value to internal code is missing") + raise RuntimeError( + "Dictionary mapping possible variable value to internal code is " + "missing" + ) if variable not in possible_variables_dict: - raise ValueError('Variable: <' + str(variable) + '> not in ' + + raise ValueError("Variable: <" + str(variable) + "> not in " + str(possible_variables_dict.keys())) return possible_variables_dict[variable] @@ -431,10 +451,13 @@ cdef inline int __mkl_str_to_int(variable, possible_variables_dict) except *: cdef __mkl_int_to_str(int mkl_int_variable, possible_variables_dict) except *: if possible_variables_dict is None: - raise RuntimeError("Dictionary mapping possible internal code to output string is missing") + raise RuntimeError( + "Dictionary mapping possible internal code to output string is " + "missing" + ) if mkl_int_variable not in possible_variables_dict: - raise ValueError('Variable: <' + str(mkl_int_variable) + '> not in ' + + raise ValueError("Variable: <" + str(mkl_int_variable) + "> not in " + str(possible_variables_dict.keys())) return possible_variables_dict[mkl_int_variable] @@ -481,7 +504,8 @@ cdef inline int __domain_set_num_threads(int c_num_threads, int mkl_domain) noex cdef inline int __set_num_threads_local(int c_num_threads) noexcept: """ - Specifies the number of OpenMP* threads for all Intel(R) MKL functions on the current execution thread. + Specifies the number of OpenMP* threads for all Intel(R) MKL functions on the + current execution thread. """ cdef int c_mkl_status = mkl.mkl_set_num_threads_local(c_num_threads) @@ -506,7 +530,8 @@ cdef inline int __get_max_threads() noexcept: cdef inline int __domain_get_max_threads(int c_mkl_domain) noexcept: """ - Gets the number of OpenMP* threads targeted for parallelism for a particular function domain. + Gets the number of OpenMP* threads targeted for parallelism for a particular + function domain. """ cdef int c_num_threads = mkl.mkl_domain_get_max_threads(c_mkl_domain) @@ -515,7 +540,8 @@ cdef inline int __domain_get_max_threads(int c_mkl_domain) noexcept: cdef inline int __get_dynamic() noexcept: """ - Determines whether Intel(R) MKL is enabled to dynamically change the number of OpenMP* threads. + Determines whether Intel(R) MKL is enabled to dynamically change the number of + OpenMP* threads. """ return mkl.mkl_get_dynamic() @@ -569,7 +595,8 @@ cdef inline double __get_clocks_frequency() noexcept: return mkl.mkl_get_clocks_frequency() -# Memory Management. See the Intel(R) MKL Developer Guide for more memory usage information. +# Memory Management. See the Intel(R) MKL Developer Guide for more memory usage +# information. cdef inline void __free_buffers() noexcept: """ Frees unused memory allocated by the Intel(R) MKL Memory Allocator. @@ -580,7 +607,8 @@ cdef inline void __free_buffers() noexcept: cdef inline void __thread_free_buffers() noexcept: """ - Frees unused memory allocated by the Intel(R) MKL Memory Allocator in the current thread. + Frees unused memory allocated by the Intel(R) MKL Memory Allocator in the current + thread. """ mkl.mkl_thread_free_buffers() return @@ -588,7 +616,8 @@ cdef inline void __thread_free_buffers() noexcept: cdef inline int __disable_fast_mm() noexcept: """ - Turns off the Intel(R) MKL Memory Allocator for Intel(R) MKL functions to directly use the system malloc/free functions. + Turns off the Intel(R) MKL Memory Allocator for Intel(R) MKL functions to directly + use the system malloc/free functions. """ return mkl.mkl_disable_fast_mm() @@ -607,19 +636,19 @@ cdef object __peak_mem_usage(mem_const) except *: Reports the peak memory allocated by the Intel(R) MKL Memory Allocator. """ __variables = { - 'input': { - 'enable': mkl.MKL_PEAK_MEM_ENABLE, - 'disable': mkl.MKL_PEAK_MEM_DISABLE, - 'peak_mem': mkl.MKL_PEAK_MEM, - 'peak_mem_reset': mkl.MKL_PEAK_MEM_RESET, + "input": { + "enable": mkl.MKL_PEAK_MEM_ENABLE, + "disable": mkl.MKL_PEAK_MEM_DISABLE, + "peak_mem": mkl.MKL_PEAK_MEM, + "peak_mem_reset": mkl.MKL_PEAK_MEM_RESET, } } - cdef int c_mkl_mem_const = __mkl_str_to_int(mem_const, __variables['input']) + cdef int c_mkl_mem_const = __mkl_str_to_int(mem_const, __variables["input"]) cdef mkl.MKL_INT64 c_memory_allocator = mkl.mkl_peak_mem_usage(c_mkl_mem_const) if c_memory_allocator == -1: - memory_allocator = 'error' + memory_allocator = "error" else: memory_allocator = c_memory_allocator return memory_allocator @@ -627,7 +656,8 @@ cdef object __peak_mem_usage(mem_const) except *: cdef inline object __set_memory_limit(limit) except *: """ - On Linux, sets the limit of memory that Intel(R) MKL can allocate for a specified type of memory. + On Linux, sets the limit of memory that Intel(R) MKL can allocate for a specified + type of memory. """ cdef size_t c_limit = limit @@ -641,38 +671,38 @@ cdef object __cbwr_set(branch=None) except *: Configures the CNR mode of Intel(R) MKL. """ __variables = { - 'input': { - 'off': mkl.MKL_CBWR_OFF, - 'branch_off': mkl.MKL_CBWR_BRANCH_OFF, - 'auto': mkl.MKL_CBWR_AUTO, - 'compatible': mkl.MKL_CBWR_COMPATIBLE, - 'sse2': mkl.MKL_CBWR_SSE2, - 'ssse3': mkl.MKL_CBWR_SSSE3, - 'sse4_1': mkl.MKL_CBWR_SSE4_1, - 'sse4_2': mkl.MKL_CBWR_SSE4_2, - 'avx': mkl.MKL_CBWR_AVX, - 'avx2': mkl.MKL_CBWR_AVX2, - 'avx2,strict': mkl.MKL_CBWR_AVX2 | mkl.MKL_CBWR_STRICT, - 'avx512_mic': mkl.MKL_CBWR_AVX512_MIC, - 'avx512_mic,strict': mkl.MKL_CBWR_AVX512_MIC | mkl.MKL_CBWR_STRICT, - 'avx512': mkl.MKL_CBWR_AVX512, - 'avx512,strict': mkl.MKL_CBWR_AVX512 | mkl.MKL_CBWR_STRICT, - 'avx512_mic_e1': mkl.MKL_CBWR_AVX512_MIC_E1, - 'avx512_e1': mkl.MKL_CBWR_AVX512_E1, - 'avx512_e1,strict': mkl.MKL_CBWR_AVX512_E1 | mkl.MKL_CBWR_STRICT, + "input": { + "off": mkl.MKL_CBWR_OFF, + "branch_off": mkl.MKL_CBWR_BRANCH_OFF, + "auto": mkl.MKL_CBWR_AUTO, + "compatible": mkl.MKL_CBWR_COMPATIBLE, + "sse2": mkl.MKL_CBWR_SSE2, + "ssse3": mkl.MKL_CBWR_SSSE3, + "sse4_1": mkl.MKL_CBWR_SSE4_1, + "sse4_2": mkl.MKL_CBWR_SSE4_2, + "avx": mkl.MKL_CBWR_AVX, + "avx2": mkl.MKL_CBWR_AVX2, + "avx2,strict": mkl.MKL_CBWR_AVX2 | mkl.MKL_CBWR_STRICT, + "avx512_mic": mkl.MKL_CBWR_AVX512_MIC, + "avx512_mic,strict": mkl.MKL_CBWR_AVX512_MIC | mkl.MKL_CBWR_STRICT, + "avx512": mkl.MKL_CBWR_AVX512, + "avx512,strict": mkl.MKL_CBWR_AVX512 | mkl.MKL_CBWR_STRICT, + "avx512_mic_e1": mkl.MKL_CBWR_AVX512_MIC_E1, + "avx512_e1": mkl.MKL_CBWR_AVX512_E1, + "avx512_e1,strict": mkl.MKL_CBWR_AVX512_E1 | mkl.MKL_CBWR_STRICT, }, - 'output': { - mkl.MKL_CBWR_SUCCESS: 'success', - mkl.MKL_CBWR_ERR_INVALID_INPUT: 'err_invalid_input', - mkl.MKL_CBWR_ERR_UNSUPPORTED_BRANCH: 'err_unsupported_branch', - mkl.MKL_CBWR_ERR_MODE_CHANGE_FAILURE: 'err_mode_change_failure', + "output": { + mkl.MKL_CBWR_SUCCESS: "success", + mkl.MKL_CBWR_ERR_INVALID_INPUT: "err_invalid_input", + mkl.MKL_CBWR_ERR_UNSUPPORTED_BRANCH: "err_unsupported_branch", + mkl.MKL_CBWR_ERR_MODE_CHANGE_FAILURE: "err_mode_change_failure", }, } - mkl_branch = __mkl_str_to_int(branch, __variables['input']) + mkl_branch = __mkl_str_to_int(branch, __variables["input"]) mkl_status = mkl.mkl_cbwr_set(mkl_branch) - status = __mkl_int_to_str(mkl_status, __variables['output']) + status = __mkl_int_to_str(mkl_status, __variables["output"]) return status @@ -681,36 +711,36 @@ cdef inline __cbwr_get(cnr_const=None) except *: Returns the current CNR settings. """ __variables = { - 'input': { - 'branch': mkl.MKL_CBWR_BRANCH, - 'all': mkl.MKL_CBWR_ALL, + "input": { + "branch": mkl.MKL_CBWR_BRANCH, + "all": mkl.MKL_CBWR_ALL, }, - 'output': { - mkl.MKL_CBWR_BRANCH_OFF: 'branch_off', - mkl.MKL_CBWR_AUTO: 'auto', - mkl.MKL_CBWR_COMPATIBLE: 'compatible', - mkl.MKL_CBWR_SSE2: 'sse2', - mkl.MKL_CBWR_SSSE3: 'ssse3', - mkl.MKL_CBWR_SSE4_1: 'sse4_1', - mkl.MKL_CBWR_SSE4_2: 'sse4_2', - mkl.MKL_CBWR_AVX: 'avx', - mkl.MKL_CBWR_AVX2: 'avx2', - mkl.MKL_CBWR_AVX2 | mkl.MKL_CBWR_STRICT: 'avx2,strict', - mkl.MKL_CBWR_AVX512_MIC: 'avx512_mic', - mkl.MKL_CBWR_AVX512_MIC | mkl.MKL_CBWR_STRICT: 'avx512_mic,strict', - mkl.MKL_CBWR_AVX512: 'avx512', - mkl.MKL_CBWR_AVX512 | mkl.MKL_CBWR_STRICT: 'avx512,strict', - mkl.MKL_CBWR_AVX512_MIC_E1: 'avx512_mic_e1', - mkl.MKL_CBWR_AVX512_E1: 'avx512_e1', - mkl.MKL_CBWR_AVX512_E1 | mkl.MKL_CBWR_STRICT: 'avx512_e1,strict', - mkl.MKL_CBWR_ERR_INVALID_INPUT: 'err_invalid_input', + "output": { + mkl.MKL_CBWR_BRANCH_OFF: "branch_off", + mkl.MKL_CBWR_AUTO: "auto", + mkl.MKL_CBWR_COMPATIBLE: "compatible", + mkl.MKL_CBWR_SSE2: "sse2", + mkl.MKL_CBWR_SSSE3: "ssse3", + mkl.MKL_CBWR_SSE4_1: "sse4_1", + mkl.MKL_CBWR_SSE4_2: "sse4_2", + mkl.MKL_CBWR_AVX: "avx", + mkl.MKL_CBWR_AVX2: "avx2", + mkl.MKL_CBWR_AVX2 | mkl.MKL_CBWR_STRICT: "avx2,strict", + mkl.MKL_CBWR_AVX512_MIC: "avx512_mic", + mkl.MKL_CBWR_AVX512_MIC | mkl.MKL_CBWR_STRICT: "avx512_mic,strict", + mkl.MKL_CBWR_AVX512: "avx512", + mkl.MKL_CBWR_AVX512 | mkl.MKL_CBWR_STRICT: "avx512,strict", + mkl.MKL_CBWR_AVX512_MIC_E1: "avx512_mic_e1", + mkl.MKL_CBWR_AVX512_E1: "avx512_e1", + mkl.MKL_CBWR_AVX512_E1 | mkl.MKL_CBWR_STRICT: "avx512_e1,strict", + mkl.MKL_CBWR_ERR_INVALID_INPUT: "err_invalid_input", }, } - mkl_cnr_const = __mkl_str_to_int(cnr_const, __variables['input']) + mkl_cnr_const = __mkl_str_to_int(cnr_const, __variables["input"]) mkl_status = mkl.mkl_cbwr_get(mkl_cnr_const) - status = __mkl_int_to_str(mkl_status, __variables['output']) + status = __mkl_int_to_str(mkl_status, __variables["output"]) return status @@ -719,57 +749,58 @@ cdef object __cbwr_get_auto_branch() except *: Automatically detects the CNR code branch for your platform. """ __variables = { - 'output': { - mkl.MKL_CBWR_BRANCH_OFF: 'branch_off', - mkl.MKL_CBWR_AUTO: 'auto', - mkl.MKL_CBWR_COMPATIBLE: 'compatible', - mkl.MKL_CBWR_SSE2: 'sse2', - mkl.MKL_CBWR_SSSE3: 'ssse3', - mkl.MKL_CBWR_SSE4_1: 'sse4_1', - mkl.MKL_CBWR_SSE4_2: 'sse4_2', - mkl.MKL_CBWR_AVX: 'avx', - mkl.MKL_CBWR_AVX2: 'avx2', - mkl.MKL_CBWR_AVX2 | mkl.MKL_CBWR_STRICT: 'avx2,strict', - mkl.MKL_CBWR_AVX512_MIC: 'avx512_mic', - mkl.MKL_CBWR_AVX512_MIC | mkl.MKL_CBWR_STRICT: 'avx512_mic,strict', - mkl.MKL_CBWR_AVX512: 'avx512', - mkl.MKL_CBWR_AVX512 | mkl.MKL_CBWR_STRICT: 'avx512,strict', - mkl.MKL_CBWR_AVX512_MIC_E1: 'avx512_mic_e1', - mkl.MKL_CBWR_AVX512_E1: 'avx512_e1', - mkl.MKL_CBWR_AVX512_E1 | mkl.MKL_CBWR_STRICT: 'avx512_e1,strict', - mkl.MKL_CBWR_SUCCESS: 'success', - mkl.MKL_CBWR_ERR_INVALID_INPUT: 'err_invalid_input', + "output": { + mkl.MKL_CBWR_BRANCH_OFF: "branch_off", + mkl.MKL_CBWR_AUTO: "auto", + mkl.MKL_CBWR_COMPATIBLE: "compatible", + mkl.MKL_CBWR_SSE2: "sse2", + mkl.MKL_CBWR_SSSE3: "ssse3", + mkl.MKL_CBWR_SSE4_1: "sse4_1", + mkl.MKL_CBWR_SSE4_2: "sse4_2", + mkl.MKL_CBWR_AVX: "avx", + mkl.MKL_CBWR_AVX2: "avx2", + mkl.MKL_CBWR_AVX2 | mkl.MKL_CBWR_STRICT: "avx2,strict", + mkl.MKL_CBWR_AVX512_MIC: "avx512_mic", + mkl.MKL_CBWR_AVX512_MIC | mkl.MKL_CBWR_STRICT: "avx512_mic,strict", + mkl.MKL_CBWR_AVX512: "avx512", + mkl.MKL_CBWR_AVX512 | mkl.MKL_CBWR_STRICT: "avx512,strict", + mkl.MKL_CBWR_AVX512_MIC_E1: "avx512_mic_e1", + mkl.MKL_CBWR_AVX512_E1: "avx512_e1", + mkl.MKL_CBWR_AVX512_E1 | mkl.MKL_CBWR_STRICT: "avx512_e1,strict", + mkl.MKL_CBWR_SUCCESS: "success", + mkl.MKL_CBWR_ERR_INVALID_INPUT: "err_invalid_input", }, } mkl_status = mkl.mkl_cbwr_get_auto_branch() - status = __mkl_int_to_str(mkl_status, __variables['output']) + status = __mkl_int_to_str(mkl_status, __variables["output"]) return status # Miscellaneous cdef object __enable_instructions(isa=None) except *: """ - Enables dispatching for new Intel architectures or restricts the set of Intel instruction sets available for dispatching. + Enables dispatching for new Intel architectures or restricts the set of Intel + instruction sets available for dispatching. """ __variables = { - 'input': { - 'single_path': mkl.MKL_SINGLE_PATH_ENABLE, - 'avx512_e4': mkl.MKL_ENABLE_AVX512_E4, - 'avx512_e3': mkl.MKL_ENABLE_AVX512_E3, - 'avx512_e2': mkl.MKL_ENABLE_AVX512_E2, - 'avx512_e1': mkl.MKL_ENABLE_AVX512_E1, - 'avx512_mic_e1': mkl.MKL_ENABLE_AVX512_MIC_E1, - 'avx512': mkl.MKL_ENABLE_AVX512, - 'avx512_mic': mkl.MKL_ENABLE_AVX512_MIC, - 'avx2_e1': mkl.MKL_ENABLE_AVX2_E1, - 'avx2': mkl.MKL_ENABLE_AVX2, - 'avx': mkl.MKL_ENABLE_AVX, - 'sse4_2': mkl.MKL_ENABLE_SSE4_2, + "input": { + "single_path": mkl.MKL_SINGLE_PATH_ENABLE, + "avx512_e4": mkl.MKL_ENABLE_AVX512_E4, + "avx512_e3": mkl.MKL_ENABLE_AVX512_E3, + "avx512_e2": mkl.MKL_ENABLE_AVX512_E2, + "avx512_e1": mkl.MKL_ENABLE_AVX512_E1, + "avx512_mic_e1": mkl.MKL_ENABLE_AVX512_MIC_E1, + "avx512": mkl.MKL_ENABLE_AVX512, + "avx512_mic": mkl.MKL_ENABLE_AVX512_MIC, + "avx2_e1": mkl.MKL_ENABLE_AVX2_E1, + "avx2": mkl.MKL_ENABLE_AVX2, + "avx": mkl.MKL_ENABLE_AVX, + "sse4_2": mkl.MKL_ENABLE_SSE4_2, }, } - cdef int c_mkl_isa = __mkl_str_to_int(isa, __variables['input']) + cdef int c_mkl_isa = __mkl_str_to_int(isa, __variables["input"]) cdef int c_mkl_status = mkl.mkl_enable_instructions(c_mkl_isa) @@ -778,18 +809,19 @@ cdef object __enable_instructions(isa=None) except *: cdef object __set_env_mode() except *: """ - Sets up the mode that ignores environment settings specific to Intel(R) MKL. See mkl_set_env_mode(1). + Sets up the mode that ignores environment settings specific to Intel(R) MKL. + See mkl_set_env_mode(1). """ __variables = { - 'input': None, - 'output': { - 0: 'default', - 1: 'ignore', + "input": None, + "output": { + 0: "default", + 1: "ignore", }, } cdef int c_mkl_status = mkl.mkl_set_env_mode(1) - status = __mkl_int_to_str(c_mkl_status, __variables['output']) + status = __mkl_int_to_str(c_mkl_status, __variables["output"]) return status @@ -798,14 +830,14 @@ cdef object __get_env_mode() except *: Query the current environment mode. See mkl_set_env_mode(0). """ __variables = { - 'output': { - 0: 'default', - 1: 'ignore', + "output": { + 0: "default", + 1: "ignore", }, } cdef int c_mkl_status = mkl.mkl_set_env_mode(0) - status = __mkl_int_to_str(c_mkl_status, __variables['output']) + status = __mkl_int_to_str(c_mkl_status, __variables["output"]) return status @@ -821,100 +853,107 @@ cdef __set_mpi(vendor, custom_library_name=None) except *: Sets the implementation of the message-passing interface to be used by Intel(R) MKL. """ __variables = { - 'input': { - 'custom': mkl.MKL_BLACS_CUSTOM, - 'msmpi': mkl.MKL_BLACS_MSMPI, - 'intelmpi': mkl.MKL_BLACS_INTELMPI, + "input": { + "custom": mkl.MKL_BLACS_CUSTOM, + "msmpi": mkl.MKL_BLACS_MSMPI, + "intelmpi": mkl.MKL_BLACS_INTELMPI, }, - 'output': { - 0: 'success', - -1: 'vendor_invalid', - -2: 'custom_library_name_invalid', - -3: 'MPI library cannot be set at this point', + "output": { + 0: "success", + -1: "vendor_invalid", + -2: "custom_library_name_invalid", + -3: "MPI library cannot be set at this point", }, } if mkl.MKL_BLACS_LASTMPI > mkl.MKL_BLACS_INTELMPI + 1: - __variables['input']['mpich2'] = mkl.MKL_BLACS_MPICH2 - if ((vendor is 'custom' or custom_library_name is not None) and - (vendor is not 'custom' or custom_library_name is None)): + __variables["input"]["mpich2"] = mkl.MKL_BLACS_MPICH2 + if ( + (vendor is "custom" or custom_library_name is not None) + and (vendor is not "custom" or custom_library_name is None) + ): raise ValueError("Selecting custom MPI for BLACS requires specifying " "the custom library, and specifying custom library " "necessitates selecting a custom MPI for BLACS library") - mkl_vendor = __mkl_str_to_int(vendor, __variables['input']) + mkl_vendor = __mkl_str_to_int(vendor, __variables["input"]) cdef bytes c_bytes - cdef char* c_string = '' + cdef char* c_string = "" if custom_library_name is not None: c_bytes = custom_library_name.encode() c_string = c_bytes mkl_status = mkl.mkl_set_mpi(mkl_vendor, c_string) - status = __mkl_int_to_str(mkl_status, __variables['output']) + status = __mkl_int_to_str(mkl_status, __variables["output"]) return status # VM Service Functions cdef object __vml_set_mode(accuracy, ftzdaz, errmode) except *: """ - Sets a new mode for VM functions according to the mode parameter and stores the previous VM mode to oldmode. + Sets a new mode for VM functions according to the mode parameter and stores the + previous VM mode to oldmode. """ __variables = { - 'input': { - 'accuracy': { - 'ha': mkl.VML_HA, - 'la': mkl.VML_LA, - 'ep': mkl.VML_EP, + "input": { + "accuracy": { + "ha": mkl.VML_HA, + "la": mkl.VML_LA, + "ep": mkl.VML_EP, }, - 'ftzdaz': { - 'on': mkl.VML_FTZDAZ_ON, - 'off': mkl.VML_FTZDAZ_OFF, - 'default': 0, + "ftzdaz": { + "on": mkl.VML_FTZDAZ_ON, + "off": mkl.VML_FTZDAZ_OFF, + "default": 0, }, - 'errmode': { - 'ignore': mkl.VML_ERRMODE_IGNORE, - 'errno': mkl.VML_ERRMODE_ERRNO, - 'stderr': mkl.VML_ERRMODE_STDERR, - 'except': mkl.VML_ERRMODE_EXCEPT, - 'callback': mkl.VML_ERRMODE_CALLBACK, - 'default': mkl.VML_ERRMODE_DEFAULT, + "errmode": { + "ignore": mkl.VML_ERRMODE_IGNORE, + "errno": mkl.VML_ERRMODE_ERRNO, + "stderr": mkl.VML_ERRMODE_STDERR, + "except": mkl.VML_ERRMODE_EXCEPT, + "callback": mkl.VML_ERRMODE_CALLBACK, + "default": mkl.VML_ERRMODE_DEFAULT, }, }, - 'output': { - 'accuracy': { - mkl.VML_HA: 'ha', - mkl.VML_LA: 'la', - mkl.VML_EP: 'ep', + "output": { + "accuracy": { + mkl.VML_HA: "ha", + mkl.VML_LA: "la", + mkl.VML_EP: "ep", }, - 'ftzdaz': { - mkl.VML_FTZDAZ_ON: 'on', - mkl.VML_FTZDAZ_OFF: 'off', - 0: 'default', + "ftzdaz": { + mkl.VML_FTZDAZ_ON: "on", + mkl.VML_FTZDAZ_OFF: "off", + 0: "default", }, - 'errmode': { - mkl.VML_ERRMODE_IGNORE: 'ignore', - mkl.VML_ERRMODE_ERRNO: 'errno', - mkl.VML_ERRMODE_STDERR: 'stderr', - mkl.VML_ERRMODE_EXCEPT: 'except', - mkl.VML_ERRMODE_CALLBACK: 'callback', - mkl.VML_ERRMODE_DEFAULT: 'default', + "errmode": { + mkl.VML_ERRMODE_IGNORE: "ignore", + mkl.VML_ERRMODE_ERRNO: "errno", + mkl.VML_ERRMODE_STDERR: "stderr", + mkl.VML_ERRMODE_EXCEPT: "except", + mkl.VML_ERRMODE_CALLBACK: "callback", + mkl.VML_ERRMODE_DEFAULT: "default", }, }, } - cdef int c_mkl_accuracy = __mkl_str_to_int(accuracy, __variables['input']['accuracy']) - cdef int c_mkl_ftzdaz = __mkl_str_to_int(ftzdaz, __variables['input']['ftzdaz']) - cdef int c_mkl_errmode = __mkl_str_to_int(errmode, __variables['input']['errmode']) + cdef int c_mkl_accuracy = __mkl_str_to_int( + accuracy, __variables["input"]["accuracy"] + ) + cdef int c_mkl_ftzdaz = __mkl_str_to_int(ftzdaz, __variables["input"]["ftzdaz"]) + cdef int c_mkl_errmode = __mkl_str_to_int(errmode, __variables["input"]["errmode"]) - cdef int c_mkl_status = mkl.vmlSetMode(c_mkl_accuracy | c_mkl_ftzdaz | c_mkl_errmode) + cdef int c_mkl_status = mkl.vmlSetMode( + c_mkl_accuracy | c_mkl_ftzdaz | c_mkl_errmode + ) accuracy = __mkl_int_to_str( c_mkl_status & mkl.VML_ACCURACY_MASK, - __variables['output']['accuracy']) + __variables["output"]["accuracy"]) ftzdaz = __mkl_int_to_str( c_mkl_status & mkl.VML_FTZDAZ_MASK, - __variables['output']['ftzdaz']) + __variables["output"]["ftzdaz"]) errmode = __mkl_int_to_str( c_mkl_status & mkl.VML_ERRMODE_MASK, - __variables['output']['errmode']) + __variables["output"]["errmode"]) return (accuracy, ftzdaz, errmode) @@ -924,24 +963,24 @@ cdef object __vml_get_mode() except *: Gets the VM mode. """ __variables = { - 'output': { - 'accuracy': { - mkl.VML_HA: 'ha', - mkl.VML_LA: 'la', - mkl.VML_EP: 'ep', + "output": { + "accuracy": { + mkl.VML_HA: "ha", + mkl.VML_LA: "la", + mkl.VML_EP: "ep", }, - 'ftzdaz': { - mkl.VML_FTZDAZ_ON: 'on', - mkl.VML_FTZDAZ_OFF: 'off', - 0: 'default', + "ftzdaz": { + mkl.VML_FTZDAZ_ON: "on", + mkl.VML_FTZDAZ_OFF: "off", + 0: "default", }, - 'errmode': { - mkl.VML_ERRMODE_IGNORE: 'ignore', - mkl.VML_ERRMODE_ERRNO: 'errno', - mkl.VML_ERRMODE_STDERR: 'stderr', - mkl.VML_ERRMODE_EXCEPT: 'except', - mkl.VML_ERRMODE_CALLBACK: 'callback', - mkl.VML_ERRMODE_DEFAULT: 'default', + "errmode": { + mkl.VML_ERRMODE_IGNORE: "ignore", + mkl.VML_ERRMODE_ERRNO: "errno", + mkl.VML_ERRMODE_STDERR: "stderr", + mkl.VML_ERRMODE_EXCEPT: "except", + mkl.VML_ERRMODE_CALLBACK: "callback", + mkl.VML_ERRMODE_DEFAULT: "default", }, }, } @@ -950,59 +989,60 @@ cdef object __vml_get_mode() except *: accuracy = __mkl_int_to_str( c_mkl_status & mkl.VML_ACCURACY_MASK, - __variables['output']['accuracy']) + __variables["output"]["accuracy"]) ftzdaz = __mkl_int_to_str( c_mkl_status & mkl.VML_FTZDAZ_MASK, - __variables['output']['ftzdaz']) + __variables["output"]["ftzdaz"]) errmode = __mkl_int_to_str( c_mkl_status & mkl.VML_ERRMODE_MASK, - __variables['output']['errmode']) + __variables["output"]["errmode"]) return (accuracy, ftzdaz, errmode) __mkl_vml_status = { - 'ok': mkl.VML_STATUS_OK, - 'accuracywarning': mkl.VML_STATUS_ACCURACYWARNING, - 'badsize': mkl.VML_STATUS_BADSIZE, - 'badmem': mkl.VML_STATUS_BADMEM, - 'errdom': mkl.VML_STATUS_ERRDOM, - 'sing': mkl.VML_STATUS_SING, - 'overflow': mkl.VML_STATUS_OVERFLOW, - 'underflow': mkl.VML_STATUS_UNDERFLOW, + "ok": mkl.VML_STATUS_OK, + "accuracywarning": mkl.VML_STATUS_ACCURACYWARNING, + "badsize": mkl.VML_STATUS_BADSIZE, + "badmem": mkl.VML_STATUS_BADMEM, + "errdom": mkl.VML_STATUS_ERRDOM, + "sing": mkl.VML_STATUS_SING, + "overflow": mkl.VML_STATUS_OVERFLOW, + "underflow": mkl.VML_STATUS_UNDERFLOW, } cdef object __vml_set_err_status(status) except *: """ - Sets the new VM Error Status according to err and stores the previous VM Error Status to olderr. + Sets the new VM Error Status according to err and stores the previous VM Error + Status to olderr. """ __variables = { - 'input': { - 'ok': mkl.VML_STATUS_OK, - 'accuracywarning': mkl.VML_STATUS_ACCURACYWARNING, - 'badsize': mkl.VML_STATUS_BADSIZE, - 'badmem': mkl.VML_STATUS_BADMEM, - 'errdom': mkl.VML_STATUS_ERRDOM, - 'sing': mkl.VML_STATUS_SING, - 'overflow': mkl.VML_STATUS_OVERFLOW, - 'underflow': mkl.VML_STATUS_UNDERFLOW, + "input": { + "ok": mkl.VML_STATUS_OK, + "accuracywarning": mkl.VML_STATUS_ACCURACYWARNING, + "badsize": mkl.VML_STATUS_BADSIZE, + "badmem": mkl.VML_STATUS_BADMEM, + "errdom": mkl.VML_STATUS_ERRDOM, + "sing": mkl.VML_STATUS_SING, + "overflow": mkl.VML_STATUS_OVERFLOW, + "underflow": mkl.VML_STATUS_UNDERFLOW, }, - 'output': { - mkl.VML_STATUS_OK: 'ok', - mkl.VML_STATUS_ACCURACYWARNING: 'accuracywarning', - mkl.VML_STATUS_BADSIZE: 'badsize', - mkl.VML_STATUS_BADMEM: 'badmem', - mkl.VML_STATUS_ERRDOM: 'errdom', - mkl.VML_STATUS_SING: 'sing', - mkl.VML_STATUS_OVERFLOW: 'overflow', - mkl.VML_STATUS_UNDERFLOW: 'underflow', + "output": { + mkl.VML_STATUS_OK: "ok", + mkl.VML_STATUS_ACCURACYWARNING: "accuracywarning", + mkl.VML_STATUS_BADSIZE: "badsize", + mkl.VML_STATUS_BADMEM: "badmem", + mkl.VML_STATUS_ERRDOM: "errdom", + mkl.VML_STATUS_SING: "sing", + mkl.VML_STATUS_OVERFLOW: "overflow", + mkl.VML_STATUS_UNDERFLOW: "underflow", }, } - cdef int mkl_status_in = __mkl_str_to_int(status, __variables['input']) + cdef int mkl_status_in = __mkl_str_to_int(status, __variables["input"]) cdef int mkl_status_out = mkl.vmlSetErrStatus(mkl_status_in) - status = __mkl_int_to_str(mkl_status_out, __variables['output']) + status = __mkl_int_to_str(mkl_status_out, __variables["output"]) return status @@ -1011,44 +1051,45 @@ cdef object __vml_get_err_status() except *: Gets the VM Error Status. """ __variables = { - 'input': None, - 'output': { - mkl.VML_STATUS_OK: 'ok', - mkl.VML_STATUS_ACCURACYWARNING: 'accuracywarning', - mkl.VML_STATUS_BADSIZE: 'badsize', - mkl.VML_STATUS_BADMEM: 'badmem', - mkl.VML_STATUS_ERRDOM: 'errdom', - mkl.VML_STATUS_SING: 'sing', - mkl.VML_STATUS_OVERFLOW: 'overflow', - mkl.VML_STATUS_UNDERFLOW: 'underflow', + "input": None, + "output": { + mkl.VML_STATUS_OK: "ok", + mkl.VML_STATUS_ACCURACYWARNING: "accuracywarning", + mkl.VML_STATUS_BADSIZE: "badsize", + mkl.VML_STATUS_BADMEM: "badmem", + mkl.VML_STATUS_ERRDOM: "errdom", + mkl.VML_STATUS_SING: "sing", + mkl.VML_STATUS_OVERFLOW: "overflow", + mkl.VML_STATUS_UNDERFLOW: "underflow", }, } cdef int mkl_status = mkl.vmlGetErrStatus() - status = __mkl_int_to_str(mkl_status, __variables['output']) + status = __mkl_int_to_str(mkl_status, __variables["output"]) return status cdef object __vml_clear_err_status() except *: """ - Sets the VM Error Status to VML_STATUS_OK and stores the previous VM Error Status to olderr. + Sets the VM Error Status to VML_STATUS_OK and stores the previous VM Error Status + to olderr. """ __variables = { - 'input': None, - 'output': { - mkl.VML_STATUS_OK: 'ok', - mkl.VML_STATUS_ACCURACYWARNING: 'accuracywarning', - mkl.VML_STATUS_BADSIZE: 'badsize', - mkl.VML_STATUS_BADMEM: 'badmem', - mkl.VML_STATUS_ERRDOM: 'errdom', - mkl.VML_STATUS_SING: 'sing', - mkl.VML_STATUS_OVERFLOW: 'overflow', - mkl.VML_STATUS_UNDERFLOW: 'underflow', + "input": None, + "output": { + mkl.VML_STATUS_OK: "ok", + mkl.VML_STATUS_ACCURACYWARNING: "accuracywarning", + mkl.VML_STATUS_BADSIZE: "badsize", + mkl.VML_STATUS_BADMEM: "badmem", + mkl.VML_STATUS_ERRDOM: "errdom", + mkl.VML_STATUS_SING: "sing", + mkl.VML_STATUS_OVERFLOW: "overflow", + mkl.VML_STATUS_UNDERFLOW: "underflow", }, } cdef int mkl_status = mkl.vmlClearErrStatus() - status = __mkl_int_to_str(mkl_status, __variables['output']) + status = __mkl_int_to_str(mkl_status, __variables["output"]) return status diff --git a/mkl/_mklinitmodule.c b/mkl/_mklinitmodule.c index 791cfb6..15a94f7 100644 --- a/mkl/_mklinitmodule.c +++ b/mkl/_mklinitmodule.c @@ -9,8 +9,8 @@ #define FORCE_PRELOADING 1 #define _GNU_SOURCE 1 #include -#include #include +#include #undef _GNU_SOURCE #endif @@ -20,9 +20,7 @@ #endif #include "mkl.h" -static struct PyMethodDef methods[] = { - {NULL, NULL, 0, NULL} -}; +static struct PyMethodDef methods[] = {{NULL, NULL, 0, NULL}}; #if defined(_MSC_VER) && (_MSC_VER <= 1500) #define MKL_SERVICE_INLINE @@ -34,154 +32,165 @@ static MKL_SERVICE_INLINE void _set_mkl_ilp64(void); static MKL_SERVICE_INLINE void _set_mkl_lp64(void); static MKL_SERVICE_INLINE void _set_mkl_interface(void); -static const char* mtlayer; -static const char* verbose; +static const char *mtlayer; +static const char *verbose; #if FORCE_PRELOADING -#define VERBOSE(...) if(verbose) printf("mkl-service + Intel(R) MKL: " __VA_ARGS__) +#define VERBOSE(...) \ + if (verbose) \ + printf("mkl-service + Intel(R) MKL: " __VA_ARGS__) static void restore_mtlayer(void) { - if (mtlayer) { - VERBOSE("Re-setting Intel(R) MKL_THREADING_LAYER=%s for the forked process\n", mtlayer); - setenv("MKL_THREADING_LAYER", mtlayer, 1); - } else { - VERBOSE("Unsetting Intel(R) MKL_THREADING_LAYER variable for the forked process \n"); - unsetenv("MKL_THREADING_LAYER"); - } + if (mtlayer) { + VERBOSE( + "Re-setting Intel(R) MKL_THREADING_LAYER=%s for the forked process\n", + mtlayer); + setenv("MKL_THREADING_LAYER", mtlayer, 1); + } else { + VERBOSE("Unsetting Intel(R) MKL_THREADING_LAYER variable for the forked " + "process \n"); + unsetenv("MKL_THREADING_LAYER"); + } } #endif static void _preload_threading_layer(void) { #if FORCE_PRELOADING -#define SET_MTLAYER(L) do { \ - VERBOSE("setting Intel(R) MKL to use " #L " OpenMP runtime\n"); \ - mkl_set_threading_layer(MKL_THREADING_##L); \ - setenv("MKL_THREADING_LAYER", #L, 0); \ - pthread_atfork(NULL, NULL, &restore_mtlayer); \ - } while(0) -#define PRELOAD(lib) do { \ - VERBOSE("preloading %s runtime\n", lib); \ - dlopen(lib, RTLD_LAZY|RTLD_GLOBAL); \ - } while(0) - /* - * The following is the pseudo-code skeleton for reinterpreting unset MKL_THREADING_LAYER - * - * if MKL_THREADING_LAYER is empty - * if kmp_calloc (or a suitable symbol identified by Terry) is loaded, - * we are using Intel(R) OpenMP, i.e. reinterpret as implicit value of INTEL - * otherwise check if other Open MP is loaded by checking get_omp_num_threads symbol - * if not loaded: - * assume INTEL, and force loading of IOMP5 - * if loaded: - * if Gnu OMP, set MKL_THREADING_LAYER=GNU, and call set_mkl_threading_layer(MKL_THREADING_GNU) - * if other vendors? - * if MKL_THREADING_LAYER is INTEL - * force loading of iomp, to preempt possibility of other modules loading other OMP library before MKL is actually used - * - * should we treat other possible values of MKL_THREADING_LAYER specially? - * - */ - - const char *libiomp = "libiomp5.so"; - verbose = getenv("MKL_VERBOSE"); - mtlayer = getenv("MKL_THREADING_LAYER"); - - /* Use of RTLD_DEFAULT handler is to indicate that symbol is being lookup-up among symbols - * presently known to this process. - * - * See: https://pubs.opengroup.org/onlinepubs/9699919799/functions/dlsym.html - */ - void *omp = dlsym(RTLD_DEFAULT, "omp_get_num_threads"); - const char *omp_name = "(unidentified)"; - const char *iomp = NULL; /* non-zero indicates Intel(R) OpenMP is loaded */ - Dl_info omp_info; - - if(verbose && (verbose[0] == 0 || atoi(verbose) == 0)) - verbose = NULL; - - VERBOSE("THREADING LAYER: %s\n", mtlayer); - - if(omp) { - if(dladdr(omp, &omp_info)) { - omp_name = basename(omp_info.dli_fname); /* GNU version doesn't modify argument */ - iomp = strstr(omp_name, libiomp); - } - VERBOSE("%s OpenMP runtime %s is already loaded\n", iomp?"Intel(R)":"Other vendor", omp_name); +#define SET_MTLAYER(L) \ + do { \ + VERBOSE("setting Intel(R) MKL to use " #L " OpenMP runtime\n"); \ + mkl_set_threading_layer(MKL_THREADING_##L); \ + setenv("MKL_THREADING_LAYER", #L, 0); \ + pthread_atfork(NULL, NULL, &restore_mtlayer); \ + } while (0) +#define PRELOAD(lib) \ + do { \ + VERBOSE("preloading %s runtime\n", lib); \ + dlopen(lib, RTLD_LAZY | RTLD_GLOBAL); \ + } while (0) + /* + * The following is the pseudo-code skeleton for reinterpreting unset + * MKL_THREADING_LAYER + * + * if MKL_THREADING_LAYER is empty + * if kmp_calloc (or a suitable symbol identified by Terry) is + * loaded, we are using Intel(R) OpenMP, i.e. reinterpret as implicit value of + * INTEL otherwise check if other Open MP is loaded by checking + * get_omp_num_threads symbol if not loaded: assume INTEL, and force loading + * of IOMP5 if loaded: if Gnu OMP, set MKL_THREADING_LAYER=GNU, and call + * set_mkl_threading_layer(MKL_THREADING_GNU) if other vendors? if + * MKL_THREADING_LAYER is INTEL force loading of iomp, to preempt possibility + * of other modules loading other OMP library before MKL is actually used + * + * should we treat other possible values of MKL_THREADING_LAYER + * specially? + * + */ + + const char *libiomp = "libiomp5.so"; + verbose = getenv("MKL_VERBOSE"); + mtlayer = getenv("MKL_THREADING_LAYER"); + + /* Use of RTLD_DEFAULT handler is to indicate that symbol is being lookup-up + * among symbols presently known to this process. + * + * See: https://pubs.opengroup.org/onlinepubs/9699919799/functions/dlsym.html + */ + void *omp = dlsym(RTLD_DEFAULT, "omp_get_num_threads"); + const char *omp_name = "(unidentified)"; + const char *iomp = NULL; /* non-zero indicates Intel(R) OpenMP is loaded */ + Dl_info omp_info; + + if (verbose && (verbose[0] == 0 || atoi(verbose) == 0)) + verbose = NULL; + + VERBOSE("THREADING LAYER: %s\n", mtlayer); + + if (omp) { + if (dladdr(omp, &omp_info)) { + omp_name = basename( + omp_info.dli_fname); /* GNU version doesn't modify argument */ + iomp = strstr(omp_name, libiomp); } - if(!mtlayer || mtlayer[0] == 0) { /* unset or empty */ - if(omp) { /* if OpenMP runtime is loaded */ - if(iomp) /* if Intel runtime is loaded */ - SET_MTLAYER(INTEL); - else /* otherwise, assume it is GNU OpenMP */ - SET_MTLAYER(GNU); - } else { /* nothing is loaded */ - SET_MTLAYER(INTEL); - PRELOAD(libiomp); - } - } else if(strcasecmp(mtlayer, "intel") == 0) { /* Intel runtime is requested */ - if(omp && !iomp) { - fprintf(stderr, "Error: mkl-service + Intel(R) MKL: MKL_THREADING_LAYER=INTEL is incompatible with %s library." - "\n\tTry to import numpy first or set the threading layer accordingly. " - "Set MKL_SERVICE_FORCE_INTEL to force it.\n", omp_name); - if(!getenv("MKL_SERVICE_FORCE_INTEL")) - exit(1); - } else - PRELOAD(libiomp); + VERBOSE("%s OpenMP runtime %s is already loaded\n", + iomp ? "Intel(R)" : "Other vendor", omp_name); + } + if (!mtlayer || mtlayer[0] == 0) { /* unset or empty */ + if (omp) { /* if OpenMP runtime is loaded */ + if (iomp) /* if Intel runtime is loaded */ + SET_MTLAYER(INTEL); + else /* otherwise, assume it is GNU OpenMP */ + SET_MTLAYER(GNU); + } else { /* nothing is loaded */ + SET_MTLAYER(INTEL); + PRELOAD(libiomp); } + } else if (strcasecmp(mtlayer, "intel") == + 0) { /* Intel runtime is requested */ + if (omp && !iomp) { + fprintf(stderr, + "Error: mkl-service + Intel(R) MKL: MKL_THREADING_LAYER=INTEL is " + "incompatible with %s library." + "\n\tTry to import numpy first or set the threading layer " + "accordingly. " + "Set MKL_SERVICE_FORCE_INTEL to force it.\n", + omp_name); + if (!getenv("MKL_SERVICE_FORCE_INTEL")) + exit(1); + } else + PRELOAD(libiomp); + } #endif - return; + return; } static MKL_SERVICE_INLINE void _set_mkl_ilp64(void) { #ifdef USING_MKL_RT - mkl_set_interface_layer(MKL_INTERFACE_ILP64); + mkl_set_interface_layer(MKL_INTERFACE_ILP64); #endif - return; + return; } static MKL_SERVICE_INLINE void _set_mkl_lp64(void) { #ifdef USING_MKL_RT - mkl_set_interface_layer(MKL_INTERFACE_LP64); + mkl_set_interface_layer(MKL_INTERFACE_LP64); #endif - return; + return; } static MKL_SERVICE_INLINE void _set_mkl_interface(void) { - _set_mkl_lp64(); - _preload_threading_layer(); + _set_mkl_lp64(); + _preload_threading_layer(); } #if defined(IS_PY3K) -static struct PyModuleDef moduledef = { - PyModuleDef_HEAD_INIT, - "mklinit", - NULL, - -1, - methods, - NULL, - NULL, - NULL, - NULL -}; +static struct PyModuleDef moduledef = {PyModuleDef_HEAD_INIT, + "mklinit", + NULL, + -1, + methods, + NULL, + NULL, + NULL, + NULL}; #endif /* Initialization function for the module */ #if defined(IS_PY3K) PyMODINIT_FUNC PyInit__mklinit(void) { - PyObject *m; + PyObject *m; - _set_mkl_interface(); - m = PyModule_Create(&moduledef); - if (!m) { - return NULL; - } + _set_mkl_interface(); + m = PyModule_Create(&moduledef); + if (!m) { + return NULL; + } - return m; + return m; } #else -PyMODINIT_FUNC -init_mklinit(void) { - _set_mkl_interface(); - Py_InitModule("_mklinit", methods); +PyMODINIT_FUNC init_mklinit(void) { + _set_mkl_interface(); + Py_InitModule("_mklinit", methods); } #endif diff --git a/mkl/tests/test_mkl_service.py b/mkl/tests/test_mkl_service.py index a31343d..22b2e60 100644 --- a/mkl/tests/test_mkl_service.py +++ b/mkl/tests/test_mkl_service.py @@ -23,76 +23,78 @@ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# pylint: disable=no-member import pytest + import mkl 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') - saved_vml_nt = mkl.domain_get_max_threads(domain='vml') + saved_blas_nt = mkl.domain_get_max_threads(domain="blas") + saved_fft_nt = mkl.domain_get_max_threads(domain="fft") + saved_vml_nt = mkl.domain_get_max_threads(domain="vml") # set - blas_nt = int( (3 + saved_blas_nt)/4 ) - fft_nt = int( (3 + 2*saved_fft_nt)/4 ) - vml_nt = int( (3 + 3*saved_vml_nt)/4 ) - status = mkl.domain_set_num_threads(blas_nt, domain='blas') - assert status == 'success' - status = mkl.domain_set_num_threads(fft_nt, domain='fft') - assert status == 'success' - status = mkl.domain_set_num_threads(vml_nt, domain='vml') - assert status == 'success' + blas_nt = int((3 + saved_blas_nt) / 4) + fft_nt = int((3 + 2 * saved_fft_nt) / 4) + vml_nt = int((3 + 3 * saved_vml_nt) / 4) + status = mkl.domain_set_num_threads(blas_nt, domain="blas") + assert status == "success" + status = mkl.domain_set_num_threads(fft_nt, domain="fft") + assert status == "success" + status = mkl.domain_set_num_threads(vml_nt, domain="vml") + assert status == "success" # check - assert mkl.domain_get_max_threads(domain='blas') == blas_nt - assert mkl.domain_get_max_threads(domain='fft') == fft_nt - assert mkl.domain_get_max_threads(domain='vml') == vml_nt + assert mkl.domain_get_max_threads(domain="blas") == blas_nt + assert mkl.domain_get_max_threads(domain="fft") == fft_nt + assert mkl.domain_get_max_threads(domain="vml") == vml_nt # restore - status = mkl.domain_set_num_threads(saved_blas_nt, domain='blas') - assert status == 'success' - status = mkl.domain_set_num_threads(saved_fft_nt, domain='fft') - assert status == 'success' - status = mkl.domain_set_num_threads(saved_vml_nt, domain='vml') - assert status == 'success' + status = mkl.domain_set_num_threads(saved_blas_nt, domain="blas") + assert status == "success" + status = mkl.domain_set_num_threads(saved_fft_nt, domain="fft") + assert status == "success" + 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' + 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' + 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' + 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' + 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) - assert status == 'global_num_threads' + assert status == "global_num_threads" status = mkl.set_num_threads_local(4) assert status == 2 status = mkl.set_num_threads_local(0) assert status == 4 status = mkl.set_num_threads_local(8) - assert status == 'global_num_threads' + assert status == "global_num_threads" def test_set_dynamic(): @@ -104,23 +106,23 @@ def test_get_max_threads(): def test_domain_get_max_threads_blas(): - mkl.domain_get_max_threads(domain='blas') + mkl.domain_get_max_threads(domain="blas") def test_domain_get_max_threads_fft(): - mkl.domain_get_max_threads(domain='fft') + mkl.domain_get_max_threads(domain="fft") def test_domain_get_max_threads_vml(): - mkl.domain_get_max_threads(domain='vml') + mkl.domain_get_max_threads(domain="vml") def test_domain_get_max_threads_pardiso(): - mkl.domain_get_max_threads(domain='pardiso') + mkl.domain_get_max_threads(domain="pardiso") def test_domain_get_max_threads_all(): - mkl.domain_get_max_threads(domain='all') + mkl.domain_get_max_threads(domain="all") def test_get_dynamic(): @@ -178,19 +180,19 @@ def test_mem_stat(): def test_peak_mem_usage_enable(): - mkl.peak_mem_usage('enable') + mkl.peak_mem_usage("enable") def test_peak_mem_usage_disable(): - mkl.peak_mem_usage('disable') + mkl.peak_mem_usage("disable") def test_peak_mem_usage_peak_mem(): - mkl.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') + mkl.peak_mem_usage("peak_mem_reset") def test_set_memory_limit(): @@ -199,51 +201,52 @@ def test_set_memory_limit(): def check_cbwr(branch, cnr_const): status = mkl.cbwr_set(branch=branch) - if status == 'success': - expected_value = 'branch_off' if branch == 'off' else 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']: + 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 = [ - 'off', - 'branch_off', - 'auto', - 'compatible', - 'sse2', - 'ssse3', - 'sse4_1', - 'sse4_2', - 'avx', - 'avx2', - 'avx512_mic', - 'avx512', - 'avx512_mic_e1', - 'avx512_e1', + "off", + "branch_off", + "auto", + "compatible", + "sse2", + "ssse3", + "sse4_1", + "sse4_2", + "avx", + "avx2", + "avx512_mic", + "avx512", + "avx512_mic_e1", + "avx512_e1", ] strict = [ - 'avx2,strict', - 'avx512_mic,strict', - 'avx512,strict', - 'avx512_e1,strict', + "avx2,strict", + "avx512_mic,strict", + "avx512,strict", + "avx512_e1,strict", ] -@pytest.mark.parametrize('branch', branches) +@pytest.mark.parametrize("branch", branches) def test_cbwr_branch(branch): - check_cbwr(branch, 'branch') + check_cbwr(branch, "branch") -@pytest.mark.parametrize('branch', branches + strict) +@pytest.mark.parametrize("branch", branches + strict) def test_cbwr_all(branch): - check_cbwr(branch, 'all') + check_cbwr(branch, "all") def test_cbwr_get_auto_branch(): @@ -251,27 +254,27 @@ def test_cbwr_get_auto_branch(): def test_enable_instructions_avx512_mic_e1(): - mkl.enable_instructions('avx512_mic_e1') + mkl.enable_instructions("avx512_mic_e1") def test_enable_instructions_avx512(): - mkl.enable_instructions('avx512') + mkl.enable_instructions("avx512") def test_enable_instructions_avx512_mic(): - mkl.enable_instructions('avx512_mic') + mkl.enable_instructions("avx512_mic") def test_enable_instructions_avx2(): - mkl.enable_instructions('avx2') + mkl.enable_instructions("avx2") def test_enable_instructions_avx(): - mkl.enable_instructions('avx') + mkl.enable_instructions("avx") def test_enable_instructions_sse4_2(): - mkl.enable_instructions('sse4_2') + mkl.enable_instructions("sse4_2") def test_set_env_mode(): @@ -292,51 +295,51 @@ def test_verbose_true(): @pytest.mark.skip(reason="Skipping MPI-related test") def test_set_mpi_custom(): - mkl.set_mpi('custom', 'custom_library_name') + mkl.set_mpi("custom", "custom_library_name") @pytest.mark.skip(reason="Skipping MPI-related test") def test_set_mpi_msmpi(): - mkl.set_mpi('msmpi') + mkl.set_mpi("msmpi") @pytest.mark.skip(reason="Skipping MPI-related test") def test_set_mpi_intelmpi(): - mkl.set_mpi('intelmpi') + mkl.set_mpi("intelmpi") @pytest.mark.skip(reason="Skipping MPI-related test") def test_set_mpi_mpich2(): - mkl.set_mpi('mpich2') + mkl.set_mpi("mpich2") def test_vml_set_get_mode_roundtrip(): saved = mkl.vml_get_mode() - mkl.vml_set_mode(*saved) # should not raise errors + mkl.vml_set_mode(*saved) # should not raise errors def test_vml_set_mode_ha_on_ignore(): - mkl.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') + mkl.vml_set_mode("ha", "on", "errno") def test_vml_set_mode_la_on_stderr(): - mkl.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') + mkl.vml_set_mode("la", "off", "except") def test_vml_set_mode_op_off_callback(): - mkl.vml_set_mode('ep', 'off', 'callback') + mkl.vml_set_mode("ep", "off", "callback") def test_vml_set_mode_ep_off_default(): - mkl.vml_set_mode('ep', 'off', 'default') + mkl.vml_set_mode("ep", "off", "default") def test_vml_get_mode(): @@ -344,35 +347,35 @@ def test_vml_get_mode(): def test_vml_set_err_status_ok(): - mkl.vml_set_err_status('ok') + mkl.vml_set_err_status("ok") def test_vml_set_err_status_accuracywarning(): - mkl.vml_set_err_status('accuracywarning') + mkl.vml_set_err_status("accuracywarning") def test_vml_set_err_status_badsize(): - mkl.vml_set_err_status('badsize') + mkl.vml_set_err_status("badsize") def test_vml_set_err_status_badmem(): - mkl.vml_set_err_status('badmem') + mkl.vml_set_err_status("badmem") def test_vml_set_err_status_errdom(): - mkl.vml_set_err_status('errdom') + mkl.vml_set_err_status("errdom") def test_vml_set_err_status_sing(): - mkl.vml_set_err_status('sing') + mkl.vml_set_err_status("sing") def test_vml_set_err_status_overflow(): - mkl.vml_set_err_status('overflow') + mkl.vml_set_err_status("overflow") def test_vml_set_err_status_underflow(): - mkl.vml_set_err_status('underflow') + mkl.vml_set_err_status("underflow") def test_vml_get_err_status(): @@ -393,12 +396,12 @@ def test_get_version(): """ v = mkl.get_version() assert isinstance(v, dict) - assert 'MajorVersion' in v - assert 'MinorVersion' in v - assert 'UpdateVersion' in v + 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 + assert "Math Kernel Library" in v diff --git a/pyproject.toml b/pyproject.toml index bbb4760..2efd692 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,14 +3,14 @@ # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # -# * Redistributions of source code must retain the above copyright notice, -# this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# * Neither the name of Intel Corporation nor the names of its contributors -# may be used to endorse or promote products derived from this software -# without specific prior written permission. +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of Intel Corporation nor the names of its contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE @@ -23,7 +23,6 @@ # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - [build-system] build-backend = "setuptools.build_meta" requires = ["setuptools>=77", "Cython"] diff --git a/setup.py b/setup.py index c350a35..b5fcc2b 100644 --- a/setup.py +++ b/setup.py @@ -30,13 +30,14 @@ import Cython.Build from setuptools import Extension, setup + def extensions(): mkl_root = os.environ.get("MKLROOT", None) if mkl_root: mkl_info = { "include_dirs": [join(mkl_root, "include")], "library_dirs": [join(mkl_root, "lib"), join(mkl_root, "lib", "intel64")], - "libraries": ["mkl_rt"] + "libraries": ["mkl_rt"], } else: raise ValueError("MKLROOT environment variable not set.") @@ -47,7 +48,7 @@ def extensions(): defs = [] if any(["mkl_rt" in li for li in mkl_libraries]): - #libs += ["dl"] - by default on Linux + # libs += ["dl"] - by default on Linux defs += [("USING_MKL_RT", None)] extensions = [] @@ -62,7 +63,7 @@ def extensions(): "-DNDEBUG" # "-g", "-O2", "-Wall", ], - define_macros=defs, + define_macros=defs, ) ) @@ -76,7 +77,7 @@ def extensions(): extra_compile_args=[ "-DNDEBUG" # "-g", "-O2", "-Wall", - ] + ], ) )