Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace context.compile_internal by @overload in cmathimpl.py #9516

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

guilhermeleobas
Copy link
Collaborator

@guilhermeleobas guilhermeleobas commented Mar 28, 2024

This is more of an exploratory work, and it is not ready yet.

The idea is to replace all occurrences of compile_internal by call_overload, introduced in this PR. Some of the motivation for this change is the ability to use print inside compiled function and dynamic exceptions.

Replaces all occurrences of context.compile_internal by @overload in cmathimpl.py

@guilhermeleobas
Copy link
Collaborator Author

guilhermeleobas commented Mar 28, 2024

acos test fails with the following error:

...
numba/core/lowering.py:1392: in lower_expr
    self.incref(resty, castval)
numba/core/lowering.py:1560: in incref
    self.context.nrt.incref(self.builder, typ, val)
numba/core/runtime/context.py:382: in incref
    self._call_incref_decref(builder, typ, value, "NRT_incref")
numba/core/runtime/context.py:367: in _call_incref_decref
    meminfos = self.get_meminfos(builder, typ, value)
numba/core/runtime/context.py:355: in get_meminfos
    field = getter(val)
numba/core/datamodel/models.py:713: in getter
    raise TypeError("expecting {0} but got {1}".format(*args))
E   TypeError: expecting {float, float} but got {double, double}

@guilhermeleobas guilhermeleobas changed the title Replace context.compile_internal by context.call_overload Replace context.compile_internal by @overload in cmathimpl.py Mar 28, 2024
@guilhermeleobas guilhermeleobas force-pushed the guilhermeleobas/call_overload branch 2 times, most recently from a408eab to ca143f6 Compare March 28, 2024 19:04
@gmarkall
Copy link
Member

gmarkall commented Apr 8, 2024

Should this be moved from draft status now it's RFR?

@guilhermeleobas guilhermeleobas marked this pull request as ready for review April 8, 2024 14:39
@gmarkall
Copy link
Member

gmarkall commented Apr 9, 2024

gpuci run tests

Copy link
Member

@gmarkall gmarkall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks for the improvements! I've left some comments on the diff.

Unfortunately this seems to have broken CUDA ufuncs e.g. - https://gpuci.gpuopenanalytics.com/job/numba/job/numba/job/prb/job/numba-prb/675/CUDA_TOOLKIT_VER=11.8,CUDA_VER=11.2,LINUX_VER=ubuntu18.04,PYTHON_VER=3.8,RAPIDS_VER=21.12/console

Do you need some help looking into the CUDA issue, or are you happy to fix this up?

numba/cpython/cmathimpl.py Outdated Show resolved Hide resolved
numba/cpython/cmathimpl.py Outdated Show resolved Hide resolved
numba/cpython/cmathimpl.py Outdated Show resolved Hide resolved
numba/cpython/cmathimpl.py Outdated Show resolved Hide resolved
numba/cpython/cmathimpl.py Outdated Show resolved Hide resolved
@lower(cmath.sqrt, types.Complex)
def sqrt_impl(context, builder, sig, args):
@overload(cmath.sqrt)
def sqrt_impl(z):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this return None if z is not a complex?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's one test in parfors that call cmath.sqrt with an integer. I think I remember why I included the code below:

     theargflt = z.underlying_float if isinstance(z, types.Complex) else z 

Should numba cast the integer to a complex value?

numba/cpython/cmathimpl.py Show resolved Hide resolved
numba/cpython/cmathimpl.py Outdated Show resolved Hide resolved
@gmarkall gmarkall added 4 - Waiting on author Waiting for author to respond to review and removed 3 - Ready for Review labels Apr 9, 2024
@gmarkall
Copy link
Member

gmarkall commented May 7, 2024

gpuci run tests

@guilhermeleobas
Copy link
Collaborator Author

The CI failure is probably related to one of the parfor tests calling cmath.sqrt(integer)

@guilhermeleobas
Copy link
Collaborator Author

Calling any cmath function with a non-complex value should be valid. I'll create an issue to track this and change cmath.sqrt to accept non-complex inputs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4 - Waiting on author Waiting for author to respond to review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants