summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorSayed Adel <seiko@imavr.com>2020-07-21 13:08:07 +0200
committerGitHub <noreply@github.com>2020-07-21 14:08:07 +0300
commitbcce3573fb5d8e66b3c756d56e3cbdf9ed9b3eaf (patch)
treee6bbee2fc3f6e7fddcdc056f8572b9b207bcb052 /numpy
parentef5656d842459a6c338ee03ee422d7bd4b8beb61 (diff)
downloadnumpy-bcce3573fb5d8e66b3c756d56e3cbdf9ed9b3eaf.tar.gz
ENH: Integrate the new CPU dispatcher with umath generator (#16888)
Add new attribute `dispatch` to umath generator, same usage as the current attribute `simd` but requires the name of the dispatch-able source without its extension rather than CPU features names.
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/code_generators/generate_umath.py27
1 files changed, 24 insertions, 3 deletions
diff --git a/numpy/core/code_generators/generate_umath.py b/numpy/core/code_generators/generate_umath.py
index 4c8884dc5..86e28b104 100644
--- a/numpy/core/code_generators/generate_umath.py
+++ b/numpy/core/code_generators/generate_umath.py
@@ -48,8 +48,11 @@ class TypeDescription:
simd: list
Available SIMD ufunc loops, dispatched at runtime in specified order
Currently only supported for simples types (see make_arrays)
+ dispatch: list
+ Available SIMD ufunc loops, dispatched at runtime in specified order
+ Currently only supported for simples types (see make_arrays)
"""
- def __init__(self, type, f=None, in_=None, out=None, astype=None, simd=None):
+ def __init__(self, type, f=None, in_=None, out=None, astype=None, simd=None, dispatch=None):
self.type = type
self.func_data = f
if astype is None:
@@ -62,6 +65,7 @@ class TypeDescription:
out = out.replace('P', type)
self.out = out
self.simd = simd
+ self.dispatch = dispatch
def finish_signature(self, nin, nout):
if self.in_ is None:
@@ -86,7 +90,7 @@ def build_func_data(types, f):
func_data = [_fdata_map.get(t, '%s') % (f,) for t in types]
return func_data
-def TD(types, f=None, astype=None, in_=None, out=None, simd=None):
+def TD(types, f=None, astype=None, in_=None, out=None, simd=None, dispatch=None):
if f is not None:
if isinstance(f, str):
func_data = build_func_data(types, f)
@@ -115,7 +119,14 @@ def TD(types, f=None, astype=None, in_=None, out=None, simd=None):
simdt = [k for k, v in simd if t in v]
else:
simdt = []
- tds.append(TypeDescription(t, f=fd, in_=i, out=o, astype=astype, simd=simdt))
+ # [(dispatch file name without extension '.dispatch.c*', list of types)]
+ if dispatch:
+ dispt = [k for k, v in dispatch if t in v]
+ else:
+ dispt = []
+ tds.append(TypeDescription(
+ t, f=fd, in_=i, out=o, astype=astype, simd=simdt, dispatch=dispt
+ ))
return tds
class Ufunc:
@@ -1025,6 +1036,16 @@ def make_arrays(funcdict):
ISA=vt.upper(), isa=vt,
fname=name, type=tname, idx=k
))
+ if t.dispatch is not None:
+ for dname in t.dispatch:
+ code2list.append(textwrap.dedent("""\
+ #ifndef NPY_DISABLE_OPTIMIZATION
+ #include "{dname}.dispatch.h"
+ #endif
+ NPY_CPU_DISPATCH_CALL_XB({name}_functions[{k}] = {tname}_{name})
+ """).format(
+ dname=dname, name=name, tname=tname, k=k
+ ))
else:
funclist.append('NULL')
try: