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

is Float16 a real computational type or not? #5942

Closed
StefanKarpinski opened this issue Feb 24, 2014 · 22 comments
Closed

is Float16 a real computational type or not? #5942

StefanKarpinski opened this issue Feb 24, 2014 · 22 comments
Labels
domain:maths Mathematical functions status:help wanted Indicates that a maintainer wants help on an issue or pull request
Milestone

Comments

@StefanKarpinski
Copy link
Sponsor Member

At this point, Float16 is in a kind of weird limbo where it is sort of a storage type but we keep haphazardly adding more and more functionality to it. I think we really need to figure out where to draw the line here. Either we severely limit the scope of Float16's functionality and stop using it in tests for anything but converting to and from other numeric types, or we just go full throttle and make it a full computation type with as much functionality as Float32 or Float64 – albeit slower, since many operations will not be implemented as native machine ops.

@jiahao
Copy link
Member

jiahao commented Feb 24, 2014

I've wondered about this as well. Until extremely recently, we've had some tests for linear algebra over Float16s, which have turned out to be very stressful on our test criteria.

@andreasnoack
Copy link
Member

I saw your last comment about this and I am preparing to remove the Float16 linalg tests. They are also overfloating all the time.

@andreasnoack
Copy link
Member

@jiahao Almost the same comment at the same time. In #5902 I have removed Float16 from the tests.

@JeffBezanson
Copy link
Sponsor Member

I think it should have the same status as other numeric types that lack
extensive hardware and library support, like rational. Probably all we need
to do is generalize the definitions that make libm functions applicable to
ints and rationals.
On Feb 24, 2014 5:48 PM, "Andreas Noack Jensen" notifications@github.com
wrote:

I saw your last comment about this and I am preparing to remove the
Float16 linalg tests. They are also overfloating all the time.

Reply to this email directly or view it on GitHubhttps://github.com//issues/5942#issuecomment-35949938
.

@JeffBezanson
Copy link
Sponsor Member

Oh and fixed point would be another type in this category, though it is
more plausible to compute with.
On Feb 24, 2014 5:55 PM, "Jeff Bezanson" jeff.bezanson@gmail.com wrote:

I think it should have the same status as other numeric types that lack
extensive hardware and library support, like rational. Probably all we need
to do is generalize the definitions that make libm functions applicable to
ints and rationals.
On Feb 24, 2014 5:48 PM, "Andreas Noack Jensen" notifications@github.com
wrote:

I saw your last comment about this and I am preparing to remove the
Float16 linalg tests. They are also overfloating all the time.

Reply to this email directly or view it on GitHubhttps://github.com//issues/5942#issuecomment-35949938
.

@pao
Copy link
Member

pao commented Feb 24, 2014

fixed point would be another type in this category, though it is more plausible to compute with

It's very plausible in some domains, but these are also places you are unlikely to get the Julia runtime to work.

@JeffBezanson
Copy link
Sponsor Member

Is that a challenge? :-)
On Feb 24, 2014 6:37 PM, "pao" notifications@github.com wrote:

fixed point would be another type in this category, though it is more
plausible to compute with

It's very plausible in some domains, but these are also places you are
unlikely to get the Julia runtime to work.

Reply to this email directly or view it on GitHubhttps://github.com//issues/5942#issuecomment-35954405
.

@JeffBezanson
Copy link
Sponsor Member

Currently the fallbacks for transcendental functions look like

        ($f)(x::Real) = ($f)(float(x))

How about we use instead

        ($f)(x::Integer) = ($f)(float(x))
        ($f)(x::Real) = oftype(x, ($f)(float64(x)))

Then we could remove most of the definitions in float16.jl, and it wouldn't seem haphazard anymore.

@jiahao
Copy link
Member

jiahao commented Feb 25, 2014

This seems to work.

  • It looks like you can also remove the ($f)(x::FloatingPoint) fallback methods in math.jl, which just complain that the method is not defined.
  • The complex definitions seem to be redundant with the generic implementations in complex.jl, modulo the fact that some type instability results from the current behavior that float16(1) * im is not a Complex32, but rather a Complex64.

@jiahao
Copy link
Member

jiahao commented Feb 25, 2014

julia> typeof(float16(1.0)*true)
Float32

julia> promote_type(Bool, Float16)
Float32

@jiahao
Copy link
Member

jiahao commented Feb 25, 2014

MathConsts also need special handling.

With the proposed fallbacks:

julia> sqrt(pi)
ERROR: no method convert(Type{MathConst{:π}}, Float64)
 in sqrt at math.jl:274

jiahao added a commit that referenced this issue Feb 25, 2014
Implements @JeffBezanson's suggestion in #5942.

- Removes Complex32 definitions in float16.jl
- Removes also error-raising ($f)(x::FloatingPoint) fallbacks in math.jl

Status:
- Some of the complex functions are no longer type stable because
  float16(1) * im returns a Complex64 instead of the expected Complex32.
@JeffBezanson
Copy link
Sponsor Member

I guess there is a case to be made that any operation on Float16 should return a Float32, since that way there's no roundoff and subsequent operations will actually be faster. That's probably what it means to be a "storage type". There is a strong similarity to how we do e.g. Int8 + Int8.

@jiahao
Copy link
Member

jiahao commented Feb 25, 2014

Fair enough, but having to explicitly recast the complex elementary functions strikes me as really quite inelegant, given the generic implementations in complex.jl:

julia> for f in (sin, cos, tan, asin, acos, atan, sinh, cosh, tanh, asinh, acosh, atanh, exp, log, sqrt)
          x=float16(rand()+rand()*im); @show f, typeof(f(x))
       end
(f,typeof(f(x))) => (sin,Complex{Float16})
(f,typeof(f(x))) => (cos,Complex{Float16})
(f,typeof(f(x))) => (tan,Complex{Float32})
(f,typeof(f(x))) => (asin,Complex{Float32})
(f,typeof(f(x))) => (acos,Complex{Float32})
(f,typeof(f(x))) => (atan,Complex{Float32})
(f,typeof(f(x))) => (sinh,Complex{Float16})
(f,typeof(f(x))) => (cosh,Complex{Float16})
(f,typeof(f(x))) => (tanh,Complex{Float32})
(f,typeof(f(x))) => (asinh,Complex{Float32})
(f,typeof(f(x))) => (acosh,Complex{Float32})
(f,typeof(f(x))) => (atanh,Complex{Float32})
(f,typeof(f(x))) => (exp,Complex{Float16})
(f,typeof(f(x))) => (log,Complex{Float32})
(f,typeof(f(x))) => (sqrt,Complex{Float32})

jiahao added a commit that referenced this issue May 6, 2014
Implements @JeffBezanson's suggestion in #5942.

- Removes Complex32 definitions in float16.jl
- Removes also error-raising ($f)(x::FloatingPoint) fallbacks in math.jl

Status:
- Some of the complex functions are no longer type stable because
  float16(1) * im returns a Complex64 instead of the expected Complex32.
jiahao added a commit that referenced this issue Feb 1, 2015
Implements @JeffBezanson's suggestion in #5942.

- Removes Complex32 definitions in float16.jl
- Removes also error-raising ($f)(x::FloatingPoint) fallbacks in math.jl

Status:
- Some of the complex functions are no longer type stable because
  float16(1) * im returns a Complex64 instead of the expected Complex32.
jiahao added a commit that referenced this issue Feb 1, 2015
The advantage of this definition is that

    float16(1)*im

will be a Complex32 and not a Complex64.

Ref: #5942
jiahao added a commit that referenced this issue Feb 2, 2015
The advantage of this definition is that

    float16(1)*im

will be a Complex32 and not a Complex64.

Ref: #5942
@StefanKarpinski
Copy link
Sponsor Member Author

It's resolved at this point that Float16 is a real computational type: many people want to use if for a variety of purposes and find it frustrating that it doesn't behave the same way as Float32 and Float64; moreover, GPUs have actual support for using Float16 as a computational type.

@StefanKarpinski StefanKarpinski added domain:maths Mathematical functions and removed needs decision A decision on this change is needed labels Sep 13, 2016
@StefanKarpinski StefanKarpinski added the status:help wanted Indicates that a maintainer wants help on an issue or pull request label Sep 13, 2016
@StefanKarpinski StefanKarpinski added this to the 0.6.0 milestone Sep 13, 2016
@StefanKarpinski
Copy link
Sponsor Member Author

What if anything is left to do here?

@tkelman
Copy link
Contributor

tkelman commented Nov 10, 2016

ping @vchuravy for your thoughts

@vchuravy
Copy link
Member

There are two main things currently missing.

  1. Lowering of Float16 to half instead of i16 (I think we could do this now)
  2. RTLIB: A runtime-library for Julia Juleps#11 or at least Basic support for builtins from compiler-rt #18734

@yuyichao
Copy link
Contributor

Both of those affect performance but not functions right?

@vchuravy
Copy link
Member

Yes, but if we actually want to make use of Float16 we need both of them. Right now we are eagerly using Float32 as a fallback, preventing any benefit from actually using Float16. (except maybe reduce memory usage and bandwidth)

@StefanKarpinski
Copy link
Sponsor Member Author

Strict performance improvements can happen any time and be backported, so that makes this not a release-blocking issue – it's an issue that anyone who wants to can tackle whenever.

@tkelman
Copy link
Contributor

tkelman commented Nov 11, 2016

The build system changes and library restructuring to integrate compiler-rt and the rtlib julep are probably too big to backport, but they're making progress.

@JeffBezanson
Copy link
Sponsor Member

Closing since there seem to be no more semantic changes needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:maths Mathematical functions status:help wanted Indicates that a maintainer wants help on an issue or pull request
Projects
None yet
Development

No branches or pull requests

8 participants