Repository navigation
Add np.log* bindings for CUDA #9417
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
Changes from 2 commits
605ac85
8af4864
bd9737b
898d018
fdc423f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Support math.log2 | ||
| ================= | ||
|
|
||
| Support for ``np.log2`` is added to CUDA target. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This adds more than just
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
| register_numpy_ufunc, | ||
| trigonometric_functions, | ||
| comparison_functions, | ||
| math_operations, | ||
| bit_twiddling_functions) | ||
| from numba.core.typing.templates import (AttributeTemplate, ConcreteTemplate, | ||
| AbstractTemplate, CallableTemplate, | ||
|
|
@@ -799,3 +800,7 @@ def resolve_local(self, mod): | |
|
|
||
| for func in bit_twiddling_functions: | ||
| register_numpy_ufunc(func, register_global) | ||
|
|
||
| for func in math_operations: | ||
| if func in ('log2', 'log', 'log10'): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would being specific by using something like the following be preferable to iterating over all the math operations and masking off those supported? for name in ('log2', 'log', 'log10'):
func = getattr(math_operations, name, None)
if func is None:
raise # something appropriate
... # do registration
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good. But just a remainder that (Pdb++) math_operations
['add', 'subtract', 'multiply', 'logaddexp', 'logaddexp2', 'true_divide', 'floor_divide', 'negative', 'positive', 'power', 'float_power', 'remainder', 'fmod', 'absolute', 'rint', 'sign', 'conjugate', 'exp', 'exp2', 'log', 'log2', 'log10', 'expm1', 'log1p', 'sqrt', 'square', 'cbrt', 'reciprocal', 'divide', 'mod', 'divmod', 'abs', 'fabs', 'gcd', 'lcm'] |
||
| register_numpy_ufunc(func, register_global) | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -260,6 +260,18 @@ def test_bitwise_not_ufunc(self): | |||||||||||||||||||||||||||||||||
| # when the second argument is a negative. See the comment in | ||||||||||||||||||||||||||||||||||
| # numba/tests/test_ufuncs.py for more details. | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| ############################################################################ | ||||||||||||||||||||||||||||||||||
| # Mathematical Functions | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| def test_log_ufunc(self): | ||||||||||||||||||||||||||||||||||
| self.basic_ufunc_test(np.log, kinds='cf') | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| def test_log2_ufunc(self): | ||||||||||||||||||||||||||||||||||
| self.basic_ufunc_test(np.log2, kinds='cf') | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| def test_log10_ufunc(self): | ||||||||||||||||||||||||||||||||||
| self.basic_ufunc_test(np.log10, kinds='cf') | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+266
to
+273
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think these test functions will check values in the complex domain.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I print the data that was generated in
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The ufunc tests in numba/numba/cuda/tests/cudapy/test_ufuncs.py Lines 33 to 48 in 03f2722
|
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if __name__ == '__main__': | ||||||||||||||||||||||||||||||||||
| unittest.main() | ||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,15 @@ def np_binary_impl(fn, context, builder, sig, args): | |
| impl = get_binary_impl_for_fn_and_ty(fn, sig.args[0]) | ||
| return impl(context, builder, sig, args) | ||
|
|
||
| def np_real_log_impl(context, builder, sig, args): | ||
| return np_unary_impl(math.log, context, builder, sig, args) | ||
|
|
||
| def np_real_log2_impl(context, builder, sig, args): | ||
| return np_unary_impl(math.log2, context, builder, sig, args) | ||
|
|
||
| def np_real_log10_impl(context, builder, sig, args): | ||
| return np_unary_impl(math.log10, context, builder, sig, args) | ||
|
|
||
| def np_real_sin_impl(context, builder, sig, args): | ||
| return np_unary_impl(math.sin, context, builder, sig, args) | ||
|
|
||
|
|
@@ -628,4 +637,26 @@ def np_real_atanh_impl(context, builder, sig, args): | |
| 'qq->q': numbers.int_shr_impl, | ||
| 'QQ->Q': numbers.int_shr_impl, | ||
| } | ||
|
|
||
| db[np.log] = { | ||
| 'f->f': np_real_log_impl, | ||
| 'd->d': np_real_log_impl, | ||
| 'F->F': npyfuncs.np_complex_log_impl, | ||
| 'D->D': npyfuncs.np_complex_log_impl, | ||
|
Comment on lines
+644
to
+645
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure what will happen with complex data types, I think the calls will resolve in terms of the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
...
B0:
%".25" = call float @"__nv_hypotf"(float %"arg.x", float %"arg.y")
%".26" = call float @"__nv_logf"(float %".25")
%".27" = call float @"__nv_atan2f"(float %"arg.y", float %"arg.x")
store {float, float} zeroinitializer, {float, float}* %".28"
%".31" = getelementptr inbounds {float, float}, {float, float}* %".28", i32 0, i32 0
store float %".26", float* %".31"
%".33" = getelementptr inbounds {float, float}, {float, float}* %".28", i32 0, i32 1
store float %".27", float* %".33"
%".35" = load {float, float}, {float, float}* %".28"
%"extracted.real" = extractvalue {float, float} %".35", 0
%"extracted.imag" = extractvalue {float, float} %".35", 1
%".36" = insertvalue {float, float} undef, float %"extracted.real", 0
%".37" = insertvalue {float, float} %".36", float %"extracted.imag", 1
store {float, float} %".37", {float, float}* %".ret"
ret i32 0
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These libdevice functions are used because of the lowerings of |
||
| } | ||
|
|
||
| db[np.log2] = { | ||
| 'f->f': np_real_log2_impl, | ||
| 'd->d': np_real_log2_impl, | ||
| 'F->F': npyfuncs.np_complex_log2_impl, | ||
| 'D->D': npyfuncs.np_complex_log2_impl, | ||
| } | ||
|
|
||
| db[np.log10] = { | ||
| 'f->f': np_real_log10_impl, | ||
| 'd->d': np_real_log10_impl, | ||
| 'F->F': npyfuncs.np_complex_log10_impl, | ||
| 'D->D': npyfuncs.np_complex_log10_impl, | ||
| } | ||
|
|
||
| return db | ||
Uh oh!
There was an error while loading. Please reload this page.