MKL-Service package: Controlling MKL behavior through Python interfaces

Intel® Math Kernel Library (Intel® MKL) provides a set of functions for control of MKL behavior. These functions are subdivided into the following groups: Version Information, Threading Control, Timing, Memory Management, Conditional Numerical Reproducibility, Miscellaneous, and VM Control Functions.

MKL-service module implements a Python interface for these functions.

Version Information

  • get_version() - returns the Intel MKL version
  • get_version_string() - returns the Intel MKL version in a character string

Threading Control

  • set_num_threads(num_threads) - specifies the number of OpenMP* threads to use
  • domain_set_num_threads(num_threads, domain='all') - specifies the number of OpenMP* threads for a particular function domain('blas', 'fft', 'vml', 'pardiso', 'all')
  • set_num_threads_local(num_threads) - specifies the number of OpenMP* threads for all Intel MKL functions on the current execution thread
  • set_dynamic(enable) - enables Intel MKL to dynamically change the number of OpenMP* threads
  • get_max_threads() - gets the number of OpenMP* threads targeted for parallelism
  • domain_get_max_threads(domain='all') - gets the number of OpenMP* threads targeted for parallelism for a particular function domain('blas', 'fft', 'vml', 'pardiso', 'all')
  • get_dynamic() - determines whether Intel MKL is enabled to dynamically change the number of OpenMP* threads

Timing

  • second() - returns elapsed time in seconds
  • dsecnd() - returns elapsed time in seconds
  • get_cpu_clocks() - returns elapsed CPU clocks
  • get_cpu_frequency() - returns the current CPU frequency value in GHz
  • get_max_cpu_frequency() - returns the maximum CPU frequency value in GHz
  • get_clocks_frequency() - returns the frequency value in GHz based on constant-rate Time Stamp Counter

Memory Management

  • free_buffers() - frees unused memory allocated by the Intel MKL Memory Allocator
  • thread_free_buffers() - frees unused memory allocated by the Intel MKL Memory Allocator in the current thread
  • disable_fast_mm() - turns off the Intel MKL Memory Allocator for Intel MKL functions to directly use the system malloc/freefunctions
  • mem_stat() - reports the status of the Intel MKL Memory Allocator
  • peak_mem_usage(mem_const) - reports the peak memory allocated by the Intel MKL Memory Allocator
  • set_memory_limit(limit) - on Linux, sets the limit of memory that Intel MKL can allocate for a specified type of memory

Conditional Numerical Reproducibility

  • cbwr_set(branch=None) - configures the CNR mode of Intel MKL
  • cbwr_get(cnr_const=None) - returns the current CNR settings
  • cbwr_get_auto_branch() - automatically detects the CNR code branch for your platform

Miscellaneous

  • enable_instructions(isa=None) - enables dispatching for new Intel® architectures or restricts the set of Intel® instruction sets available for dispatching
  • set_env_mode() - sets up the mode that ignores environment settings specific to Intel MKL
  • get_env_mode() - returns the current environment settings
  • verbose(enable) - enables or disables Intel MKL Verbose mode
  • set_mpi(vendor, custom_library_name=None) - sets the implementation of the message-passing interface to be used by Intel MKL

VM Service Functions

  • vml_set_mode(accuracy, ftzdaz, errmode) - sets a new mode for VM functions according to the mode parameter
  • vml_get_mode() - gets the VM mode
  • vml_set_err_status(status) - sets the new VM Error Status according to status
  • vml_get_err_status() - gets the VM Error Status
  • vml_clear_err_status() - sets the VM Error Status to 'ok'
Setup

MKL-service module is included in Intel® Distribution for Python. You can also use conda to install mkl-service from intel channel.

Usage
import mkl

time_begin = mkl.dsecnd()
mkl_version = mkl.get_version_string()
time_end = mkl.dsecnd()

print(mkl_version)
print('Execution time: ' + str(time_end - time_begin))
For more complete information about compiler optimizations, see our Optimization Notice.