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

Julia port of Openlibm expm1. #25903

Closed
wants to merge 10 commits into from
Closed

Julia port of Openlibm expm1. #25903

wants to merge 10 commits into from

Conversation

pkofod
Copy link
Contributor

@pkofod pkofod commented Feb 5, 2018

cc @simonbyrne

This works, but is a bit slower than the C version, and I'm not quite sure why.

I put the definitions in a module JuLibm, opened julia with -O3 punched in

for x in [0.0,0.3,0.9,4.0,20.0,120.0]
       xf0 = Float32(x)
       println("\n --- Benchmarking $x")
       display(@benchmark JuLibm.expm1($x))
       display(@benchmark expm1($x))
       println("\n --- Benchmarking $(xf0)")
       display(@benchmark JuLibm.expm1($xf0))
       display(@benchmark expm1($xf0))
end

and got
https://gist.github.com/pkofod/c4dda880815985e6020ea58730d315cd https://gist.github.com/pkofod/d666951a7886f9f75ad013782b61acd9

there will be tests, but I'm just posting this to get some feedback about what to look for. I have a feeling the problem here is the same one that is causing regressions here #24859

Design suggestions and comment suggestions are also very welcome!

  • tests
  • license info update
  • fix performance

and then we're golden

@ararslan ararslan added the maths Mathematical functions label Feb 5, 2018

# filter out huge and non-finite argument
if absx >= expm1_huge(T) # quit early for large absolute values of x
if isinf(absx)
Copy link
Member

Choose a reason for hiding this comment

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

The indentation in this file is kind of all over the place. Should be 4-space indents everywhere.

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 will fix it. Not sure why that happened though...

@ararslan ararslan added the needs tests Unit tests are required for this change label Feb 5, 2018
@simonbyrne
Copy link
Contributor

I rebuilt with these functions, and am benchmarking against 0.6, but not seeing any difference.

@pkofod
Copy link
Contributor Author

pkofod commented Feb 6, 2018

You're getting comparable timings?

Edit: oh, I seem to be getting the exact same timings as well. Great, then I just need to polish this.

# filter out huge and non-finite argument
if absx >= expm1_huge(T) # quit early for large absolute values of x
if isinf(absx)
return xsign == true ? x : -T(1.0)
Copy link
Member

Choose a reason for hiding this comment

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

Probably just xsign, not xsign == true

end
else
# k = round(Int32, expm1_invln2(T)*x)
k = unsafe_trunc(Int32, expm1_invln2(T)*x + (!xsign ? 0.5 : -0.5))
Copy link
Member

Choose a reason for hiding this comment

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

possibly ifelse(xsign, -0.5, 0.5)

Copy link
Member

Choose a reason for hiding this comment

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

Also, T(0.5)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

to avoid the branch? and yes, T(0.5) to be safe!

@ararslan ararslan removed the needs tests Unit tests are required for this change label Feb 10, 2018
@ararslan
Copy link
Member

@nanosoldier runbenchmarks(ALL, vs=":master")

# the next line could be replaced with the above but we don't need the
# safety of round, so we round by adding one half with the appropriate
# sign and truncate to Int32
k = unsafe_trunc(Int32, expm1_invln2(T)*x + ifelse(xsign, -T(0.5), 0.5))
Copy link
Member

Choose a reason for hiding this comment

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

T(0.5) for the other branch too.

if k == -1
return T(0.5)*(x - e) - T(0.5)
end
if k ==1
Copy link
Member

Choose a reason for hiding this comment

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

missing space

return T(1.0) + T(2.0)*(x - e)
end
end
two_pow_k = expm1_two_pow_k(T, k) # T(2.0)^k but 9-10 times faster
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 be merged into exp2? Maybe we should have an exp2(T, x::Integer) method.

@nanosoldier
Copy link
Collaborator

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan

@pkofod
Copy link
Contributor Author

pkofod commented Feb 14, 2018

can nansoldier run here again now that the benchmarks are tuned? @ararslan

@ararslan
Copy link
Member

Yep, I recommend fixing the branch conflicts first though.

@ararslan
Copy link
Member

@nanosoldier runbenchmarks(ALL, vs=":master")

@nanosoldier
Copy link
Collaborator

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan

@pkofod
Copy link
Contributor Author

pkofod commented Feb 20, 2018

CI seems unrelated as usual (it was a few sweet weeks of green CI we had :))

@simonbyrne simonbyrne mentioned this pull request Mar 13, 2018
17 tasks
@pkofod
Copy link
Contributor Author

pkofod commented May 16, 2018

Nanosoldier can be activated again here.

@KristofferC
Copy link
Member

@nanosoldier runbenchmarks("scalar", vs=":master")

@nanosoldier
Copy link
Collaborator

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan

@pkofod
Copy link
Contributor Author

pkofod commented May 16, 2018

A few expm1 "regressions", but they might be flukes. Though, they're specific to Float32, so I'll have a look locally.

@ViralBShah
Copy link
Member

Also, the new optimizer is enabled now.

@pkofod
Copy link
Contributor Author

pkofod commented May 17, 2018

Comments for the PR in general or nanosoldier specifically ? @simonbyrne @stevengj

@ViralBShah
Copy link
Member

It's likely because of the new optimizer - @Keno

Probably shouldn't hold merging if all else is good, and we can have a new performance issue then.

@pkofod
Copy link
Contributor Author

pkofod commented May 22, 2018

Can I turn the new optimizer off locally? Or is it no longer a flag on master?

@Keno
Copy link
Member

Keno commented May 22, 2018

The flag should still work enable_new_optimizer in base/optimize.jl

@pkofod
Copy link
Contributor Author

pkofod commented May 22, 2018

The flag should still work enable_new_optimizer in base/optimize.jl

thanks, I'll try it without to see if that's why it regresses.

@pkofod
Copy link
Contributor Author

pkofod commented Jun 7, 2018

I think this is good to go, unless @simonbyrne has some rewrites (though they could always be done later as well)

@@ -0,0 +1,238 @@
# ====================================================
Copy link
Member

Choose a reason for hiding this comment

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

Probably the comment should start with:

# This code is a Julia translation of the C code from ... with the following license:

to make it clear that this is not the original Sun code.

Copy link
Contributor

Choose a reason for hiding this comment

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

@ViralBShah
Copy link
Member

Bump.

@ararslan
Copy link
Member

ararslan commented Jul 8, 2018

Rebased on master.

@pkofod
Copy link
Contributor Author

pkofod commented Jul 17, 2018

I can change the license comment as suggested by sgj when I get back from vacation, but if someone can push a commit with the changes before that, feel free.

@pkofod
Copy link
Contributor Author

pkofod commented Jul 20, 2018

Fixed the license comment. Should we run nanosoldier here as well?

@KristofferC
Copy link
Member

@nanosoldier runbenchmarks("scalar", vs=":master")

@ararslan
Copy link
Member

Nanosoldier is being weird. @nanosoldier runbenchmarks("scalar", vs=":master")

@nanosoldier
Copy link
Collaborator

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan

@pkofod
Copy link
Contributor Author

pkofod commented Jul 22, 2018

@simonbyrne thoughts on these benchmarks?

@pkofod pkofod changed the title [WIP] Julia port of Openlibm expm1. Julia port of Openlibm expm1. Jul 22, 2018
base/math.jl Outdated
@@ -277,7 +277,8 @@ asinh(x::Number)
Accurately compute ``e^x-1``.
"""
expm1(x)
for f in (:exp2, :expm1)

for f in (:exp2,)
Copy link
Member

Choose a reason for hiding this comment

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

Now that this is down to a single function, it would make sense to get rid of the loop.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I should have made a comment after I did this. The only reason why I did it like this is because it was easier for me, and the remaining code will be removed when I rebase #24859 after this is merged. Both should be quite close to merge-able I think.

I can remove the loop in this PR if you prefer it for a "clean" git history.

(on a side note, having removed these functions from the tuple one by one, I'm very happy to see the loop gone soon :))

@@ -1,3 +1,4 @@
# This code is a Julia translation of the C code from ... with the following license:
Copy link
Member

Choose a reason for hiding this comment

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

the ... should be replaced with the actual source(s) of the C code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I actually saw that, but I was pretty sure I changed it. Lol

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just double checked , we’re you commenting on an old commit?

@oscardssmith
Copy link
Member

Superseded by #37440

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maths Mathematical functions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants