Coder Social home page Coder Social logo

proposal-float16array's Introduction

Float16Array

A proposal to add float16 (aka half-precision or binary16) TypedArrays to JavaScript.

Status

Authors: Kevin Gibbons

Champions: Leo Balter, Kevin Gibbons

This proposal is at Stage 3 of The TC39 Process as of the May 2023 meeting. It awaits implementations.

Spec text is available here.

Implementations

This proposal is ready for engines to implement and ship. See this issue for current status of implementations.

Motivation

  • Explicit request from the Color on the Web CG, for their use case with float-backed canvases.
  • Useful for GPU operations, where full precision often isn't necessary and memory constraints are serious.
    • WebGPU supports float16. It exposes/consumes raw ArrayBuffers. When those contain 32-bit floats, the pattern is to wrap the buffer in new Float32Array(...); that doesn't work when they contain 16-bit floats.
    • Increasingly relevant with new tools like Stable Diffusion, where full-precision representations don't fit in VRAM on many machines.
  • WebGL/WebGL2 support float16.
  • ARM and IA-32 and Intel® 64 architectures support float16 intrinsics.
  • Faking it in userland has serious performance costs.

Proposal

This would add a new kind of TypedArray, Float16Array, to complement the existing Float32Array and Float64Array. It would also add two new methods on DataView for reading and setting float16 values, as getFloat16 and setFloat16, to complement the existing similar methods for working with full and double precision floats, as well as Math.f16round, to complement the existing Math.fround.

Userland

@petramoriken has a package implementing Float16Array which gets 100k+ downloads/week on npm. See that repository for examples of some of the limitations and downsides of trying to do this purely in userland - notably the impossibility of integrating correctly with other web platform features like WebGL's HALF_FLOAT buffers and structuredClone.

proposal-float16array's People

Contributors

bakkot avatar petamoriken avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

proposal-float16array's Issues

Stage 4 tracking

This proposal achieved stage 3 at the May 2023 meeting. This is a tracking issue for getting stage 4.

  • committee consensus
  • open PR to the spec
    • editors have approved the PR
  • write test262 tests - issue
    • merge test262 tests
  • at least two implementations
  • significant in-the-field experience

BF16 vs FP16

It seems there are two competing standards for 16-bit floating point. IEEE has one standard, FP16, and Google Brain has another, BF16. They are very similar except they have different number of bits for the exponent versus mantissa.

FP16 seems to have native support for conversion to f32 on x86, and for limited computation in aarch64. BF16 has native support for computation on TPU chips, which are found in Pixel phones, and it seems that BF16 support is coming to AMD and Intel chips as well (based on public forums and bugs).

In other words, is it premature to add support for a Float16Array, if it is soon to be supplanted by a newer standard? Or should we add the other type as BFloat16Array?

Platform integration work

This needs integration with a couple of bits of the web platform:

As far as I am aware these are the only places which need updating currently (updating Web IDL will flow to a number of places, including WebGPU). WebNN and float-backed canvases are in progress features, and I've informed people working on both about Float16Array.

Should Float16Array be normative-optional?

All of the major use cases I'm aware of require either web canvases or GPUs. Obviously not all JS runtimes will be running in environments with access to those things (notably Moddable's XS engine, as well stuff like quickJS or Duktape). I don't see much reason to want Float16Arrays in such environments. Given that, should Float16Array be normative-optional for non-web runtimes?

cc @phoddie

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.