-
Notifications
You must be signed in to change notification settings - Fork 40
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
Re-implementation of Tang (1990) log procedures in pure float32 #236
Conversation
src/device/intrinsics/math.jl
Outdated
jp = unsafe_trunc(Int,128.0f0*F)-127 | ||
|
||
## Steps 1 and 2 | ||
hi = t_log_Float32[jp] |
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.
Julia Base uses Float64
tables
q = u*v*0.08333351f0 | ||
|
||
## Step 4 | ||
logb(base)*(l + (u + q)) |
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.
Similarly, logb
in base returns a double
src/device/intrinsics/math.jl
Outdated
0.012512346f0) | ||
|
||
## Step 3 | ||
@inline function truncate(x) |
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.
From Tang (1990):
(1) Define M := 12 for single precision, and define M := 24 for double precision.
(2) u1 := u rounded (or truncated) to M significant bits.
(3) fi := f rounded (or truncated) to M significant bits.
I'm not sure if this is what is meant
src/device/intrinsics/math.jl
Outdated
reinterpret(Float32, | ||
reinterpret(Int32, 0.012512346f0) & 0b11111111111100000000000000000000) | ||
end | ||
u₁ = truncate(u) |
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.
Non-upcasting alternative procedure from Tang (1990)
What's the error like for these implementations? |
EDIT: CPU, running on metal has too high error
This
|
NOTE Running on Metal has very high error - something is not right |
Can you compare against Base.Math.log1p (Float64)? your current comparison isn't great since Base.Math.log1p (Float32) also has rounding error. |
I assumed that we're interested in the difference between the upcasting float32 vs. the pure float32 implementation. This
And for reference,
|
@oscardssmith do you think the error is acceptable? And most critically, running on Metal does not work - the error is way too high. Can you see any possible culprit in the code? |
the error is probably acceptable, but it is higher than I was expecting. I don't know why it's giving wrong answers on gpu. possibly the truncate is misbehaving? |
The problems seems to be accessing |
now that you mention it, a table based method is probably not the best idea for a gpu. |
https://github.com/JuliaMath/openlibm/blob/master/src/s_log1pf.c might be a better approach. |
Replaced by #239 |
Base.Math.log1p
calculation relies on two procedures , log_proc1 and log_proc2 from the literature Tang (1990). The current implementation upscales toFloat64
internally and as such is incompatible with Metal.This PR attempts to convert the two procedures to pure-float32.
See also relevant discussion #234