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

Support Unary Operations in Masked UDF #9409

Merged
merged 10 commits into from
Oct 19, 2021

Conversation

isVoid
Copy link
Contributor

@isVoid isVoid commented Oct 9, 2021

This PR adds support for several unary operations in masked udfs. Including trigonometry functions sin, cos, tan; rounding functions ceil and floor, sign functions neg and logic functions not.

closes #9405

@isVoid isVoid requested a review from a team as a code owner October 9, 2021 02:49
@isVoid isVoid requested a review from galipremsagar October 9, 2021 02:49
@github-actions github-actions bot added the Python Affects Python cuDF API. label Oct 9, 2021
@isVoid isVoid added feature request New feature or request non-breaking Non-breaking change labels Oct 9, 2021
@codecov
Copy link

codecov bot commented Oct 9, 2021

Codecov Report

Merging #9409 (96f99ae) into branch-21.12 (ab4bfaa) will increase coverage by 0.26%.
The diff coverage is 0.00%.

Impacted file tree graph

@@               Coverage Diff                @@
##           branch-21.12    #9409      +/-   ##
================================================
+ Coverage         10.79%   11.05%   +0.26%     
================================================
  Files               116      117       +1     
  Lines             18869    20250    +1381     
================================================
+ Hits               2036     2239     +203     
- Misses            16833    18011    +1178     
Impacted Files Coverage Δ
python/cudf/cudf/__init__.py 0.00% <0.00%> (ø)
python/cudf/cudf/_lib/__init__.py 0.00% <ø> (ø)
python/cudf/cudf/_lib/strings/__init__.py 0.00% <0.00%> (ø)
python/cudf/cudf/core/_base_index.py 0.00% <0.00%> (ø)
python/cudf/cudf/core/column/categorical.py 0.00% <0.00%> (ø)
python/cudf/cudf/core/column/column.py 0.00% <0.00%> (ø)
python/cudf/cudf/core/column/datetime.py 0.00% <0.00%> (ø)
python/cudf/cudf/core/column/lists.py 0.00% <0.00%> (ø)
python/cudf/cudf/core/column/numerical.py 0.00% <0.00%> (ø)
python/cudf/cudf/core/column/string.py 0.00% <0.00%> (ø)
... and 73 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7fa2738...96f99ae. Read the comment docs.

@isVoid isVoid added the numba Numba issue label Oct 11, 2021
Copy link
Contributor

@bdice bdice left a comment

Choose a reason for hiding this comment

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

@isVoid @brandon-b-miller Thanks for tagging me on this! It's a really interesting part of the code. I have a few comments/questions.

python/cudf/cudf/core/udf/_ops.py Outdated Show resolved Hide resolved
python/cudf/cudf/core/udf/lowering.py Outdated Show resolved Hide resolved
python/cudf/cudf/core/udf/lowering.py Outdated Show resolved Hide resolved
python/cudf/cudf/core/udf/lowering.py Outdated Show resolved Hide resolved
python/cudf/cudf/core/udf/lowering.py Show resolved Hide resolved
Copy link
Contributor

@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.

This looks good on the whole - it looks like you've got to grips with extending UDF support with relative ease! There are a couple of comments on the diff on expanding the set of supported functions and tightening up the typing a bit, but I don't see anything major that needs changing.

@@ -10,6 +11,26 @@
operator.pow,
]

unary_ops = [
Copy link
Contributor

Choose a reason for hiding this comment

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

All the unary math ops supported by the CUDA target can be found in Numba's cudamath.py, starting at this line: https://github.com/numba/numba/blob/master/numba/cuda/cudamath.py#L10 - it may be worth adding the complete set?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was able to get many unary ops in, except math.trunc. It's suggesting

NotImplementedError: No definition for lowering <built-in function trunc>(float64,) -> float64

I believe it should should've gotten trunc(float64)->int64, maybe something is not registered correctly?

Copy link
Contributor Author

@isVoid isVoid Oct 14, 2021

Choose a reason for hiding this comment

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

Besides math.log appears to be both a binary op and a unary op. Can we simply register math.log in binaryop as well as in unaryop to support both its usage?

Lastly, is there a place for all operator ops? Sorry for cramming all the questions in one place!

Copy link
Contributor

Choose a reason for hiding this comment

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

For trunc, the lack of implementation in CUDA might be a bug in Numba - I'll check into it and get back to you.

For log with two arguments, this appears not to be supported by the CUDA target (probably not for any good technical reason) - if the CUDA target did support it, just registering log as both a unary and binary op would work (because when one typing fails Numba will carry on trying others until it finds a successful one).

For all the operators, there's https://github.com/numba/numba/blob/master/numba/cpython/numbers.py - you have to look for all the instances of lower_builtin in that file. It's using the exact same code as the CPU target, so it isn't duplicated in the CUDA target, but instead the CUDA target pulls it in by "magic"... I started trying to trace exactly why the typing is registered for the CUDA target but I ended up going through several layers and still didn't get to the bottom of it. However, the lowering is pulled in by a side effect of this import in the CUDA target context: https://github.com/numba/numba/blob/master/numba/cuda/target.py#L88

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing out the operator locations. I was able to add invert. For abs, there's an error:

TypingError: No implementation of function Function(<built-in function abs>) found for signature:
E                         
E                         >>> abs(int32)

Which seems strange because the lowering for integer types are here: https://github.com/numba/numba/blob/2a792155c3dce43f86b9ff93802f12d39a3752dc/numba/cpython/numbers.py#L565

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unless... it's not for cuda target?

python/cudf/cudf/core/udf/typing.py Outdated Show resolved Hide resolved
@isVoid isVoid requested a review from gmarkall October 15, 2021 16:11
@brandon-b-miller
Copy link
Contributor

All, is this ready to merge? @isVoid @gmarkall

Copy link
Contributor

@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.

All, is this ready to merge? @isVoid @gmarkall

Looks good to me.

@brandon-b-miller
Copy link
Contributor

rerun tests

@brandon-b-miller brandon-b-miller added 5 - Ready to Merge Testing and reviews complete, ready to merge non-breaking Non-breaking change and removed non-breaking Non-breaking change labels Oct 18, 2021
@brandon-b-miller
Copy link
Contributor

rerun tests

@brandon-b-miller
Copy link
Contributor

@gpucibot merge

@rapids-bot rapids-bot bot merged commit 5e2aaf9 into rapidsai:branch-21.12 Oct 19, 2021
@brandon-b-miller
Copy link
Contributor

thanks @isVoid ! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5 - Ready to Merge Testing and reviews complete, ready to merge feature request New feature or request non-breaking Non-breaking change numba Numba issue Python Affects Python cuDF API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEA] Masked UDF Unary ops
5 participants