Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
06d69dd
Abstract out the call to array allocator as an intrinsic.
sklam May 24, 2021
81cba5d
Cleanup previous staging.
sklam May 25, 2021
c15fac1
Adding classmethod Array._allocate
sklam May 25, 2021
ac2708c
Use align instead of dtype
sklam May 25, 2021
ffcb989
Use array type to determine the classmethod
sklam May 25, 2021
b683418
Convert operator module functions to overloads.
stuartarchibald May 26, 2021
81ed617
Fix Black-Scholes test
stuartarchibald May 26, 2021
2b31732
Fix test_array_exprs
stuartarchibald May 26, 2021
64ca8bc
Flake8
stuartarchibald May 26, 2021
7ddd4d5
Fix error handling test
stuartarchibald May 26, 2021
37530ba
Fix debug test
stuartarchibald May 26, 2021
2cb8766
Fix up cache test
stuartarchibald May 26, 2021
2c0582c
Remove compile_isolated from svml tests
stuartarchibald May 27, 2021
6b8c62e
Fix test_debug in 32-bit platforms
sklam Jun 2, 2021
4188fe5
Fix fastmath propagation in SVML.
sklam Jun 3, 2021
b1b4fe3
Run SVML tests in isolated processes
sklam Jun 7, 2021
a5e7c43
Add inheriting behavior for error_model
sklam Jun 2, 2021
49f1dd8
Avoid compile_isolated in looplifting tests
sklam Jun 2, 2021
4024a9a
Revert "Convert operator module functions to overloads."
sklam Jun 8, 2021
57ebd93
Merge branch 'pr/7058' with revert of 0e323f5 into enh/arrayallocapi
sklam Jun 8, 2021
30b4eab
Revert patches specific to overload operators
sklam Jun 8, 2021
cec66fd
Test target specific overload_classmethod for allocator
stuartarchibald Jun 17, 2021
c5c08bb
Fix overload_method and attribute lookup not respecting hw class
sklam Jun 18, 2021
693f759
Fix typo
sklam Jun 23, 2021
609533a
Fix incorrect caching of BoundFunction due to target-overload
sklam Jun 23, 2021
1230e55
Merge branch 'master' into enh/arrayallocapi
sklam Jun 23, 2021
8fee312
Fix ir inlining test due to `inline` option in kwargs
sklam Jun 23, 2021
6c21b6d
More kwargs fixes
sklam Jun 24, 2021
144a840
Cleanup
sklam Jun 24, 2021
344c5b3
Apply suggestions from code review
sklam Jun 25, 2021
179767a
Remove dead code
sklam Jun 25, 2021
a5c48e6
Add timeout to avoid test hanging
sklam Jun 25, 2021
049923d
Remove redundant target_override and put nopython flag into jit_options
sklam Jun 25, 2021
f756fd0
PEP8
sklam Jun 25, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert "Convert operator module functions to overloads."
  • Loading branch information
sklam committed Jun 8, 2021
commit 4024a9ac2436c561ca7ac8b18dba0dc27d3cc2b3
55 changes: 1 addition & 54 deletions numba/core/lowering.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from functools import partial

from llvmlite.llvmpy.core import Constant, Type, Builder
from llvmlite import ir as llvm_ir

from numba.core import (typing, utils, types, ir, debuginfo, funcdesc,
generators, config, ir_utils, cgutils, removerefctpass)
Expand All @@ -16,58 +15,6 @@
_VarArgItem = namedtuple("_VarArgItem", ("vararg", "index"))


class TargetContextAwareBuilder(Builder):
"""Same as a llvmlite builder, but pays attention to the target context
and injects flags into instructions based on the current compilation flags.
These flags are locally overridable if desired.
"""
def fadd(self, lhs, rhs, name='', flags=()):
if flags:
ll_flags = flags
else:
ll_flags = utils.current_target_config().fastmath.flags
return super().fadd(lhs, rhs, name=name, flags=tuple(ll_flags))

def fsub(self, lhs, rhs, name='', flags=()):
if flags:
ll_flags = flags
else:
ll_flags = utils.current_target_config().fastmath.flags
return super().fsub(lhs, rhs, name=name, flags=tuple(ll_flags))

def fmul(self, lhs, rhs, name='', flags=()):
if flags:
ll_flags = flags
else:
ll_flags = utils.current_target_config().fastmath.flags
return super().fmul(lhs, rhs, name=name, flags=tuple(ll_flags))

def fdiv(self, lhs, rhs, name='', flags=()):
if flags:
ll_flags = flags
else:
ll_flags = utils.current_target_config().fastmath.flags
return super().fdiv(lhs, rhs, name=name, flags=tuple(ll_flags))

def frem(self, lhs, rhs, name='', flags=()):
if flags:
ll_flags = flags
else:
ll_flags = utils.current_target_config().fastmath.flags
return super().frem(lhs, rhs, name=name, flags=tuple(ll_flags))

def call(self, fn, args, name='', cconv=None, tail=False, fastmath=(),
attrs=()):
ll_flags = fastmath
# only mark floating point functions as fast
if isinstance(fn.function_type.return_type, (llvm_ir.types.FloatType,
llvm_ir.types.DoubleType)):
if not fastmath:
ll_flags = utils.current_target_config().fastmath.flags
return super().call(fn, args, name=name, cconv=cconv, tail=tail,
fastmath=ll_flags, attrs=attrs)


class BaseLower(object):
"""
Lower IR to LLVM
Expand Down Expand Up @@ -309,7 +256,7 @@ def setup_function(self, fndesc):
# Setup function
self.function = self.context.declare_function(self.module, fndesc)
self.entry_block = self.function.append_basic_block('entry')
self.builder = TargetContextAwareBuilder(self.entry_block)
self.builder = Builder(self.entry_block)
self.call_helper = self.call_conv.init_call_helper(self.builder)

def typeof(self, varname):
Expand Down
19 changes: 9 additions & 10 deletions numba/core/typing/builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import operator

from numba.core import types, errors
from numba.core.overload_glue import glue_typing
from numba import prange
from numba.parfors.parfor import internal_prange

Expand Down Expand Up @@ -173,43 +172,43 @@ class BinOp(ConcreteTemplate):
cases += [signature(op, op, op) for op in sorted(types.complex_domain)]


@glue_typing(operator.add)
@infer_global(operator.add)
class BinOpAdd(BinOp):
pass


@glue_typing(operator.iadd)
@infer_global(operator.iadd)
class BinOpAdd(BinOp):
pass


@glue_typing(operator.sub)
@infer_global(operator.sub)
class BinOpSub(BinOp):
pass


@glue_typing(operator.isub)
@infer_global(operator.isub)
class BinOpSub(BinOp):
pass


@glue_typing(operator.mul)
@infer_global(operator.mul)
class BinOpMul(BinOp):
pass


@glue_typing(operator.imul)
@infer_global(operator.imul)
class BinOpMul(BinOp):
pass


@glue_typing(operator.mod)
@infer_global(operator.mod)
class BinOpMod(ConcreteTemplate):
cases = list(integer_binop_cases)
cases += [signature(op, op, op) for op in sorted(types.real_domain)]


@glue_typing(operator.imod)
@infer_global(operator.imod)
class BinOpMod(ConcreteTemplate):
cases = list(integer_binop_cases)
cases += [signature(op, op, op) for op in sorted(types.real_domain)]
Expand Down Expand Up @@ -243,7 +242,7 @@ class BinOpFloorDiv(ConcreteTemplate):
cases += [signature(op, op, op) for op in sorted(types.real_domain)]


@glue_typing(divmod)
@infer_global(divmod)
class DivMod(ConcreteTemplate):
_tys = machine_ints + sorted(types.real_domain)
cases = [signature(types.UniTuple(ty, 2), ty, ty) for ty in _tys]
Expand Down
6 changes: 0 additions & 6 deletions numba/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,6 @@ def enter(self, flags):
self.pop()


def current_target_config():
""" Shortcut function for getting the current target configuration.
"""
return ConfigStack().top_or_none()


class ConfigOptions(object):
OPTIONS = {}

Expand Down
50 changes: 24 additions & 26 deletions numba/cpython/numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
from numba.core import typing, types, utils, errors, cgutils, optional
from numba.core.extending import intrinsic, overload_method
from numba.cpython.unsafe.numbers import viewer
from numba.core.overload_glue import glue_lowering


def _int_arith_flags(rettype):
"""
Expand Down Expand Up @@ -159,7 +157,7 @@ def _int_divmod_impl(context, builder, sig, args, zerodiv_message):
return quot, rem


@glue_lowering(divmod, types.Integer, types.Integer)
@lower_builtin(divmod, types.Integer, types.Integer)
def int_divmod_impl(context, builder, sig, args):
quot, rem = _int_divmod_impl(context, builder, sig, args,
"integer divmod by zero")
Expand Down Expand Up @@ -189,8 +187,8 @@ def int_truediv_impl(context, builder, sig, args):
return impl_ret_untracked(context, builder, sig.return_type, res)


@glue_lowering(operator.mod, types.Integer, types.Integer)
@glue_lowering(operator.imod, types.Integer, types.Integer)
@lower_builtin(operator.mod, types.Integer, types.Integer)
@lower_builtin(operator.imod, types.Integer, types.Integer)
def int_rem_impl(context, builder, sig, args):
quot, rem = _int_divmod_impl(context, builder, sig, args,
"integer modulo by zero")
Expand Down Expand Up @@ -521,12 +519,12 @@ def bool_unary_positive_impl(context, builder, sig, args):
def _implement_integer_operators():
ty = types.Integer

glue_lowering(operator.add, ty, ty)(int_add_impl)
glue_lowering(operator.iadd, ty, ty)(int_add_impl)
glue_lowering(operator.sub, ty, ty)(int_sub_impl)
glue_lowering(operator.isub, ty, ty)(int_sub_impl)
glue_lowering(operator.mul, ty, ty)(int_mul_impl)
glue_lowering(operator.imul, ty, ty)(int_mul_impl)
lower_builtin(operator.add, ty, ty)(int_add_impl)
lower_builtin(operator.iadd, ty, ty)(int_add_impl)
lower_builtin(operator.sub, ty, ty)(int_sub_impl)
lower_builtin(operator.isub, ty, ty)(int_sub_impl)
lower_builtin(operator.mul, ty, ty)(int_mul_impl)
lower_builtin(operator.imul, ty, ty)(int_mul_impl)
lower_builtin(operator.eq, ty, ty)(int_eq_impl)
lower_builtin(operator.ne, ty, ty)(int_ne_impl)

Expand Down Expand Up @@ -734,7 +732,7 @@ def real_divmod_func_body(context, builder, vx, wx):
return builder.load(pfloordiv), builder.load(pmod)


@glue_lowering(divmod, types.Float, types.Float)
@lower_builtin(divmod, types.Float, types.Float)
def real_divmod_impl(context, builder, sig, args, loc=None):
x, y = args
quot = cgutils.alloca_once(builder, x.type, name="quot")
Expand Down Expand Up @@ -892,18 +890,18 @@ def real_sign_impl(context, builder, sig, args):

ty = types.Float

glue_lowering(operator.add, ty, ty)(real_add_impl)
glue_lowering(operator.iadd, ty, ty)(real_add_impl)
glue_lowering(operator.sub, ty, ty)(real_sub_impl)
glue_lowering(operator.isub, ty, ty)(real_sub_impl)
glue_lowering(operator.mul, ty, ty)(real_mul_impl)
glue_lowering(operator.imul, ty, ty)(real_mul_impl)
lower_builtin(operator.add, ty, ty)(real_add_impl)
lower_builtin(operator.iadd, ty, ty)(real_add_impl)
lower_builtin(operator.sub, ty, ty)(real_sub_impl)
lower_builtin(operator.isub, ty, ty)(real_sub_impl)
lower_builtin(operator.mul, ty, ty)(real_mul_impl)
lower_builtin(operator.imul, ty, ty)(real_mul_impl)
lower_builtin(operator.floordiv, ty, ty)(real_floordiv_impl)
lower_builtin(operator.ifloordiv, ty, ty)(real_floordiv_impl)
lower_builtin(operator.truediv, ty, ty)(real_div_impl)
lower_builtin(operator.itruediv, ty, ty)(real_div_impl)
glue_lowering(operator.mod, ty, ty)(real_mod_impl)
glue_lowering(operator.imod, ty, ty)(real_mod_impl)
lower_builtin(operator.mod, ty, ty)(real_mod_impl)
lower_builtin(operator.imod, ty, ty)(real_mod_impl)
lower_builtin(operator.pow, ty, ty)(real_power_impl)
lower_builtin(operator.ipow, ty, ty)(real_power_impl)
lower_builtin(pow, ty, ty)(real_power_impl)
Expand Down Expand Up @@ -1146,12 +1144,12 @@ def complex_abs(z):

ty = types.Complex

glue_lowering(operator.add, ty, ty)(complex_add_impl)
glue_lowering(operator.iadd, ty, ty)(complex_add_impl)
glue_lowering(operator.sub, ty, ty)(complex_sub_impl)
glue_lowering(operator.isub, ty, ty)(complex_sub_impl)
glue_lowering(operator.mul, ty, ty)(complex_mul_impl)
glue_lowering(operator.imul, ty, ty)(complex_mul_impl)
lower_builtin(operator.add, ty, ty)(complex_add_impl)
lower_builtin(operator.iadd, ty, ty)(complex_add_impl)
lower_builtin(operator.sub, ty, ty)(complex_sub_impl)
lower_builtin(operator.isub, ty, ty)(complex_sub_impl)
lower_builtin(operator.mul, ty, ty)(complex_mul_impl)
lower_builtin(operator.imul, ty, ty)(complex_mul_impl)
lower_builtin(operator.truediv, ty, ty)(complex_div_impl)
lower_builtin(operator.itruediv, ty, ty)(complex_div_impl)
lower_builtin(operator.neg, ty)(complex_negate_impl)
Expand Down
12 changes: 12 additions & 0 deletions numba/np/ufunc/ufuncbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,18 @@ def store_overloads_on_success():

Comment thread
stuartarchibald marked this conversation as resolved.
Resolved
return cres

# Compile
args, return_type = sigutils.normalize_signature(sig)
cres = compiler.compile_extra(typingctx, targetctx,
self.py_func, args=args,
return_type=return_type,
flags=flags, locals=locals)

# cache lookup failed before so safe to save
self.cache.save_overload(sig, cres)

return cres


dispatcher_registry[target_registry['npyufunc']] = UFuncDispatcher

Expand Down