import math import numpy as np import numbers import re import traceback import multiprocessing as mp import numba from numba import njit, prange from numba.core import config from numba.tests.support import TestCase, tag, override_env_config import unittest needs_svml = unittest.skipUnless(config.USING_SVML, "SVML tests need SVML to be present") # a map of float64 vector lengths with corresponding CPU architecture vlen2cpu = {2: 'nehalem', 4: 'haswell', 8: 'skylake-avx512'} # force LLVM to use AVX512 registers for vectorization # https://reviews.llvm.org/D67259 vlen2cpu_features = {2: '', 4: '', 8: '-prefer-256-bit'} # env vars to force CPU as skylake-avx512. # force LLVM to use AVX512 registers for vectorization # https://reviews.llvm.org/D67259 _skylake_axv512_envvars = {'NUMBA_CPU_NAME': 'skylake-avx512', 'NUMBA_CPU_FEATURES': '-prefer-256-bit'} # K: SVML functions, V: python functions which are expected to be SIMD-vectorized # using SVML, explicit references to Python functions here are mostly for sake of # instant import checks. # TODO: [] and comments below mean unused/untested SVML function, it's to be # either enabled or to be replaced with the explanation why the function # cannot be used in Numba # TODO: this test does not support functions with more than 1 arguments yet # The test logic should be modified if there is an SVML function being used under # different name or module from Python svml_funcs = { "sin": [np.sin, math.sin], "cos": [np.cos, math.cos], "pow": [], # pow, math.pow], "exp": [np.exp, math.exp], "log": [np.log, math.log], "acos": [math.acos], "acosh": [math.acosh], "asin": [math.asin], "asinh": [math.asinh], "atan2": [], # math.atan2], "atan": [math.atan], "atanh": [math.atanh], "cbrt": [], # np.cbrt], "cdfnorm": [], "cdfnorminv": [], "ceil": [], # np.ceil, math.ceil], "cosd": [], "cosh": [np.cosh, math.cosh], "erf": [math.erf], # np.erf is available in Intel Distribution "erfc": [math.erfc], "erfcinv": [], "erfinv": [], "exp10": [], "exp2": [], # np.exp2], "expm1": [np.expm1, math.expm1], "floor": [], # np.floor, math.floor], "fmod": [], # np.fmod, math.fmod], "hypot": [], # np.hypot, math.hypot], "invsqrt": [], # available in Intel Distribution "log10": [np.log10, math.log10], "log1p": [np.log1p, math.log1p], "log2": [], # np.log2], "logb": [], "nearbyint": [], "rint": [], # np.rint], "round": [], # round], "sind": [], "sinh": [np.sinh, math.sinh], "tan": [np.tan, math.tan], "tanh": [np.tanh, math.tanh], "trunc": [], # np.trunc, math.trunc], } # TODO: these functions are not vectorizable with complex types complex_funcs_exclude = ["tan", "log10", "expm1", "log1p", "tanh", "log"] # remove untested entries svml_funcs = {k: v for k, v in svml_funcs.items() if len(v) > 0} # lists for functions which belong to numpy and math modules correpondently numpy_funcs = [f for f, v in svml_funcs.items() if "