Zig: BFLOAT16 support

Created on 1 Sep 2019  路  6Comments  路  Source: ziglang/zig

BFLOAT16 is a new floating-point format. It's a 16-bit floating point format with an 8 bit exponent and 7 bit mantissa (vs 5 bit exponent, 11 bit mantissa of a half-precision float which is currently f16) designed for deep learning.

The bfloat16 format is utilized in upcoming Intel AI processors, such as Nervana NNP-L1000, Xeon processors, and Intel FPGAs, Google Cloud TPUs, and TensorFlow. Arm Neon and SVE also supports bfloat16 format.

Selected excerpts:

  • Rust proposal is to call the type f16b.
  • > should always have size 2 and alignment 2 on all platforms

References:


As a more general issue: how should we add new numeric types going forward? e.g. Unum. With zig not supporting operator overloading, such types would have to be provided by the core for ergonomic use.

proposal

Most helpful comment

We could do what we do with integer types and allow the creation of arbitrary exponent/mantissa bitcount float types on demand.

All 6 comments

Also .NET 5 will have Half types

As a type naming proposal, perhaps f16_7, so use the mantissa/fraction number of bits? Rationale: Less precision -> lower number.

Short name | Long name | Description
---------- | --------- | -----------
f16 | f16_10 | IEEE half-precision 16-bit float / .NET Half type
f32 | f32_23 | IEEE 754 single-precision 32-bit float
f64 | f64_52 | IEEE 754 double-precision 64-bit float
_(none?)_ | f16_7 | bfloat16
? | f19_10 | NVidia's TensorFloat
? | f24_16 | AMD's fp24 format

We could do what we do with integer types and allow the creation of arbitrary exponent/mantissa bitcount float types on demand.

Apparently ARM Neoverse v1 will be getting BFLOAT16 support: https://fuse.wikichip.org/news/4564/arm-updates-its-neoverse-roadmap-new-bfloat16-sve-support/

If you do, also add BFLOAT19 AKA TF32. If we are following rust naming convention that would be f19b.

LLVM 11 added support for bfloat16: https://llvm.org/docs/LangRef.html#floating-point-types

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bheads picture bheads  路  3Comments

andrewrk picture andrewrk  路  3Comments

andersfr picture andersfr  路  3Comments

dobkeratops picture dobkeratops  路  3Comments

jorangreef picture jorangreef  路  3Comments