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 all 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.log, math.log2 and math.log10 in CUDA | ||
| -------------------------------------------------- | ||
|
|
||
| CUDA target now supports ``np.log``, ``np.log2`` and ``np.log10``. |
| 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 | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I print the data that was generated in
basic_ufunc_testand could see a few complex arrays there.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ufunc tests in
numba.tests.test_ufuncsdon't check values in the complex domain, but the CUDA ones have extra inputs added:numba/numba/cuda/tests/cudapy/test_ufuncs.py
Lines 33 to 48 in 03f2722